From f5394badad02671dc0de181ab63b9a9bfbe9fd59 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Fri, 18 Aug 2017 20:25:41 -0700 Subject: Misc 2 (#191) * Add further checks for iab and remove generic error dialog * Theme all snackbars * Add dynamic media action tile --- .../kotlin/com/pitchedapps/frost/utils/Utils.kt | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 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 74e800df..469a3951 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -148,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)) } } -- cgit v1.2.3