diff options
author | Allan Wang <me@allanwang.ca> | 2020-02-29 23:35:07 -0800 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2020-02-29 23:35:07 -0800 |
commit | 118635f6630487e93a519e9a63151d95b31ee8b1 (patch) | |
tree | 354c8b0a52866ad62e1b20860517bc5287401cb4 /app/src/main/kotlin/com/pitchedapps/frost/utils | |
parent | 34e5eebbc2dfdd9e71ba200c044f3637ba89aaa2 (diff) | |
parent | e732e30d97babca49ba5f7d97aea1620ba14024b (diff) | |
download | frost-118635f6630487e93a519e9a63151d95b31ee8b1.tar.gz frost-118635f6630487e93a519e9a63151d95b31ee8b1.tar.bz2 frost-118635f6630487e93a519e9a63151d95b31ee8b1.zip |
Merge remote-tracking branch 'origin/dev' into save-image
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils')
3 files changed, 13 insertions, 14 deletions
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<CookieEntity> { */ private inline fun <reified T : WebOverlayActivityBase> 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 <reified T : WebOverlayActivityBase> Context.launchWebOverlay } } -fun Context.launchWebOverlay(url: String, fbCookie: FbCookie) = - launchWebOverlayImpl<WebOverlayActivity>(url, fbCookie) +fun Context.launchWebOverlay(url: String, fbCookie: FbCookie, prefs: Prefs) = + launchWebOverlayImpl<WebOverlayActivity>(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<WebOverlayMobileActivity>(url, fbCookie) +fun Context.launchWebOverlayMobile(url: String, fbCookie: FbCookie, prefs: Prefs) = + launchWebOverlayImpl<WebOverlayMobileActivity>(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) }), |