aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt25
1 files changed, 14 insertions, 11 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 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))
}
}