From 84bf883a47b956865d31b1b618d5495fcd7d4876 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 19 Aug 2017 09:47:05 -0700 Subject: v1.4.7 (#195) * Add try catch (#179) * Add checks before injections (#180) * Enhancement/url redirect manager (#182) * Initial blacklist * Move js checks to java * Optimize imports and clean up request interceptor * Misc (#190) * Update play store description * Finalize description * Update kotlin and bg2 for custom themes * Update to Android Studio 3.0 beta 2 * Update test dependencies and add logging to image activity * Rename throwable to errorRef * Update searchview and media picker through kau * Update themes (#183) * Theme content now found view * Update verified bg and bg2 for transparent themes * Fix check in star text * Various fixes * Create base svg sass images * Feature/theme accent (#192) * Add lots of theming components * Optimize and add * Update accents * Misc 2 (#191) * Add further checks for iab and remove generic error dialog * Theme all snackbars * Add dynamic media action tile * Enhancement/media-camera-picker (#194) * Update kau * Update changelog --- .../kotlin/com/pitchedapps/frost/utils/Utils.kt | 37 +++++++++++++++------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt') 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 e79816f3..469a3951 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -13,6 +13,8 @@ import android.support.v7.widget.Toolbar import android.view.View import android.widget.FrameLayout import android.widget.TextView +import ca.allanwang.kau.mediapicker.createMediaFile +import ca.allanwang.kau.mediapicker.createPrivateMediaFile import ca.allanwang.kau.utils.* import com.afollestad.materialdialogs.MaterialDialog import com.bumptech.glide.RequestBuilder @@ -54,6 +56,11 @@ fun Activity.cookies(): ArrayList { return intent?.extras?.getParcelableArrayList(EXTRA_COOKIES) ?: arrayListOf() } +/** + * Launches the given url in a new overlay (if it already isn't in an overlay) + * Note that most requests may need to first check if the url can be launched as an overlay + * See [requestWebOverlay] to verify the launch + */ fun Context.launchWebOverlay(url: String) { val argUrl = url.formattedFbUrl L.v("Launch received", url) @@ -141,17 +148,20 @@ fun Throwable?.logFrostAnswers(text: String) { frostAnswersCustom("Errors", "text" to text, "message" to (this?.message ?: "NA")) } -fun View.frostSnackbar(@StringRes text: Int, builder: Snackbar.() -> Unit = {}) { - Snackbar.make(this, text, Snackbar.LENGTH_LONG).apply { - builder() - //hacky workaround, but it has proper checks and shouldn't crash - ((view as? FrameLayout)?.getChildAt(0) as? SnackbarContentLayout)?.apply { - messageView.setTextColor(Prefs.textColor) - actionView.setTextColor(Prefs.accentColor) - //only set if previous text colors are set - view.setBackgroundColor(Prefs.bgColor.withAlpha(255).colorToForeground(0.1f)) - } - show() +fun Activity.frostSnackbar(@StringRes text: Int, builder: Snackbar.() -> Unit = {}) + = snackbar(text, Snackbar.LENGTH_LONG, frostSnackbar(builder)) + +fun View.frostSnackbar(@StringRes text: Int, builder: Snackbar.() -> Unit = {}) + = snackbar(text, Snackbar.LENGTH_LONG, frostSnackbar(builder)) + +private inline fun frostSnackbar(crossinline builder: Snackbar.() -> Unit): Snackbar.() -> Unit = { + builder() + //hacky workaround, but it has proper checks and shouldn't crash + ((view as? FrameLayout)?.getChildAt(0) as? SnackbarContentLayout)?.apply { + messageView.setTextColor(Prefs.textColor) + actionView.setTextColor(Prefs.accentColor) + //only set if previous text colors are set + view.setBackgroundColor(Prefs.bgColor.withAlpha(255).colorToForeground(0.1f)) } } @@ -172,10 +182,13 @@ 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().contains(FACEBOOK_COM) && !uri.toString().contains("intent:")) return false //ignore response as we will be triggering ourself + 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 } +inline val String?.isFacebookUrl + get() = this != null && this.contains(FACEBOOK_COM) + -- cgit v1.2.3