diff options
author | Allan Wang <me@allanwang.ca> | 2021-04-17 20:06:36 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2021-04-17 20:06:36 -0700 |
commit | 6abaf596e4db5a36057f6a8acf31b72f57a12e18 (patch) | |
tree | 1b2d52fe2f6a4d1d73fe23c0061a697c9d664eab /app/src/main/kotlin/com/pitchedapps/frost/utils | |
parent | 795182bab71e70c28e7d07550bca0d2e35b70c60 (diff) | |
download | frost-6abaf596e4db5a36057f6a8acf31b72f57a12e18.tar.gz frost-6abaf596e4db5a36057f6a8acf31b72f57a12e18.tar.bz2 frost-6abaf596e4db5a36057f6a8acf31b72f57a12e18.zip |
Remove koin dependency in production
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt | 42 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt | 14 |
2 files changed, 33 insertions, 23 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 73572a44..ec8aec6c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -266,15 +266,23 @@ fun Throwable?.logFrostEvent(text: String) { frostEvent("Errors", "text" to text, "message" to (this?.message ?: "NA")) } -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)) +fun Activity.frostSnackbar( + @StringRes text: Int, + themeProvider: ThemeProvider, + builder: Snackbar.() -> Unit = {} +) = snackbar(text, Snackbar.LENGTH_LONG, frostSnackbar(themeProvider, builder)) + +fun View.frostSnackbar( + @StringRes text: Int, + themeProvider: ThemeProvider, + builder: Snackbar.() -> Unit = {} +) = snackbar(text, Snackbar.LENGTH_LONG, frostSnackbar(themeProvider, builder)) @SuppressLint("RestrictedApi") -private inline fun frostSnackbar(crossinline builder: Snackbar.() -> Unit): Snackbar.() -> Unit = { - val themeProvider = ThemeProvider.get() +private inline fun frostSnackbar( + themeProvider: ThemeProvider, + 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 { @@ -421,18 +429,20 @@ fun Context.frostUri(entry: String): Uri { inline fun Context.sendFrostEmail( @StringRes subjectId: Int, + prefs: Prefs, crossinline builder: EmailBuilder.() -> Unit -) = - sendFrostEmail(string(subjectId), builder) +) = sendFrostEmail(string(subjectId), prefs, builder) -inline fun Context.sendFrostEmail(subjectId: String, crossinline builder: EmailBuilder.() -> Unit) = - sendEmail("", subjectId) { - builder() - addFrostDetails() - } +inline fun Context.sendFrostEmail( + subjectId: String, + prefs: Prefs, + crossinline builder: EmailBuilder.() -> Unit +) = sendEmail("", subjectId) { + builder() + addFrostDetails(prefs) +} -fun EmailBuilder.addFrostDetails() { - val prefs = Prefs.get() +fun EmailBuilder.addFrostDetails(prefs: Prefs) { addItem("Prev version", prefs.prevVersionCode.toString()) val proTag = "FO" addItem("Random Frost ID", "${prefs.frostId}-$proTag") diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt index 2e88141d..f3c81578 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt @@ -32,7 +32,7 @@ import com.pitchedapps.frost.prefs.Prefs /** * Created by Allan Wang on 2017-07-07. */ -fun Context.showWebContextMenu(wc: WebContext, fbCookie: FbCookie) { +fun Context.showWebContextMenu(wc: WebContext, fbCookie: FbCookie, prefs: Prefs) { if (wc.isEmpty) return var title = wc.url ?: string(R.string.menu) title = @@ -45,7 +45,7 @@ fun Context.showWebContextMenu(wc: WebContext, fbCookie: FbCookie) { materialDialog { title(text = title) listItems(items = menuItems.map { string(it.textId) }) { _, position, _ -> - menuItems[position].onClick(this@showWebContextMenu, wc, fbCookie) + menuItems[position].onClick(this@showWebContextMenu, wc, fbCookie, prefs) } onDismiss { // showing the dialog interrupts the touch down event, so we must ensure that the viewpager's swipe is enabled @@ -67,16 +67,16 @@ class WebContext(val unformattedUrl: String?, val text: String?) { enum class WebContextType( val textId: Int, val constraint: (wc: WebContext) -> Boolean, - val onClick: (c: Context, wc: WebContext, fc: FbCookie) -> Unit + val onClick: (c: Context, wc: WebContext, fc: FbCookie, prefs: Prefs) -> Unit ) { OPEN_LINK( R.string.open_link, { it.hasUrl }, - { c, wc, fc -> c.launchWebOverlay(wc.url!!, fc, Prefs.get()) } + { c, wc, fc, prefs -> c.launchWebOverlay(wc.url!!, fc, prefs) } ), - COPY_LINK(R.string.copy_link, { it.hasUrl }, { c, wc, _ -> c.copyToClipboard(wc.url) }), - COPY_TEXT(R.string.copy_text, { it.hasText }, { c, wc, _ -> c.copyToClipboard(wc.text) }), - SHARE_LINK(R.string.share_link, { it.hasUrl }, { c, wc, _ -> c.shareText(wc.url) }) + COPY_LINK(R.string.copy_link, { it.hasUrl }, { c, wc, _, _ -> c.copyToClipboard(wc.url) }), + COPY_TEXT(R.string.copy_text, { it.hasText }, { c, wc, _, _ -> c.copyToClipboard(wc.text) }), + SHARE_LINK(R.string.share_link, { it.hasUrl }, { c, wc, _, _ -> c.shareText(wc.url) }) ; companion object { |