diff options
author | Allan Wang <me@allanwang.ca> | 2017-11-13 05:09:24 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-13 05:09:24 -0500 |
commit | 63d8779ad4fab7d2eb762be34eeca04c7debc6f3 (patch) | |
tree | 334f3c0c4c6a717d7c0b0872574cb65b3b50166c /app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt | |
parent | 4aed05a8923a7f76799bbaa254f407f7e11fef0b (diff) | |
download | frost-63d8779ad4fab7d2eb762be34eeca04c7debc6f3.tar.gz frost-63d8779ad4fab7d2eb762be34eeca04c7debc6f3.tar.bz2 frost-63d8779ad4fab7d2eb762be34eeca04c7debc6f3.zip |
Enhancement/video (#484)v1.6.4
* Fix more parsing issues
* Try catch decoder resolves #456
* Fix unit test and add null check for images, resolves #458
* Remove downloadservice, resolves #459
* Clean up progress animator
* Check for download manager before download attempt
* Update strings
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt index 3e1e1dde..e6db8eee 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt @@ -8,10 +8,15 @@ import android.os.Environment import android.webkit.URLUtil import ca.allanwang.kau.permissions.PERMISSION_WRITE_EXTERNAL_STORAGE import ca.allanwang.kau.permissions.kauRequestPermissions +import ca.allanwang.kau.utils.isAppEnabled import ca.allanwang.kau.utils.string import com.pitchedapps.frost.R import com.pitchedapps.frost.dbflow.loadFbCookie import com.pitchedapps.frost.facebook.USER_AGENT_BASIC +import android.support.v4.content.ContextCompat.startActivity +import android.content.Intent +import android.content.ActivityNotFoundException +import ca.allanwang.kau.utils.showAppInfo /** @@ -37,6 +42,16 @@ fun Context.frostDownload(uri: Uri?, L.d("Received download request", "Download $uri") if (uri.scheme != "http" && uri.scheme != "https") return L.e("Invalid download attempt", uri.toString()) + if (!isAppEnabled(DOWNLOAD_MANAGER_PACKAGE)) { + materialDialogThemed { + title(R.string.no_download_manager) + content(R.string.no_download_manager_desc) + positiveText(R.string.kau_yes) + onPositive { _, _ -> showAppInfo(DOWNLOAD_MANAGER_PACKAGE) } + negativeText(R.string.kau_no) + } + return + } kauRequestPermissions(PERMISSION_WRITE_EXTERNAL_STORAGE) { granted, _ -> if (!granted) return@kauRequestPermissions val request = DownloadManager.Request(uri) @@ -53,4 +68,6 @@ fun Context.frostDownload(uri: Uri?, val dm = getSystemService(DOWNLOAD_SERVICE) as DownloadManager dm.enqueue(request) } -}
\ No newline at end of file +} + +private const val DOWNLOAD_MANAGER_PACKAGE = "com.android.providers.downloads"
\ No newline at end of file |