diff options
author | Allan Wang <me@allanwang.ca> | 2017-11-15 02:47:13 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-15 02:47:13 -0500 |
commit | 5a6bf455cb2e550c18f94d8aeaaa91c2260cb75a (patch) | |
tree | be77ea3de84f549a612e22a0adb8785956e0ac56 /app/src/main/kotlin/com/pitchedapps/frost/utils | |
parent | 98fb870bdabae28beabe99d1e49ad74ab9a5a1c2 (diff) | |
download | frost-5a6bf455cb2e550c18f94d8aeaaa91c2260cb75a.tar.gz frost-5a6bf455cb2e550c18f94d8aeaaa91c2260cb75a.tar.bz2 frost-5a6bf455cb2e550c18f94d8aeaaa91c2260cb75a.zip |
Fix/bad overlay (#490)v1.6.5
* Fix intent launching
* Add some tests and update kotlin
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt | 23 |
1 files changed, 20 insertions, 3 deletions
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 c644499e..082f4758 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -1,5 +1,6 @@ package com.pitchedapps.frost.utils +import android.annotation.SuppressLint import android.app.Activity import android.content.Context import android.content.Intent @@ -163,6 +164,7 @@ fun Activity.frostSnackbar(@StringRes text: Int, builder: Snackbar.() -> Unit = fun View.frostSnackbar(@StringRes text: Int, builder: Snackbar.() -> Unit = {}) = snackbar(text, Snackbar.LENGTH_LONG, frostSnackbar(builder)) +@SuppressLint("RestrictedApi") private inline fun frostSnackbar(crossinline builder: Snackbar.() -> Unit): Snackbar.() -> Unit = { builder() //hacky workaround, but it has proper checks and shouldn't crash @@ -191,18 +193,33 @@ fun Context.createPrivateMediaFile(extension: String) = createPrivateMediaFile(" * @returns {@code true} if activity is resolved, {@code false} otherwise */ fun Context.resolveActivityForUri(uri: Uri): Boolean { - if (uri.toString().isFacebookUrl && !uri.toString().contains("intent:")) return false //ignore response as we will be triggering ourself val intent = Intent(Intent.ACTION_VIEW, uri) if (intent.resolveActivity(packageManager) == null) return false startActivity(intent) return true } +/** + * [true] if url contains [FACEBOOK_COM] + */ inline val String?.isFacebookUrl - get() = this != null && this.contains(FACEBOOK_COM) + get() = this != null && contains(FACEBOOK_COM) +/** + * [true] is url is a video and can be accepted by VideoViewer + */ inline val String?.isVideoUrl - get() = this != null && (this.startsWith(VIDEO_REDIRECT) || this.startsWith("https://video-")) + get() = this != null && (startsWith(VIDEO_REDIRECT) || startsWith("https://video-")) + +/** + * [true] is url can be displayed in a different webview + */ +inline val String?.isIndependent + get() = this == null || (startsWith("http") && !isFacebookUrl) + || !contains("photoset_token") + +inline val String?.isExplicitIntent + get() = this != null && startsWith("intent://") fun Context.frostChangelog() = showChangelog(R.xml.frost_changelog, Prefs.textColor) { theme() |