diff options
author | Allan Wang <me@allanwang.ca> | 2017-12-11 17:52:24 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-11 17:52:24 -0500 |
commit | db262e95779e0a17275bdb94be2b0ac12819178e (patch) | |
tree | 42b89edf8796e85e362ca86dead1170cb38f6434 /app/src/main/kotlin/com/pitchedapps/frost/utils | |
parent | 1d4380cee77fc049a54d280a27dcefa3fa6ff1fd (diff) | |
download | frost-db262e95779e0a17275bdb94be2b0ac12819178e.tar.gz frost-db262e95779e0a17275bdb94be2b0ac12819178e.tar.bz2 frost-db262e95779e0a17275bdb94be2b0ac12819178e.zip |
Feature/tab customization (#522)
* Add initial tab customizing view
* Add rest of content for now
* Delete project file backups
* Stash
* Support full tab customization
* Test activity animations
* Update kau and fix sound uri
* Try catch download, resolves #523
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt | 19 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt | 12 |
2 files changed, 24 insertions, 7 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 e6db8eee..2c638dfd 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt @@ -9,14 +9,12 @@ 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.showAppInfo import ca.allanwang.kau.utils.string +import ca.allanwang.kau.utils.toast 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 /** @@ -40,8 +38,10 @@ fun Context.frostDownload(uri: Uri?, contentLength: Long = 0L) { uri ?: return L.d("Received download request", "Download $uri") - if (uri.scheme != "http" && uri.scheme != "https") - return L.e("Invalid download attempt", uri.toString()) + if (uri.scheme != "http" && uri.scheme != "https") { + toast(R.string.error_invalid_download) + return L.e(string(R.string.error_invalid_download), uri.toString()) + } if (!isAppEnabled(DOWNLOAD_MANAGER_PACKAGE)) { materialDialogThemed { title(R.string.no_download_manager) @@ -66,7 +66,12 @@ fun Context.frostDownload(uri: Uri?, request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Frost/$title") val dm = getSystemService(DOWNLOAD_SERVICE) as DownloadManager - dm.enqueue(request) + try { + dm.enqueue(request) + } catch (e: Exception) { + toast(R.string.error_generic) + L.e(e, "Download") + } } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt index d8fa2ce9..ccc4033c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -10,6 +10,7 @@ import android.net.Uri import android.support.annotation.StringRes import android.support.design.internal.SnackbarContentLayout import android.support.design.widget.Snackbar +import android.support.v4.app.ActivityOptionsCompat import android.support.v7.widget.Toolbar import android.view.View import android.widget.FrameLayout @@ -80,13 +81,24 @@ fun Context.launchWebOverlay(url: String, clazz: Class<out WebOverlayActivityBas }) } +private fun Context.fadeBundle() = ActivityOptionsCompat.makeCustomAnimation(this, + android.R.anim.fade_in, android.R.anim.fade_out).toBundle() + fun Context.launchImageActivity(imageUrl: String, text: String?) { startActivity(ImageActivity::class.java, intentBuilder = { + putExtras(fadeBundle()) putExtra(ARG_IMAGE_URL, imageUrl) putExtra(ARG_TEXT, text) }) } +fun Activity.launchTabCustomizerActivity() { + startActivityForResult(TabCustomizerActivity::class.java, + SettingsActivity.ACTIVITY_REQUEST_TABS, bundleBuilder = { + with(fadeBundle()) + }) +} + fun Activity.launchIntroActivity(cookieList: ArrayList<CookieModel>) = launchNewTask(IntroActivity::class.java, cookieList, true) |