diff options
author | Allan Wang <me@allanwang.ca> | 2021-01-12 20:46:02 -0800 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2021-01-12 20:46:02 -0800 |
commit | 0e5c1ab2dd2b574970883576e18f9a119b058788 (patch) | |
tree | ba715d7a5e0537b9598722e203956fb56d3d5c53 | |
parent | 82fa4c5d6c75e245e74d903328b3e5d96b01b5ca (diff) | |
download | frost-0e5c1ab2dd2b574970883576e18f9a119b058788.tar.gz frost-0e5c1ab2dd2b574970883576e18f9a119b058788.tar.bz2 frost-0e5c1ab2dd2b574970883576e18f9a119b058788.zip |
Create themeprovider
14 files changed, 52 insertions, 42 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt index b2031f96..3248eb14 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt @@ -37,6 +37,7 @@ import com.pitchedapps.frost.db.CookieEntity import com.pitchedapps.frost.db.GenericDao import com.pitchedapps.frost.db.selectAll import com.pitchedapps.frost.facebook.FbCookie +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.BiometricUtils import com.pitchedapps.frost.utils.EXTRA_COOKIES @@ -54,6 +55,7 @@ class StartActivity : KauBaseActivity() { private val fbCookie: FbCookie by inject() private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() private val cookieDao: CookieDao by inject() private val genericDao: GenericDao by inject() @@ -85,7 +87,7 @@ class StartActivity : KauBaseActivity() { transform = CookieEntity::toSensitiveString )}" } - loadAssets(prefs) + loadAssets(themeProvider) authDefer.await() when { cookies.isEmpty() -> launchNewTask<LoginActivity>() diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt index 337c9678..e8e603ba 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt @@ -39,6 +39,7 @@ import ca.allanwang.kau.utils.statusBarColor import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.pitchedapps.frost.R import com.pitchedapps.frost.databinding.ActivityIntroBinding +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.intro.BaseIntroFragment import com.pitchedapps.frost.intro.IntroAccountFragment import com.pitchedapps.frost.intro.IntroFragmentEnd @@ -66,6 +67,7 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.OnPageChangeListener { private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() lateinit var binding: ActivityIntroBinding private var barHasNext = true @@ -176,7 +178,7 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, override fun finish() { launch(NonCancellable) { - loadAssets(prefs) + loadAssets(themeProvider) NotificationWidget.forceUpdate(this@IntroActivity) launchNewTask<MainActivity>(cookies(), false) super.finish() diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt index 3f2cb6ce..90bec985 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt @@ -236,7 +236,7 @@ class SettingsActivity : KPrefActivity() { if (!super.backPress()) { setResult(resultFlag) launch(NonCancellable) { - loadAssets(prefs) + loadAssets(themeProvider) finishSlideOut() } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/enums/Theme.kt b/app/src/main/kotlin/com/pitchedapps/frost/enums/Theme.kt index 3dccc446..1f28d271 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/enums/Theme.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/enums/Theme.kt @@ -88,7 +88,7 @@ enum class Theme( { it.customIconColor }); @VisibleForTesting - internal val file = file?.let { "${it}.css" } + internal val file = file?.let { "$it.css" } companion object { val values = values() // save one instance diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt index 7a65a818..fc4e3fae 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt @@ -21,10 +21,12 @@ package com.pitchedapps.frost.facebook */ const val FACEBOOK_COM = "facebook.com" +const val MESSENGER_COM = "messenger.com" const val FBCDN_NET = "fbcdn.net" const val WWW_FACEBOOK_COM = "www.$FACEBOOK_COM" +const val WWW_MESSENGER_COM = "www.$MESSENGER_COM" const val HTTPS_FACEBOOK_COM = "https://$WWW_FACEBOOK_COM" -const val HTTPS_MESSENGER_COM = "https://www.messenger.com" +const val HTTPS_MESSENGER_COM = "https://$WWW_MESSENGER_COM" const val FACEBOOK_BASE_COM = "m.$FACEBOOK_COM" const val FB_URL_BASE = "https://$FACEBOOK_BASE_COM/" const val FACEBOOK_MBASIC_COM = "mbasic.$FACEBOOK_COM" diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt index 36d51ec9..efaa03ab 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt @@ -28,9 +28,9 @@ import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.cookies import com.pitchedapps.frost.utils.launchLogin -import kotlinx.coroutines.Dispatchers import kotlin.coroutines.resume import kotlin.coroutines.suspendCoroutine +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/ThemeProvider.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/ThemeProvider.kt index 5a9576d2..23f4b297 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/ThemeProvider.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/ThemeProvider.kt @@ -49,33 +49,33 @@ class ThemeProvider(private val context: Context, private val prefs: Prefs) { val textColor: Int get() = theme.textColorGetter(prefs) - val accentColor: Int + val accentColor: Int get() = theme.accentColorGetter(prefs) - val accentColorForWhite: Int + val accentColorForWhite: Int get() = when { accentColor.isColorVisibleOn(Color.WHITE) -> accentColor textColor.isColorVisibleOn(Color.WHITE) -> textColor else -> FACEBOOK_BLUE } - val nativeBgColor: Int + val nativeBgColor: Int get() = bgColor.withAlpha(30) - fun nativeBgColor(unread: Boolean) = bgColor + fun nativeBgColor(unread: Boolean) = bgColor .colorToForeground(if (unread) 0.7f else 0.0f) .withAlpha(30) - val bgColor: Int + val bgColor: Int get() = theme.backgroundColorGetter(prefs) - val headerColor: Int + val headerColor: Int get() = theme.headerColorGetter(prefs) - val iconColor: Int + val iconColor: Int get() = theme.iconColorGetter(prefs) - val isCustomTheme: Boolean + val isCustomTheme: Boolean get() = theme == Theme.CUSTOM /** @@ -91,7 +91,7 @@ class ThemeProvider(private val context: Context, private val prefs: Prefs) { val file = theme.file ?: return JsActions.EMPTY try { var content = - context.assets.open("css/${category.folder}/theme/${file}").bufferedReader() + context.assets.open("css/${category.folder}/themes/$file").bufferedReader() .use(BufferedReader::readText) if (theme == Theme.CUSTOM) { val bt = if (Color.alpha(prefs.bgColor) == 255) @@ -143,4 +143,4 @@ class ThemeProvider(private val context: Context, private val prefs: Prefs) { single { ThemeProvider(get(), get()) } } } -}
\ No newline at end of file +} diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ThemePrefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ThemePrefs.kt index a5a66ee9..d997876a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ThemePrefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ThemePrefs.kt @@ -26,7 +26,6 @@ import ca.allanwang.kau.utils.withAlpha import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.enums.FACEBOOK_BLUE import com.pitchedapps.frost.enums.Theme -import com.pitchedapps.frost.injectors.InjectorContract import com.pitchedapps.frost.prefs.OldPrefs import com.pitchedapps.frost.prefs.PrefsBase import org.koin.core.component.KoinComponent @@ -61,8 +60,6 @@ interface ThemePrefs : PrefsBase { val iconColor: Int - val themeInjector: InjectorContract - val isCustomTheme: Boolean var tintNavBar: Boolean @@ -137,9 +134,6 @@ class ThemePrefsImpl( override val iconColor: Int get() = t.iconColorGetter(this) - override val themeInjector: InjectorContract - get() = t.injector - override val isCustomTheme: Boolean get() = t == Theme.CUSTOM diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt index a5f7ec28..4de93a36 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt @@ -27,7 +27,6 @@ import com.pitchedapps.frost.R import com.pitchedapps.frost.activities.SettingsActivity import com.pitchedapps.frost.enums.MainActivityLayout import com.pitchedapps.frost.enums.Theme -import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.utils.REQUEST_NAV import com.pitchedapps.frost.utils.REQUEST_TEXT_ZOOM import com.pitchedapps.frost.utils.frostEvent 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 883ea9aa..ab0e13fd 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -67,8 +67,8 @@ import com.pitchedapps.frost.facebook.FbUrlFormatter.Companion.VIDEO_REDIRECT import com.pitchedapps.frost.facebook.USER_AGENT import com.pitchedapps.frost.facebook.formattedFbUri import com.pitchedapps.frost.facebook.formattedFbUrl -import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.injectors.JsAssets +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import java.io.File import java.io.IOException @@ -222,21 +222,21 @@ class ActivityThemeUtils : KoinComponent { fun theme(activity: Activity) { with(activity) { - statusBarColor = prefs.headerColor.darken(0.1f).withAlpha(255) - if (prefs.tintNavBar) navigationBarColor = prefs.headerColor - if (themeWindow) window.setBackgroundDrawable(ColorDrawable(prefs.bgColor)) - toolbar?.setBackgroundColor(prefs.headerColor) - toolbar?.setTitleTextColor(prefs.iconColor) - toolbar?.overflowIcon?.setTint(prefs.iconColor) - texts.forEach { it.setTextColor(prefs.textColor) } - headers.forEach { it.setBackgroundColor(prefs.headerColor) } - backgrounds.forEach { it.setBackgroundColor(prefs.bgColor) } + statusBarColor = themeProvider.headerColor.darken(0.1f).withAlpha(255) + if (prefs.tintNavBar) navigationBarColor = themeProvider.headerColor + if (themeWindow) window.setBackgroundDrawable(ColorDrawable(themeProvider.bgColor)) + toolbar?.setBackgroundColor(themeProvider.headerColor) + toolbar?.setTitleTextColor(themeProvider.iconColor) + toolbar?.overflowIcon?.setTint(themeProvider.iconColor) + texts.forEach { it.setTextColor(themeProvider.textColor) } + headers.forEach { it.setBackgroundColor(themeProvider.headerColor) } + backgrounds.forEach { it.setBackgroundColor(themeProvider.bgColor) } } } } -inline fun Activity.setFrostColors(prefs: Prefs, builder: ActivityThemeUtils.() -> Unit) { - val themer = ActivityThemeUtils(prefs) +inline fun Activity.setFrostColors(builder: ActivityThemeUtils.() -> Unit) { + val themer = ActivityThemeUtils() themer.builder() themer.theme(this) } @@ -458,7 +458,7 @@ fun String.unescapeHtml(): String = .replace("\\u003C", "<") .replace("\\\"", "\"") -suspend fun Context.loadAssets(prefs: Prefs): Unit = coroutineScope { - ThemeProvider.load(this@loadAssets, prefs) +suspend fun Context.loadAssets(themeProvider: ThemeProvider): Unit = coroutineScope { + themeProvider.preload() JsAssets.load(this@loadAssets) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt index 34bb5204..e4752d1b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt @@ -34,6 +34,7 @@ import com.pitchedapps.frost.facebook.FB_HOME_URL import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.USER_AGENT import com.pitchedapps.frost.fragments.WebFragment +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.ctxCoroutine @@ -62,6 +63,7 @@ class FrostWebView @JvmOverloads constructor( val fbCookie: FbCookie by inject() val prefs: Prefs by inject() + val themeProvider: ThemeProvider by inject() val cookieDao: CookieDao by inject() override fun reload(animate: Boolean) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt index c68d3f57..a454584e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt @@ -24,9 +24,11 @@ import android.util.AttributeSet import android.view.View import android.webkit.WebView import ca.allanwang.kau.utils.withAlpha +import com.pitchedapps.frost.enums.ThemeCategory import com.pitchedapps.frost.facebook.USER_AGENT -import com.pitchedapps.frost.injectors.CssHider import com.pitchedapps.frost.injectors.CssAsset +import com.pitchedapps.frost.injectors.CssHider +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.injectors.jsInject import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L @@ -50,6 +52,7 @@ class DebugWebView @JvmOverloads constructor( ) : WebView(context, attrs, defStyleAttr), KoinComponent { private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() var onPageFinished: (String?) -> Unit = {} init { @@ -112,7 +115,7 @@ class DebugWebView @JvmOverloads constructor( CssHider.STORIES.maybe(!prefs.showStories), CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!prefs.showSuggestedFriends), CssHider.SUGGESTED_GROUPS.maybe(!prefs.showSuggestedGroups), - prefs.themeInjector, + themeProvider.injector(ThemeCategory.FACEBOOK), CssHider.NON_RECENT.maybe( (url?.contains("?sk=h_chr") ?: false) && prefs.aggressiveRecents diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt index cf248baf..fce4c75a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -23,15 +23,17 @@ import android.webkit.WebResourceResponse import android.webkit.WebView import android.webkit.WebViewClient import ca.allanwang.kau.utils.withAlpha +import com.pitchedapps.frost.enums.ThemeCategory import com.pitchedapps.frost.facebook.FACEBOOK_BASE_COM import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.facebook.WWW_FACEBOOK_COM import com.pitchedapps.frost.facebook.formattedFbUrl -import com.pitchedapps.frost.injectors.CssHider import com.pitchedapps.frost.injectors.CssAsset +import com.pitchedapps.frost.injectors.CssHider import com.pitchedapps.frost.injectors.JsActions import com.pitchedapps.frost.injectors.JsAssets +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.injectors.jsInject import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L @@ -70,6 +72,7 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { private val fbCookie: FbCookie get() = web.fbCookie private val prefs: Prefs get() = web.prefs + private val themeProvider: ThemeProvider get() = web.themeProvider private val refresh: SendChannel<Boolean> = web.parent.refreshChannel private val isMain = web.parent.baseEnum != null @@ -110,7 +113,7 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { CssHider.STORIES.maybe(!prefs.showStories), CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!prefs.showSuggestedFriends), CssHider.SUGGESTED_GROUPS.maybe(!prefs.showSuggestedGroups), - prefs.themeInjector, + themeProvider.injector(ThemeCategory.FACEBOOK), CssHider.NON_RECENT.maybe( (web.url?.contains("?sk=h_chr") ?: false) && prefs.aggressiveRecents diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt index 1a081d2e..fadbadf9 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt @@ -30,12 +30,14 @@ import ca.allanwang.kau.utils.fadeIn import ca.allanwang.kau.utils.isVisible import ca.allanwang.kau.utils.launchMain import com.pitchedapps.frost.db.CookieEntity +import com.pitchedapps.frost.enums.ThemeCategory import com.pitchedapps.frost.facebook.FB_LOGIN_URL import com.pitchedapps.frost.facebook.FB_USER_MATCHER import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.USER_AGENT import com.pitchedapps.frost.facebook.get import com.pitchedapps.frost.injectors.CssHider +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.injectors.jsInject import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L @@ -56,6 +58,7 @@ class LoginWebView @JvmOverloads constructor( private val fbCookie: FbCookie by inject() private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() private val completable: CompletableDeferred<CookieEntity> = CompletableDeferred() private lateinit var progressCallback: (Int) -> Unit @@ -105,7 +108,7 @@ class LoginWebView @JvmOverloads constructor( if (url.isFacebookUrl) view.jsInject( CssHider.CORE, - prefs.themeInjector, + themeProvider.injector(ThemeCategory.FACEBOOK), prefs = prefs ) } |