From c5d38e5122bcb452b1e61ea6526434cf62e9da8c Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 29 Feb 2020 19:29:09 -0800 Subject: Update koin usage --- .../kotlin/com/pitchedapps/frost/utils/Prefs.kt | 3 ++- .../kotlin/com/pitchedapps/frost/utils/Utils.kt | 22 ++++++++++------------ .../com/pitchedapps/frost/utils/WebContextMenu.kt | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt index 8052533b..36e3971a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -31,6 +31,7 @@ import com.pitchedapps.frost.enums.MainActivityLayout import com.pitchedapps.frost.enums.Theme import com.pitchedapps.frost.injectors.InjectorContract import org.koin.core.context.GlobalContext +import org.koin.core.context.KoinContextHandler import org.koin.dsl.module /** @@ -202,7 +203,7 @@ class Prefs(factory: KPrefFactory) : KPref("${BuildConfig.APPLICATION_ID}.prefs" get() = MainActivityLayout(mainActivityLayoutType) companion object { - fun get(): Prefs = GlobalContext.get().koin.get() + fun get(): Prefs = KoinContextHandler.get().get() fun module() = module { single { Prefs(get()) } 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 1f266eb9..6db7179d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -125,9 +125,9 @@ fun Activity.cookies(): ArrayList { */ private inline fun Context.launchWebOverlayImpl( url: String, - fbCookie: FbCookie + fbCookie: FbCookie, + prefs: Prefs ) { - val prefs = Prefs.get() val argUrl = url.formattedFbUrl L.v { "Launch received: $url\nLaunch web overlay: $argUrl" } if (argUrl.isFacebookUrl && argUrl.contains("/logout.php")) { @@ -142,15 +142,15 @@ private inline fun Context.launchWebOverlay } } -fun Context.launchWebOverlay(url: String, fbCookie: FbCookie) = - launchWebOverlayImpl(url, fbCookie) +fun Context.launchWebOverlay(url: String, fbCookie: FbCookie, prefs: Prefs) = + launchWebOverlayImpl(url, fbCookie, prefs) // TODO Currently, default is overlay. Switch this if default changes -fun Context.launchWebOverlayDesktop(url: String, fbCookie: FbCookie) = - launchWebOverlay(url, fbCookie) +fun Context.launchWebOverlayDesktop(url: String, fbCookie: FbCookie, prefs: Prefs) = + launchWebOverlay(url, fbCookie, prefs) -fun Context.launchWebOverlayMobile(url: String, fbCookie: FbCookie) = - launchWebOverlayImpl(url, fbCookie) +fun Context.launchWebOverlayMobile(url: String, fbCookie: FbCookie, prefs: Prefs) = + launchWebOverlayImpl(url, fbCookie, prefs) private fun Context.fadeBundle() = ActivityOptions.makeCustomAnimation( this, @@ -178,8 +178,7 @@ fun WebOverlayActivity.url(): String { return intent.getStringExtra(ARG_URL) ?: FbItem.FEED.url } -fun Activity.setFrostTheme(forceTransparent: Boolean = false) { - val prefs = Prefs.get() +fun Activity.setFrostTheme(prefs: Prefs, forceTransparent: Boolean = false) { val isTransparent = forceTransparent || (Color.alpha(prefs.bgColor) != 255) || (Color.alpha(prefs.headerColor) != 255) if (prefs.bgColor.isColorDark) { @@ -267,8 +266,7 @@ private inline fun frostSnackbar(crossinline builder: Snackbar.() -> Unit): Snac } } -fun Activity.frostNavigationBar() { - val prefs = Prefs.get() +fun Activity.frostNavigationBar(prefs: Prefs) { navigationBarColor = if (prefs.tintNavBar) prefs.headerColor else Color.BLACK } 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 d6e8f9e9..2e5d2fce 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt @@ -71,7 +71,7 @@ enum class WebContextType( OPEN_LINK( R.string.open_link, { it.hasUrl }, - { c, wc, fc -> c.launchWebOverlay(wc.url!!, fc) }), + { c, wc, fc -> c.launchWebOverlay(wc.url!!, fc, Prefs.get()) }), 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) }), -- cgit v1.2.3