diff options
Diffstat (limited to 'app/src/main')
32 files changed, 213 insertions, 237 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt index 059b2a0e..100aeecb 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt @@ -47,6 +47,7 @@ import org.koin.dsl.module class FrostApp : Application(), KoinComponent { private lateinit var prefs: Prefs + private lateinit var themeProvider: ThemeProvider override fun onCreate() { startKoin { @@ -69,6 +70,7 @@ class FrostApp : Application(), KoinComponent { return } prefs = get() + themeProvider = get() initPrefs() L.i { "Begin Frost for Facebook" } @@ -76,7 +78,7 @@ class FrostApp : Application(), KoinComponent { super.onCreate() - setupNotificationChannels(this, prefs) + setupNotificationChannels(this, themeProvider) scheduleNotificationsFromPrefs(prefs) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt index 17cac703..74d876cb 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt @@ -47,9 +47,11 @@ import com.mikepenz.iconics.typeface.library.community.material.CommunityMateria import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.R +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L import org.koin.android.ext.android.inject +import org.koin.core.component.inject /** * Created by Allan Wang on 2017-06-26. @@ -57,12 +59,13 @@ import org.koin.android.ext.android.inject class AboutActivity : AboutActivityBase(null) { private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() override fun Configs.buildConfigs() { - textColor = prefs.textColor - accentColor = prefs.accentColor - backgroundColor = prefs.bgColor.withMinAlpha(200) - cutoutForeground = prefs.accentColor + textColor = themeProvider.textColor + accentColor = themeProvider.accentColor + backgroundColor = themeProvider.bgColor.withMinAlpha(200) + cutoutForeground = themeProvider.accentColor cutoutDrawableRes = R.drawable.frost_f_200 faqPageTitleRes = R.string.faq_title faqXmlRes = R.xml.frost_faq diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseActivity.kt index d2ba0a92..0553086c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseActivity.kt @@ -22,9 +22,11 @@ import ca.allanwang.kau.internal.KauBaseActivity import ca.allanwang.kau.searchview.SearchViewHolder import com.pitchedapps.frost.contracts.VideoViewHolder import com.pitchedapps.frost.facebook.FbCookie +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.setFrostTheme import org.koin.android.ext.android.inject +import org.koin.core.component.inject /** * Created by Allan Wang on 2017-06-12. @@ -33,6 +35,7 @@ abstract class BaseActivity : KauBaseActivity() { val fbCookie: FbCookie by inject() val prefs: Prefs by inject() + val themeProvider: ThemeProvider by inject() /** * Inherited consumer to customize back press @@ -48,7 +51,7 @@ abstract class BaseActivity : KauBaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (this !is WebOverlayActivityBase) setFrostTheme(prefs) + if (this !is WebOverlayActivityBase) setFrostTheme(themeProvider) } override fun onStop() { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt index e352b2fc..394969cb 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt @@ -210,7 +210,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, } setSupportActionBar(toolbar) viewpager.adapter = adapter - tabs.setBackgroundColor(prefs.mainActivityLayout.backgroundColor(prefs)) + tabs.setBackgroundColor(prefs.mainActivityLayout.backgroundColor(themeProvider)) } onNestedCreate(savedInstanceState) L.i { "Main finished loading UI in ${System.currentTimeMillis() - start} ms" } @@ -288,7 +288,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, drawer.addDrawerListener(toggle) toggle.syncState() - val foregroundColor = ColorStateList.valueOf(prefs.textColor) + val foregroundColor = ColorStateList.valueOf(themeProvider.textColor) with(navigation) { FrostMenuBuilder(this@BaseMainActivity, menu).apply { @@ -317,9 +317,9 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, launchWebOverlay(item.url, fbCookie, prefs) false } - val navBg = prefs.bgColor.withMinAlpha(200) + val navBg = themeProvider.bgColor.withMinAlpha(200) setBackgroundColor(navBg) - itemBackground = createNavDrawable(prefs.accentColor, navBg) + itemBackground = createNavDrawable(themeProvider.accentColor, navBg) itemTextColor = foregroundColor itemIconTintList = foregroundColor @@ -331,7 +331,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, private fun ActivityMainContentBinding.initFab() { hasFab = false shouldShow = false - fab.backgroundTintList = ColorStateList.valueOf(prefs.headerColor.withMinAlpha(200)) + fab.backgroundTintList = ColorStateList.valueOf(themeProvider.headerColor.withMinAlpha(200)) fab.hide() appbar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset -> if (!hasFab) return@OnOffsetChangedListener @@ -351,12 +351,12 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, if (shouldShow) { if (fab.isShown) { fab.fadeScaleTransition { - setIcon(iicon, color = prefs.iconColor) + setIcon(iicon, color = themeProvider.iconColor) } return } } - fab.setIcon(iicon, color = prefs.iconColor) + fab.setIcon(iicon, color = themeProvider.iconColor) fab.showIf(shouldShow) } } @@ -383,7 +383,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, private var pendingUpdate: Boolean = false private val binding = ViewNavHeaderBinding.inflate(layoutInflater) val root: View get() = binding.root - private val optionsBackground = prefs.bgColor.withMinAlpha(200).colorToForeground( + private val optionsBackground = themeProvider.bgColor.withMinAlpha(200).colorToForeground( 0.1f ) @@ -448,7 +448,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, animator.start() } - val textColor = prefs.textColor + val textColor = themeProvider.textColor fun TextView.setOptionsIcon(iicon: IIcon) { setCompoundDrawablesRelativeWithIntrinsicBounds( @@ -458,7 +458,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, null ) setTextColor(textColor) - background = createNavDrawable(prefs.accentColor, optionsBackground) + background = createNavDrawable(themeProvider.accentColor, optionsBackground) } with(optionsLogout) { @@ -506,7 +506,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, arrow.setImageDrawable( GoogleMaterial.Icon.gmd_arrow_drop_down.toDrawable( this@BaseMainActivity, - color = prefs.textColor + color = themeProvider.textColor ) ) } @@ -531,10 +531,10 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, avatarTertiary.setAccount(orderedAccounts.getOrNull(2), false) optionsAccountsContainer.removeAllViews() name.text = orderedAccounts.getOrNull(0)?.name - name.setTextColor(prefs.textColor) + name.setTextColor(themeProvider.textColor) val glide = Glide.with(root) val accountSize = dimenPixelSize(R.dimen.drawer_account_avatar_size) - val textColor = prefs.textColor + val textColor = themeProvider.textColor orderedAccounts.forEach { cookie -> val tv = TextView( @@ -568,7 +568,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, }) tv.text = cookie.name tv.setTextColor(textColor) - tv.background = createNavDrawable(prefs.accentColor, optionsBackground) + tv.background = createNavDrawable(themeProvider.accentColor, optionsBackground) tv.setOnClickListener { switchAccount(cookie.id) } @@ -626,9 +626,9 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_main, menu) - contentBinding.toolbar.tint(prefs.iconColor) + contentBinding.toolbar.tint(themeProvider.iconColor) setMenuIcons( - menu, prefs.iconColor, + menu, themeProvider.iconColor, R.id.action_settings to GoogleMaterial.Icon.gmd_settings, R.id.action_search to GoogleMaterial.Icon.gmd_search ) @@ -638,7 +638,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, private fun bindSearchView(menu: Menu) { searchViewBindIfNull { - bindSearchView(menu, R.id.action_search, prefs.iconColor) { + bindSearchView(menu, R.id.action_search, themeProvider.iconColor) { textCallback = { query, searchView -> val results = searchViewCache[query] if (results != null) @@ -671,8 +671,8 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, ); true } closeListener = { _ -> searchViewCache.clear() } - foregroundColor = prefs.textColor - backgroundColor = prefs.bgColor.withMinAlpha(200) + foregroundColor = themeProvider.textColor + backgroundColor = themeProvider.bgColor.withMinAlpha(200) onItemClick = { _, key, _, _ -> launchWebOverlay(key, fbCookie, prefs) } } } @@ -731,7 +731,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, fragmentChannel.offer(REQUEST_REFRESH) } if (hasRequest(REQUEST_NAV)) { - frostNavigationBar(prefs) + frostNavigationBar(prefs, themeProvider) } if (hasRequest(REQUEST_TEXT_ZOOM)) { fragmentChannel.offer(REQUEST_TEXT_ZOOM) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt index 6067fa82..935b88c9 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt @@ -30,7 +30,7 @@ import com.pitchedapps.frost.R import com.pitchedapps.frost.databinding.ActivityDebugBinding import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.injectors.JsActions -import com.pitchedapps.frost.prefs.Prefs +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.createFreshDir import com.pitchedapps.frost.utils.setFrostColors @@ -39,6 +39,7 @@ import kotlin.coroutines.resume import kotlin.coroutines.suspendCoroutine import kotlinx.coroutines.CoroutineExceptionHandler import org.koin.android.ext.android.inject +import org.koin.core.component.inject /** * Created by Allan Wang on 05/01/18. @@ -52,7 +53,7 @@ class DebugActivity : KauBaseActivity() { fun baseDir(context: Context) = File(context.externalCacheDir, "offline_debug") } - private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() lateinit var binding: ActivityDebugBinding @@ -79,8 +80,8 @@ class DebugActivity : KauBaseActivity() { swipeRefresh.setOnRefreshListener(debugWebview::reload) - fab.visible().setIcon(GoogleMaterial.Icon.gmd_bug_report, prefs.iconColor) - fab.backgroundTintList = ColorStateList.valueOf(prefs.accentColor) + fab.visible().setIcon(GoogleMaterial.Icon.gmd_bug_report, themeProvider.iconColor) + fab.backgroundTintList = ColorStateList.valueOf(themeProvider.accentColor) fab.setOnClickListener { _ -> fab.hide() diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt index 609ed049..7b8ee4d3 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt @@ -55,6 +55,7 @@ import com.pitchedapps.frost.facebook.get import com.pitchedapps.frost.facebook.requests.call import com.pitchedapps.frost.facebook.requests.getFullSizedImageUrl import com.pitchedapps.frost.facebook.requests.requestBuilder +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.services.LocalService import com.pitchedapps.frost.utils.ARG_COOKIE @@ -78,6 +79,7 @@ import kotlinx.coroutines.async import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.koin.android.ext.android.inject +import org.koin.core.component.inject /** * Created by Allan Wang on 2017-07-15. @@ -85,6 +87,7 @@ import org.koin.android.ext.android.inject class ImageActivity : KauBaseActivity() { private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() @Volatile internal var errorRef: Throwable? = null @@ -128,7 +131,7 @@ class ImageActivity : KauBaseActivity() { private var bottomBehavior: BottomSheetBehavior<View>? = null private val baseBackgroundColor = if (prefs.blackMediaBg) Color.BLACK - else prefs.bgColor.withMinAlpha(235) + else themeProvider.bgColor.withMinAlpha(235) private fun loadError(e: Throwable) { if (e.message?.contains("<!DOCTYPE html>") == true) { @@ -178,7 +181,7 @@ class ImageActivity : KauBaseActivity() { if (text.isNullOrBlank()) { imageText.gone() } else { - imageText.setTextColor(if (prefs.blackMediaBg) Color.WHITE else prefs.textColor) + imageText.setTextColor(if (prefs.blackMediaBg) Color.WHITE else themeProvider.textColor) imageText.setBackgroundColor( baseBackgroundColor.colorToForeground(0.2f).withAlpha(255) ) @@ -197,7 +200,7 @@ class ImageActivity : KauBaseActivity() { imageText.bringToFront() } } - val foregroundTint = if (prefs.blackMediaBg) Color.WHITE else prefs.accentColor + val foregroundTint = if (prefs.blackMediaBg) Color.WHITE else themeProvider.accentColor fun ImageView.setState(state: FabStates) { setIcon(state.iicon, color = foregroundTint, sizeDp = 24) @@ -352,7 +355,7 @@ class ImageActivity : KauBaseActivity() { internal enum class FabStates( val iicon: IIcon, - val iconColorProvider: (Prefs) -> Int = { it.iconColor }, + val iconColorProvider: (ThemeProvider) -> Int = { it.iconColor }, val backgroundTint: Int = Int.MAX_VALUE ) { ERROR(GoogleMaterial.Icon.gmd_error, { Color.WHITE }, Color.RED) { @@ -405,9 +408,9 @@ internal enum class FabStates( * https://github.com/AllanWang/KAU/issues/184 * */ - fun update(fab: FloatingActionButton, prefs: Prefs) { - val tint = if (backgroundTint != Int.MAX_VALUE) backgroundTint else prefs.accentColor - val iconColor = iconColorProvider(prefs) + fun update(fab: FloatingActionButton, themeProvider: ThemeProvider) { + val tint = if (backgroundTint != Int.MAX_VALUE) backgroundTint else themeProvider.accentColor + val iconColor = iconColorProvider(themeProvider) if (fab.isHidden) { fab.setIcon(iicon, color = iconColor) fab.backgroundTintList = ColorStateList.valueOf(tint) 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 e8e603ba..f06c3a37 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt @@ -100,21 +100,21 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, else finish(next.x + next.pivotX, next.y + next.pivotY) } skip.setOnClickListener { finish() } - ripple.set(prefs.bgColor) + ripple.set(themeProvider.bgColor) theme() } fun theme() { - statusBarColor = prefs.headerColor - navigationBarColor = prefs.headerColor + statusBarColor = themeProvider.headerColor + navigationBarColor = themeProvider.headerColor with(binding) { - skip.setTextColor(prefs.textColor) - next.imageTintList = ColorStateList.valueOf(prefs.textColor) - indicator.setColour(prefs.textColor) + skip.setTextColor(themeProvider.textColor) + next.imageTintList = ColorStateList.valueOf(themeProvider.textColor) + indicator.setColour(themeProvider.textColor) indicator.invalidate() } fragments.forEach { it.themeFragment() } - setFrostTheme(prefs, true) + setFrostTheme(themeProvider, true) } /** @@ -152,21 +152,21 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ).forEach { it?.animate()?.alpha(0f)?.setDuration(600)?.start() } - if (prefs.textColor != Color.WHITE) { + if (themeProvider.textColor != Color.WHITE) { val f = lastView?.findViewById<ImageView>(R.id.intro_image)?.drawable if (f != null) ValueAnimator.ofFloat(0f, 1f).apply { addUpdateListener { - f.setTint(prefs.textColor.blendWith(Color.WHITE, it.animatedValue as Float)) + f.setTint(themeProvider.textColor.blendWith(Color.WHITE, it.animatedValue as Float)) } duration = 600 start() } } - if (prefs.headerColor != blue) { + if (themeProvider.headerColor != blue) { ValueAnimator.ofFloat(0f, 1f).apply { addUpdateListener { - val c = prefs.headerColor.blendWith(blue, it.animatedValue as Float) + val c = themeProvider.headerColor.blendWith(blue, it.animatedValue as Float) statusBarColor = c navigationBarColor = c } @@ -209,7 +209,7 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, binding.next.fadeScaleTransition { setIcon( if (barHasNext) GoogleMaterial.Icon.gmd_navigate_next else GoogleMaterial.Icon.gmd_done, - color = prefs.textColor + color = themeProvider.textColor ) } binding.skip.animate().scaleXY(if (barHasNext) 1f else 0f) 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 90bec985..9ce16ec7 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt @@ -134,8 +134,8 @@ class SettingsActivity : KPrefActivity() { } override fun kPrefCoreAttributes(): CoreAttributeContract.() -> Unit = { - textColor = { prefs.textColor } - accentColor = { prefs.accentColor } + textColor = { themeProvider.textColor } + accentColor = { themeProvider.accentColor } } override fun onCreateKPrefs(savedInstanceState: Bundle?): KPrefAdapterBuilder.() -> Unit = { @@ -218,18 +218,18 @@ class SettingsActivity : KPrefActivity() { @SuppressLint("MissingSuperCall") override fun onCreate(savedInstanceState: Bundle?) { - setFrostTheme(prefs, true) + setFrostTheme(themeProvider, true) super.onCreate(savedInstanceState) animate = prefs.animate themeExterior(false) } fun themeExterior(animate: Boolean = true) { - if (animate) bgCanvas.fade(prefs.bgColor) - else bgCanvas.set(prefs.bgColor) - if (animate) toolbarCanvas.ripple(prefs.headerColor, RippleCanvas.MIDDLE, RippleCanvas.END) - else toolbarCanvas.set(prefs.headerColor) - frostNavigationBar(prefs) + if (animate) bgCanvas.fade(themeProvider.bgColor) + else bgCanvas.set(themeProvider.bgColor) + if (animate) toolbarCanvas.ripple(themeProvider.headerColor, RippleCanvas.MIDDLE, RippleCanvas.END) + else toolbarCanvas.set(themeProvider.headerColor) + frostNavigationBar(prefs, themeProvider) } override fun onBackPressed() { @@ -244,9 +244,9 @@ class SettingsActivity : KPrefActivity() { override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_settings, menu) - toolbar.tint(prefs.iconColor) + toolbar.tint(themeProvider.iconColor) setMenuIcons( - menu, prefs.iconColor, + menu, themeProvider.iconColor, R.id.action_github to CommunityMaterial.Icon2.cmd_github, R.id.action_changelog to GoogleMaterial.Icon.gmd_info ) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/TabCustomizerActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/TabCustomizerActivity.kt index 589289ab..f2827397 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/TabCustomizerActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/TabCustomizerActivity.kt @@ -69,15 +69,15 @@ class TabCustomizerActivity : BaseActivity() { } fun ActivityTabCustomizerBinding.init() { - pseudoToolbar.setBackgroundColor(prefs.headerColor) + pseudoToolbar.setBackgroundColor(themeProvider.headerColor) tabRecycler.layoutManager = GridLayoutManager(this@TabCustomizerActivity, TAB_COUNT, RecyclerView.VERTICAL, false) tabRecycler.adapter = adapter tabRecycler.setHasFixedSize(true) - divider.setBackgroundColor(prefs.textColor.withAlpha(30)) - instructions.setTextColor(prefs.textColor) + divider.setBackgroundColor(themeProvider.textColor.withAlpha(30)) + instructions.setTextColor(themeProvider.textColor) launch { val tabs = genericDao.getTabs().toMutableList() @@ -94,8 +94,8 @@ class TabCustomizerActivity : BaseActivity() { setResult(Activity.RESULT_CANCELED) - fabSave.setIcon(GoogleMaterial.Icon.gmd_check, prefs.iconColor) - fabSave.backgroundTintList = ColorStateList.valueOf(prefs.accentColor) + fabSave.setIcon(GoogleMaterial.Icon.gmd_check, themeProvider.iconColor) + fabSave.backgroundTintList = ColorStateList.valueOf(themeProvider.accentColor) fabSave.setOnClickListener { launchMain(NonCancellable) { val tabs = adapter.adapterItems.subList(0, TAB_COUNT).map(TabIItem::item) @@ -104,8 +104,8 @@ class TabCustomizerActivity : BaseActivity() { finish() } } - fabCancel.setIcon(GoogleMaterial.Icon.gmd_close, prefs.iconColor) - fabCancel.backgroundTintList = ColorStateList.valueOf(prefs.accentColor) + fabCancel.setIcon(GoogleMaterial.Icon.gmd_close, themeProvider.iconColor) + fabCancel.backgroundTintList = ColorStateList.valueOf(themeProvider.accentColor) fabCancel.setOnClickListener { finish() } setFrostColors { themeWindow = true diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt index c21f7362..42d84eb7 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt @@ -202,14 +202,14 @@ abstract class WebOverlayActivityBase(private val userAgent: String = USER_AGENT setSupportActionBar(toolbar) supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true) - toolbar.navigationIcon = GoogleMaterial.Icon.gmd_close.toDrawable(this, 16, prefs.iconColor) + toolbar.navigationIcon = GoogleMaterial.Icon.gmd_close.toDrawable(this, 16, themeProvider.iconColor) toolbar.setNavigationOnClickListener { finishSlideOut() } setFrostColors { toolbar(toolbar) themeWindow = false } - coordinator.setBackgroundColor(prefs.bgColor.withAlpha(255)) + coordinator.setBackgroundColor(themeProvider.bgColor.withAlpha(255)) content.bind(this) @@ -268,13 +268,13 @@ abstract class WebOverlayActivityBase(private val userAgent: String = USER_AGENT * Our theme for the overlay should be fully opaque */ fun theme() { - val opaqueAccent = prefs.headerColor.withAlpha(255) + val opaqueAccent = themeProvider.headerColor.withAlpha(255) statusBarColor = opaqueAccent.darken() navigationBarColor = opaqueAccent toolbar.setBackgroundColor(opaqueAccent) - toolbar.setTitleTextColor(prefs.iconColor) - coordinator.setBackgroundColor(prefs.bgColor.withAlpha(255)) - toolbar.overflowIcon?.setTint(prefs.iconColor) + toolbar.setTitleTextColor(themeProvider.iconColor) + coordinator.setBackgroundColor(themeProvider.bgColor.withAlpha(255)) + toolbar.overflowIcon?.setTint(themeProvider.iconColor) } override fun onResume() { @@ -309,7 +309,7 @@ abstract class WebOverlayActivityBase(private val userAgent: String = USER_AGENT override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_web, menu) overlayContext?.onMenuCreate(this, menu) - toolbar.tint(prefs.iconColor) + toolbar.tint(themeProvider.iconColor) return true } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt b/app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt index 79a6f188..ec438df1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt @@ -17,15 +17,15 @@ package com.pitchedapps.frost.enums import com.pitchedapps.frost.R -import com.pitchedapps.frost.prefs.Prefs +import com.pitchedapps.frost.injectors.ThemeProvider /** * Created by Allan Wang on 2017-08-19. */ enum class MainActivityLayout( val titleRes: Int, - val backgroundColor: (Prefs) -> Int, - val iconColor: (Prefs) -> Int + val backgroundColor: (ThemeProvider) -> Int, + val iconColor: (ThemeProvider) -> Int ) { TOP_BAR(R.string.top_bar, diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt index 0232694e..c07884bc 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt @@ -34,6 +34,7 @@ import com.pitchedapps.frost.contracts.MainFabContract import com.pitchedapps.frost.enums.FeedSort import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.ARG_URL import com.pitchedapps.frost.utils.L @@ -49,6 +50,7 @@ import kotlinx.coroutines.channels.ReceiveChannel import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import org.koin.android.ext.android.inject +import org.koin.core.component.inject /** * Created by Allan Wang on 2017-11-07. @@ -84,6 +86,7 @@ abstract class BaseFragment : Fragment(), CoroutineScope, FragmentContract, protected val fbCookie: FbCookie by inject() protected val prefs: Prefs by inject() + protected val themeProvider: ThemeProvider by inject() open lateinit var job: Job override val coroutineContext: CoroutineContext get() = ContextHelper.dispatcher + job @@ -201,10 +204,10 @@ abstract class BaseFragment : Fragment(), CoroutineScope, FragmentContract, protected fun FloatingActionButton.update(iicon: IIcon, click: () -> Unit) { if (isShown) { fadeScaleTransition { - setIcon(iicon, prefs.iconColor) + setIcon(iicon, themeProvider.iconColor) } } else { - setIcon(iicon, prefs.iconColor) + setIcon(iicon, themeProvider.iconColor) show() } setOnClickListener { click() } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt b/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt index 47a362b4..0c53a2b1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt @@ -28,6 +28,7 @@ import com.mikepenz.fastadapter.IAdapter import com.mikepenz.fastadapter.select.selectExtension import com.pitchedapps.frost.R import com.pitchedapps.frost.facebook.FbCookie +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.launchWebOverlay import org.koin.core.component.KoinComponent @@ -79,14 +80,14 @@ open class HeaderIItem( class ViewHolder(itemView: View) : FastAdapter.ViewHolder<HeaderIItem>(itemView), KoinComponent { - private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() val text: TextView by bindView(R.id.item_header_text) override fun bindView(item: HeaderIItem, payloads: List<Any>) { - text.setTextColor(prefs.accentColor) + text.setTextColor(themeProvider.accentColor) text.text = item.text - text.setBackgroundColor(prefs.nativeBgColor) + text.setBackgroundColor(themeProvider.nativeBgColor) } override fun unbindView(item: HeaderIItem) { @@ -108,14 +109,14 @@ open class TextIItem( class ViewHolder(itemView: View) : FastAdapter.ViewHolder<TextIItem>(itemView), KoinComponent { - private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() val text: TextView by bindView(R.id.item_text_view) override fun bindView(item: TextIItem, payloads: List<Any>) { - text.setTextColor(prefs.textColor) + text.setTextColor(themeProvider.textColor) text.text = item.text - text.background = createSimpleRippleDrawable(prefs.bgColor, prefs.nativeBgColor) + text.background = createSimpleRippleDrawable(themeProvider.bgColor, themeProvider.nativeBgColor) } override fun unbindView(item: TextIItem) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt index 56e27ccd..8e0d5bec 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt @@ -36,6 +36,7 @@ import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.facebook.parsers.FrostNotif import com.pitchedapps.frost.glide.FrostGlide import com.pitchedapps.frost.glide.GlideApp +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.isIndependent import com.pitchedapps.frost.utils.launchWebOverlay @@ -103,7 +104,7 @@ class NotificationIItem(val notification: FrostNotif, val cookie: String) : class ViewHolder(itemView: View) : FastAdapter.ViewHolder<NotificationIItem>(itemView), KoinComponent { - private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() private val frame: ViewGroup by bindView(R.id.item_frame) private val avatar: ImageView by bindView(R.id.item_avatar) @@ -117,11 +118,11 @@ class NotificationIItem(val notification: FrostNotif, val cookie: String) : override fun bindView(item: NotificationIItem, payloads: List<Any>) { val notif = item.notification frame.background = createSimpleRippleDrawable( - prefs.textColor, - prefs.nativeBgColor(notif.unread) + themeProvider.textColor, + themeProvider.nativeBgColor(notif.unread) ) - content.setTextColor(prefs.textColor) - date.setTextColor(prefs.textColor.withAlpha(150)) + content.setTextColor(themeProvider.textColor) + date.setTextColor(themeProvider.textColor.withAlpha(150)) val glide = glide glide.load(notif.img) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/iitems/TabIItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/iitems/TabIItem.kt index 6f278fe2..0fd39d5c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/iitems/TabIItem.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/iitems/TabIItem.kt @@ -29,7 +29,7 @@ import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.drag.IDraggable import com.pitchedapps.frost.R import com.pitchedapps.frost.facebook.FbItem -import com.pitchedapps.frost.prefs.Prefs +import com.pitchedapps.frost.injectors.ThemeProvider import org.koin.core.component.KoinComponent import org.koin.core.component.inject @@ -45,14 +45,14 @@ class TabIItem(val item: FbItem) : KauIItem<TabIItem.ViewHolder>( class ViewHolder(itemView: View) : FastAdapter.ViewHolder<TabIItem>(itemView), KoinComponent { - private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() val image: ImageView by bindView(R.id.image) val text: TextView by bindView(R.id.text) override fun bindView(item: TabIItem, payloads: List<Any>) { val isInToolbar = adapterPosition < 4 - val color = if (isInToolbar) prefs.iconColor else prefs.textColor + val color = if (isInToolbar) themeProvider.iconColor else themeProvider.textColor image.setIcon(item.item.icon, 20, color) if (isInToolbar) text.invisible() 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 23f4b297..666a6bc5 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/ThemeProvider.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/ThemeProvider.kt @@ -34,6 +34,7 @@ import java.io.BufferedReader import java.io.FileNotFoundException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +import org.koin.core.context.GlobalContext /** * Created by Allan Wang on 2017-05-31. @@ -94,24 +95,24 @@ class ThemeProvider(private val context: Context, private val prefs: Prefs) { context.assets.open("css/${category.folder}/themes/$file").bufferedReader() .use(BufferedReader::readText) if (theme == Theme.CUSTOM) { - val bt = if (Color.alpha(prefs.bgColor) == 255) - prefs.bgColor.toRgbaString() + val bt = if (Color.alpha(bgColor) == 255) + bgColor.toRgbaString() else "transparent" - val bb = prefs.bgColor.colorToForeground(0.35f) + val bb = bgColor.colorToForeground(0.35f) content = content - .replace("\$T\$", prefs.textColor.toRgbaString()) - .replace("\$TT\$", prefs.textColor.colorToBackground(0.05f).toRgbaString()) - .replace("\$A\$", prefs.accentColor.toRgbaString()) - .replace("\$AT\$", prefs.iconColor.toRgbaString()) - .replace("\$B\$", prefs.bgColor.toRgbaString()) + .replace("\$T\$", textColor.toRgbaString()) + .replace("\$TT\$", textColor.colorToBackground(0.05f).toRgbaString()) + .replace("\$A\$", accentColor.toRgbaString()) + .replace("\$AT\$", iconColor.toRgbaString()) + .replace("\$B\$", bgColor.toRgbaString()) .replace("\$BT\$", bt) .replace("\$BBT\$", bb.withAlpha(51).toRgbaString()) - .replace("\$O\$", prefs.bgColor.withAlpha(255).toRgbaString()) + .replace("\$O\$", bgColor.withAlpha(255).toRgbaString()) .replace("\$OO\$", bb.withAlpha(255).toRgbaString()) - .replace("\$D\$", prefs.textColor.adjustAlpha(0.3f).toRgbaString()) + .replace("\$D\$", textColor.adjustAlpha(0.3f).toRgbaString()) .replace("\$TI\$", bb.withAlpha(60).toRgbaString()) .replace("\$C\$", bt) } @@ -139,6 +140,9 @@ class ThemeProvider(private val context: Context, private val prefs: Prefs) { } companion object { + + fun get(): ThemeProvider = GlobalContext.get().get() + fun module() = org.koin.dsl.module { single { ThemeProvider(get(), get()) } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroFragmentTheme.kt b/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroFragmentTheme.kt index 6e735e5b..486b09a9 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroFragmentTheme.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroFragmentTheme.kt @@ -66,7 +66,7 @@ class IntroFragmentTheme : BaseIntroFragment(R.layout.intro_theme) { setOnClickListener { v -> prefs.theme = theme.ordinal (activity as IntroActivity).apply { - binding.ripple.ripple(prefs.bgColor, v.x + v.pivotX, v.y + v.pivotY) + binding.ripple.ripple(themeProvider.bgColor, v.x + v.pivotX, v.y + v.pivotY) theme() } themeList.forEach { it.animate().scaleXY(if (it == this) 1.6f else 0.8f).start() } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroImageFragments.kt b/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroImageFragments.kt index 429171dd..e27d4fee 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroImageFragments.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroImageFragments.kt @@ -57,10 +57,10 @@ abstract class BaseImageIntroFragment( override fun themeFragmentImpl() { super.themeFragmentImpl() - title.setTextColor(prefs.textColor) - desc.setTextColor(prefs.textColor) - phone.tint(prefs.textColor) - screen.tint(prefs.bgColor) + title.setTextColor(themeProvider.textColor) + desc.setTextColor(themeProvider.textColor) + phone.tint(themeProvider.textColor) + screen.tint(themeProvider.bgColor) } fun themeImageComponent(color: Int, vararg id: Int) { @@ -96,9 +96,9 @@ class IntroAccountFragment : BaseImageIntroFragment( override fun themeFragmentImpl() { super.themeFragmentImpl() - themeImageComponent(prefs.iconColor, R.id.intro_phone_avatar_1, R.id.intro_phone_avatar_2) - themeImageComponent(prefs.bgColor.colorToForeground(), R.id.intro_phone_nav) - themeImageComponent(prefs.headerColor, R.id.intro_phone_header) + themeImageComponent(themeProvider.iconColor, R.id.intro_phone_avatar_1, R.id.intro_phone_avatar_2) + themeImageComponent(themeProvider.bgColor.colorToForeground(), R.id.intro_phone_nav) + themeImageComponent(themeProvider.headerColor, R.id.intro_phone_header) } override fun onPageScrolledImpl(positionOffset: Float) { @@ -122,14 +122,14 @@ class IntroTabTouchFragment : BaseImageIntroFragment( override fun themeFragmentImpl() { super.themeFragmentImpl() themeImageComponent( - prefs.iconColor, + themeProvider.iconColor, R.id.intro_phone_icon_1, R.id.intro_phone_icon_2, R.id.intro_phone_icon_3, R.id.intro_phone_icon_4 ) - themeImageComponent(prefs.headerColor, R.id.intro_phone_tab) - themeImageComponent(prefs.textColor.withAlpha(80), R.id.intro_phone_icon_ripple) + themeImageComponent(themeProvider.headerColor, R.id.intro_phone_tab) + themeImageComponent(themeProvider.textColor.withAlpha(80), R.id.intro_phone_icon_ripple) } } @@ -141,21 +141,21 @@ class IntroTabContextFragment : BaseImageIntroFragment( override fun themeFragmentImpl() { super.themeFragmentImpl() - themeImageComponent(prefs.headerColor, R.id.intro_phone_toolbar) - themeImageComponent(prefs.bgColor.colorToForeground(0.1f), R.id.intro_phone_image) + themeImageComponent(themeProvider.headerColor, R.id.intro_phone_toolbar) + themeImageComponent(themeProvider.bgColor.colorToForeground(0.1f), R.id.intro_phone_image) themeImageComponent( - prefs.bgColor.colorToForeground(0.2f), + themeProvider.bgColor.colorToForeground(0.2f), R.id.intro_phone_like, R.id.intro_phone_share ) - themeImageComponent(prefs.bgColor.colorToForeground(0.3f), R.id.intro_phone_comment) + themeImageComponent(themeProvider.bgColor.colorToForeground(0.3f), R.id.intro_phone_comment) themeImageComponent( - prefs.bgColor.colorToForeground(0.1f), + themeProvider.bgColor.colorToForeground(0.1f), R.id.intro_phone_card_1, R.id.intro_phone_card_2 ) themeImageComponent( - prefs.textColor, + themeProvider.textColor, R.id.intro_phone_image_indicator, R.id.intro_phone_comment_indicator, R.id.intro_phone_card_indicator diff --git a/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroMainFragments.kt b/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroMainFragments.kt index d160bee4..8003cb2e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroMainFragments.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroMainFragments.kt @@ -33,9 +33,11 @@ import ca.allanwang.kau.utils.bindViewResettable import ca.allanwang.kau.utils.setOnSingleTapListener import com.pitchedapps.frost.R import com.pitchedapps.frost.activities.IntroActivity +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import kotlin.math.abs import org.koin.android.ext.android.inject +import org.koin.core.component.inject /** * Created by Allan Wang on 2017-07-28. @@ -49,6 +51,7 @@ import org.koin.android.ext.android.inject abstract class BaseIntroFragment(val layoutRes: Int) : Fragment() { protected val prefs: Prefs by inject() + protected val themeProvider: ThemeProvider by inject() val screenWidth get() = resources.displayMetrics.widthPixels @@ -105,7 +108,7 @@ abstract class BaseIntroFragment(val layoutRes: Int) : Fragment() { } protected open fun themeFragmentImpl() { - (view as? ViewGroup)?.children?.forEach { (it as? TextView)?.setTextColor(prefs.textColor) } + (view as? ViewGroup)?.children?.forEach { (it as? TextView)?.setTextColor(themeProvider.textColor) } } protected val viewArray: Array<Array<out View>> by lazyResettableRegistered { viewArray() } @@ -134,7 +137,7 @@ class IntroFragmentWelcome : BaseIntroFragment(R.layout.intro_welcome) { override fun themeFragmentImpl() { super.themeFragmentImpl() - image.imageTintList = ColorStateList.valueOf(prefs.textColor) + image.imageTintList = ColorStateList.valueOf(themeProvider.textColor) } } @@ -146,7 +149,7 @@ class IntroFragmentEnd : BaseIntroFragment(R.layout.intro_end) { override fun themeFragmentImpl() { super.themeFragmentImpl() - image.imageTintList = ColorStateList.valueOf(prefs.textColor) + image.imageTintList = ColorStateList.valueOf(themeProvider.textColor) } @SuppressLint("ClickableViewAccessibility") diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt index 2714b930..d31be432 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt @@ -28,7 +28,7 @@ import com.pitchedapps.frost.prefs.sections.ShowcasePrefs import com.pitchedapps.frost.prefs.sections.ShowcasePrefsImpl import com.pitchedapps.frost.prefs.sections.ThemePrefs import com.pitchedapps.frost.prefs.sections.ThemePrefsImpl -import org.koin.core.context.KoinContextHandler +import org.koin.core.context.GlobalContext import org.koin.dsl.module /** @@ -48,7 +48,7 @@ interface Prefs : ShowcasePrefs, PrefsBase { companion object { - fun get(): Prefs = KoinContextHandler.get().get() + fun get(): Prefs = GlobalContext.get().get() fun module() = module { single<BehaviourPrefs> { BehaviourPrefsImpl(factory = get()) } 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 d997876a..47496d6d 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 @@ -16,16 +16,10 @@ */ package com.pitchedapps.frost.prefs.sections -import android.graphics.Color -import ca.allanwang.kau.kotlin.lazyResettable import ca.allanwang.kau.kpref.KPref import ca.allanwang.kau.kpref.KPrefFactory -import ca.allanwang.kau.utils.colorToForeground -import ca.allanwang.kau.utils.isColorVisibleOn -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.ThemeProvider import com.pitchedapps.frost.prefs.OldPrefs import com.pitchedapps.frost.prefs.PrefsBase import org.koin.core.component.KoinComponent @@ -44,24 +38,6 @@ interface ThemePrefs : PrefsBase { var customIconColor: Int - val textColor: Int - - val accentColor: Int - - val accentColorForWhite: Int - - val nativeBgColor: Int - - fun nativeBgColor(unread: Boolean): Int - - val bgColor: Int - - val headerColor: Int - - val iconColor: Int - - val isCustomTheme: Boolean - var tintNavBar: Boolean } @@ -71,9 +47,10 @@ class ThemePrefsImpl( ThemePrefs, KoinComponent { private val oldPrefs: OldPrefs by inject() + private val themeProvider: ThemeProvider by inject() - override var theme: Int by kpref("theme", oldPrefs.theme /* 0 */) { _: Int -> - loader.invalidate() + override var theme: Int by kpref("theme", oldPrefs.theme /* 0 */) { + themeProvider.setTheme(it) } override var customTextColor: Int by kpref( @@ -101,41 +78,5 @@ class ThemePrefsImpl( oldPrefs.customIconColor /* 0xffeceff1.toInt() */ ) - private val loader = lazyResettable { Theme.values[theme] } - - val t: Theme by loader - - override val textColor: Int - get() = t.textColorGetter(this) - - override val accentColor: Int - get() = t.accentColorGetter(this) - - override val accentColorForWhite: Int - get() = when { - accentColor.isColorVisibleOn(Color.WHITE) -> accentColor - textColor.isColorVisibleOn(Color.WHITE) -> textColor - else -> FACEBOOK_BLUE - } - - override val nativeBgColor: Int - get() = bgColor.withAlpha(30) - - override fun nativeBgColor(unread: Boolean) = bgColor - .colorToForeground(if (unread) 0.7f else 0.0f) - .withAlpha(30) - - override val bgColor: Int - get() = t.backgroundColorGetter(this) - - override val headerColor: Int - get() = t.headerColorGetter(this) - - override val iconColor: Int - get() = t.iconColorGetter(this) - - override val isCustomTheme: Boolean - get() = t == Theme.CUSTOM - override var tintNavBar: Boolean by kpref("tint_nav_bar", oldPrefs.tintNavBar /* true */) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt index 0a90895e..0bb9d254 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt @@ -31,6 +31,7 @@ import androidx.core.app.NotificationCompat import ca.allanwang.kau.utils.color import ca.allanwang.kau.utils.string import com.pitchedapps.frost.R +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.frostUri @@ -41,13 +42,13 @@ import com.pitchedapps.frost.utils.frostUri const val NOTIF_CHANNEL_GENERAL = "general" const val NOTIF_CHANNEL_MESSAGES = "messages" -fun setupNotificationChannels(c: Context, prefs: Prefs) { +fun setupNotificationChannels(c: Context, themeProvider: ThemeProvider) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return val manager = c.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val appName = c.string(R.string.frost_name) val msg = c.string(R.string.messages) - manager.createNotificationChannel(NOTIF_CHANNEL_GENERAL, appName, prefs) - manager.createNotificationChannel(NOTIF_CHANNEL_MESSAGES, "$appName: $msg", prefs) + manager.createNotificationChannel(NOTIF_CHANNEL_GENERAL, appName, themeProvider) + manager.createNotificationChannel(NOTIF_CHANNEL_MESSAGES, "$appName: $msg", themeProvider) manager.notificationChannels .filter { it.id != NOTIF_CHANNEL_GENERAL && @@ -61,14 +62,14 @@ fun setupNotificationChannels(c: Context, prefs: Prefs) { private fun NotificationManager.createNotificationChannel( id: String, name: String, - prefs: Prefs + themeProvider: ThemeProvider ): NotificationChannel { val channel = NotificationChannel( id, name, NotificationManager.IMPORTANCE_DEFAULT ) channel.enableLights(true) - channel.lightColor = prefs.accentColor + channel.lightColor = themeProvider.accentColor channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC createNotificationChannel(channel) return channel 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 4de93a36..64d9dba2 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt @@ -43,7 +43,7 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { header(R.string.theme_customization) - text(R.string.theme, prefs::theme, { prefs.theme = it; themeProvider.setTheme(it) }) { + text(R.string.theme, prefs::theme, { prefs.theme = it }) { onClick = { materialDialog { title(R.string.theme) @@ -55,7 +55,7 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { item.pref = index shouldRestartMain() reload() - setFrostTheme(prefs, true) + setFrostTheme(themeProvider, true) themeExterior() invalidateOptionsMenu() frostEvent("Theme", "Count" to Theme(index).name) @@ -69,7 +69,7 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { } fun KPrefColorPicker.KPrefColorContract.dependsOnCustom() { - enabler = prefs::isCustomTheme + enabler = themeProvider::isCustomTheme onDisabledClick = { frostSnackbar(R.string.requires_custom_theme) } allowCustom = true } @@ -102,7 +102,7 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { prefs.customBackgroundColor = it bgCanvas.ripple(it, duration = 500L) invalidateCustomTheme() - setFrostTheme(prefs, true) + setFrostTheme(themeProvider, true) shouldRestartMain() }) { dependsOnCustom() @@ -111,7 +111,7 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { colorPicker(R.string.header_color, prefs::customHeaderColor, { prefs.customHeaderColor = it - frostNavigationBar(prefs) + frostNavigationBar(prefs, themeProvider) toolbarCanvas.ripple(it, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500L) reload() shouldRestartMain() @@ -160,7 +160,7 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { checkbox(R.string.tint_nav, prefs::tintNavBar, { prefs.tintNavBar = it - frostNavigationBar(prefs) + frostNavigationBar(prefs, themeProvider) setFrostResult(REQUEST_NAV) }) { descRes = R.string.tint_nav_desc 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 ab0e13fd..92bea27a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -183,10 +183,10 @@ fun WebOverlayActivity.url(): String { return intent.getStringExtra(ARG_URL) ?: FbItem.FEED.url } -fun Activity.setFrostTheme(prefs: Prefs, forceTransparent: Boolean = false) { +fun Activity.setFrostTheme(themeProvider: ThemeProvider, forceTransparent: Boolean = false) { val isTransparent = - forceTransparent || (Color.alpha(prefs.bgColor) != 255) || (Color.alpha(prefs.headerColor) != 255) - if (prefs.bgColor.isColorDark) { + forceTransparent || (Color.alpha(themeProvider.bgColor) != 255) || (Color.alpha(themeProvider.headerColor) != 255) + if (themeProvider.bgColor.isColorDark) { setTheme(if (isTransparent) R.style.FrostTheme_Transparent else R.style.FrostTheme) } else { setTheme(if (isTransparent) R.style.FrostTheme_Light_Transparent else R.style.FrostTheme_Light) @@ -263,19 +263,19 @@ fun View.frostSnackbar(@StringRes text: Int, builder: Snackbar.() -> Unit = {}) @SuppressLint("RestrictedApi") private inline fun frostSnackbar(crossinline builder: Snackbar.() -> Unit): Snackbar.() -> Unit = { - val prefs = Prefs.get() + val themeProvider = ThemeProvider.get() 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) + messageView.setTextColor(themeProvider.textColor) + actionView.setTextColor(themeProvider.accentColor) // only set if previous text colors are set - view.setBackgroundColor(prefs.bgColor.withAlpha(255).colorToForeground(0.1f)) + view.setBackgroundColor(themeProvider.bgColor.withAlpha(255).colorToForeground(0.1f)) } } -fun Activity.frostNavigationBar(prefs: Prefs) { - navigationBarColor = if (prefs.tintNavBar) prefs.headerColor else Color.BLACK +fun Activity.frostNavigationBar(prefs: Prefs, themeProvider: ThemeProvider) { + navigationBarColor = if (prefs.tintNavBar) themeProvider.headerColor else Color.BLACK } @Throws(IOException::class) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt index 6ba9ff4d..6eebd36f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt @@ -37,7 +37,7 @@ import com.pitchedapps.frost.db.CookieEntity import com.pitchedapps.frost.facebook.profilePictureUrl import com.pitchedapps.frost.glide.FrostGlide import com.pitchedapps.frost.glide.GlideApp -import com.pitchedapps.frost.prefs.Prefs +import com.pitchedapps.frost.injectors.ThemeProvider import org.koin.core.component.KoinComponent import org.koin.core.component.inject @@ -48,13 +48,13 @@ class AccountItem(val cookie: CookieEntity?) : KauIItem<AccountItem.ViewHolder>(R.layout.view_account, { ViewHolder(it) }, R.id.item_account), KoinComponent { - private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() override fun bindView(holder: ViewHolder, payloads: List<Any>) { super.bindView(holder, payloads) with(holder) { text.invisible() - text.setTextColor(prefs.textColor) + text.setTextColor(themeProvider.textColor) if (cookie != null) { text.text = cookie.name GlideApp.with(itemView).load(profilePictureUrl(cookie.id)) @@ -86,7 +86,7 @@ class AccountItem(val cookie: CookieEntity?) : GoogleMaterial.Icon.gmd_add_circle_outline.toDrawable( itemView.context, 100, - prefs.textColor + themeProvider.textColor ) ) text.text = itemView.context.getString(R.string.kau_add_account) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt index ed94b59f..78af4edf 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt @@ -29,6 +29,7 @@ import ca.allanwang.kau.utils.visible import ca.allanwang.kau.utils.withAlpha import com.mikepenz.iconics.typeface.IIcon import com.pitchedapps.frost.databinding.ViewBadgedIconBinding +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import org.koin.core.component.KoinComponent import org.koin.core.component.inject @@ -43,6 +44,7 @@ class BadgedIcon @JvmOverloads constructor( ) : ConstraintLayout(context, attrs, defStyleAttr), KoinComponent { private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() private val binding: ViewBadgedIconBinding = ViewBadgedIconBinding.inflate(LayoutInflater.from(context), this, true) @@ -52,7 +54,7 @@ class BadgedIcon @JvmOverloads constructor( private fun ViewBadgedIconBinding.init() { val badgeColor = - prefs.mainActivityLayout.backgroundColor(prefs).withAlpha(255).colorToForeground(0.2f) + prefs.mainActivityLayout.backgroundColor(themeProvider).withAlpha(255).colorToForeground(0.2f) val badgeBackground = GradientDrawable( GradientDrawable.Orientation.BOTTOM_TOP, @@ -60,7 +62,7 @@ class BadgedIcon @JvmOverloads constructor( ) badgeBackground.cornerRadius = 13.dpToPx.toFloat() badgeText.background = badgeBackground - badgeText.setTextColor(prefs.mainActivityLayout.iconColor(prefs)) + badgeText.setTextColor(prefs.mainActivityLayout.iconColor(themeProvider)) } var iicon: IIcon? = null @@ -70,13 +72,13 @@ class BadgedIcon @JvmOverloads constructor( value?.toDrawable( context, sizeDp = 20, - color = prefs.mainActivityLayout.iconColor(prefs) + color = prefs.mainActivityLayout.iconColor(themeProvider) ) ) } fun setAllAlpha(alpha: Float) { - // badgeTextView.setTextColor(prefs.textColor.withAlpha(alpha.toInt())) + // badgeTextView.setTextColor(themeProvider.textColor.withAlpha(alpha.toInt())) binding.badgeImage.drawable.alpha = alpha.toInt() } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt index 55f41807..e25b603e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt @@ -39,6 +39,7 @@ import com.pitchedapps.frost.contracts.FrostContentCore import com.pitchedapps.frost.contracts.FrostContentParent import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.facebook.WEB_LOAD_DELAY +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.kotlin.subscribeDuringJob import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L @@ -80,6 +81,7 @@ abstract class FrostContentView<out T> @JvmOverloads constructor( FrostContentParent, KoinComponent where T : View, T : FrostContentCore { private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() private val refresh: SwipeRefreshLayout by bindView(R.id.content_refresh) private val progress: ProgressBar by bindView(R.id.content_progress) val coreView: T by bindView(R.id.content_core) @@ -156,9 +158,9 @@ abstract class FrostContentView<out T> @JvmOverloads constructor( } override fun reloadThemeSelf() { - progress.tint(prefs.textColor.withAlpha(180)) - refresh.setColorSchemeColors(prefs.iconColor) - refresh.setProgressBackgroundColorSchemeColor(prefs.headerColor.withAlpha(255)) + progress.tint(themeProvider.textColor.withAlpha(180)) + refresh.setColorSchemeColors(themeProvider.iconColor) + refresh.setProgressBackgroundColorSchemeColor(themeProvider.headerColor.withAlpha(255)) } override fun reloadTextSizeSelf() { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt index 09be1184..169e7f73 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt @@ -43,6 +43,7 @@ import com.pitchedapps.frost.R import com.pitchedapps.frost.databinding.ViewVideoBinding import com.pitchedapps.frost.db.CookieDao import com.pitchedapps.frost.db.currentCookie +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.ctxCoroutine @@ -88,6 +89,7 @@ class FrostVideoViewer @JvmOverloads constructor( } private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() private val cookieDao: CookieDao by inject() private val binding: ViewVideoBinding = @@ -100,8 +102,8 @@ class FrostVideoViewer @JvmOverloads constructor( fun ViewVideoBinding.init() { alpha = 0f videoBackground.setBackgroundColor( - if (!prefs.blackMediaBg && prefs.bgColor.isColorDark) - prefs.bgColor.withMinAlpha(200) + if (!prefs.blackMediaBg && themeProvider.bgColor.isColorDark) + themeProvider.bgColor.withMinAlpha(200) else Color.BLACK ) @@ -109,7 +111,7 @@ class FrostVideoViewer @JvmOverloads constructor( video.pause() videoToolbar.inflateMenu(R.menu.menu_video) context.setMenuIcons( - videoToolbar.menu, prefs.iconColor, + videoToolbar.menu, themeProvider.iconColor, R.id.action_pip to GoogleMaterial.Icon.gmd_picture_in_picture_alt, R.id.action_download to GoogleMaterial.Icon.gmd_file_download ) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/Keywords.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/Keywords.kt index 0d53608b..c3d5a90e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/Keywords.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/Keywords.kt @@ -37,6 +37,7 @@ import com.mikepenz.fastadapter.listeners.ClickEventHook import com.mikepenz.iconics.typeface.IIcon import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.pitchedapps.frost.R +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import org.koin.core.component.KoinComponent import org.koin.core.component.inject @@ -51,6 +52,7 @@ class Keywords @JvmOverloads constructor( ) : ConstraintLayout(context, attrs, defStyleAttr), KoinComponent { private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() val editText: AppCompatEditText by bindView(R.id.edit_text) val addIcon: ImageView by bindView(R.id.add_icon) val recycler: RecyclerView by bindView(R.id.recycler) @@ -58,8 +60,8 @@ class Keywords @JvmOverloads constructor( init { inflate(context, R.layout.view_keywords, this) - editText.tint(prefs.textColor) - addIcon.setImageDrawable(GoogleMaterial.Icon.gmd_add.keywordDrawable(context, prefs)) + editText.tint(themeProvider.textColor) + addIcon.setImageDrawable(GoogleMaterial.Icon.gmd_add.keywordDrawable(context, themeProvider)) addIcon.setOnClickListener { if (editText.text.isNullOrEmpty()) editText.error = context.string(R.string.empty_keyword) @@ -91,8 +93,8 @@ class Keywords @JvmOverloads constructor( } } -private fun IIcon.keywordDrawable(context: Context, prefs: Prefs): Drawable = - toDrawable(context, 20, prefs.textColor) +private fun IIcon.keywordDrawable(context: Context, themeProvider: ThemeProvider): Drawable = + toDrawable(context, 20, themeProvider.textColor) class KeywordItem(val keyword: String) : AbstractItem<KeywordItem.ViewHolder>() { @@ -116,16 +118,16 @@ class KeywordItem(val keyword: String) : AbstractItem<KeywordItem.ViewHolder>() class ViewHolder(v: View) : RecyclerView.ViewHolder(v), KoinComponent { - private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() val text: AppCompatTextView by bindView(R.id.keyword_text) val delete: ImageView by bindView(R.id.keyword_delete) init { - text.setTextColor(prefs.textColor) + text.setTextColor(themeProvider.textColor) delete.setImageDrawable( GoogleMaterial.Icon.gmd_delete.keywordDrawable( itemView.context, - prefs + themeProvider ) ) } 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 a454584e..fe85ab9c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt @@ -100,7 +100,7 @@ class DebugWebView @JvmOverloads constructor( private fun injectBackgroundColor() { setBackgroundColor( - if (url.isFacebookUrl) prefs.bgColor.withAlpha(255) + if (url.isFacebookUrl) themeProvider.bgColor.withAlpha(255) else Color.WHITE ) } 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 fce4c75a..b5874bf2 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -144,7 +144,7 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { web.setBackgroundColor( when { isMain -> Color.TRANSPARENT - web.url.isFacebookUrl -> prefs.bgColor.withAlpha(255) + web.url.isFacebookUrl -> themeProvider.bgColor.withAlpha(255) else -> Color.WHITE } ) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/widgets/NotificationWidget.kt b/app/src/main/kotlin/com/pitchedapps/frost/widgets/NotificationWidget.kt index aef3fada..3bf37f7d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/widgets/NotificationWidget.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/widgets/NotificationWidget.kt @@ -43,6 +43,7 @@ import com.pitchedapps.frost.db.NotificationDao import com.pitchedapps.frost.db.selectNotificationsSync import com.pitchedapps.frost.glide.FrostGlide import com.pitchedapps.frost.glide.GlideApp +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.services.NotificationContent import com.pitchedapps.frost.services.NotificationType @@ -53,6 +54,7 @@ import org.koin.core.component.inject class NotificationWidget : AppWidgetProvider(), KoinComponent { private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() override fun onUpdate( context: Context, @@ -66,14 +68,14 @@ class NotificationWidget : AppWidgetProvider(), KoinComponent { for (id in appWidgetIds) { val views = RemoteViews(context.packageName, R.layout.widget_notifications) - views.setBackgroundColor(R.id.widget_layout_toolbar, prefs.headerColor) - views.setIcon(R.id.img_frost, context, R.drawable.frost_f_24, prefs.iconColor) + views.setBackgroundColor(R.id.widget_layout_toolbar, themeProvider.headerColor) + views.setIcon(R.id.img_frost, context, R.drawable.frost_f_24, themeProvider.iconColor) views.setOnClickPendingIntent( R.id.img_frost, PendingIntent.getActivity(context, 0, Intent(context, MainActivity::class.java), 0) ) - views.setBackgroundColor(R.id.widget_notification_list, prefs.bgColor) + views.setBackgroundColor(R.id.widget_notification_list, themeProvider.bgColor) views.setRemoteAdapter(R.id.widget_notification_list, intent) val pendingIntentTemplate = PendingIntent.getActivity( @@ -156,7 +158,7 @@ class NotificationWidgetDataProvider(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory, KoinComponent { - private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() private val notifDao: NotificationDao by inject() @@ -192,10 +194,10 @@ class NotificationWidgetDataProvider(val context: Context, val intent: Intent) : val views = RemoteViews(context.packageName, R.layout.widget_notification_item) try { val notif = content[position] - views.setBackgroundColor(R.id.item_frame, prefs.nativeBgColor(notif.unread)) - views.setTextColor(R.id.item_content, prefs.textColor) + views.setBackgroundColor(R.id.item_frame, themeProvider.nativeBgColor(notif.unread)) + views.setTextColor(R.id.item_content, themeProvider.textColor) views.setTextViewText(R.id.item_content, notif.text) - views.setTextColor(R.id.item_date, prefs.textColor.withAlpha(150)) + views.setTextColor(R.id.item_date, themeProvider.textColor.withAlpha(150)) views.setTextViewText(R.id.item_date, notif.timestamp.toReadableTime(context)) val avatar = glide.load(notif.profileUrl).transform(FrostGlide.circleCrop) |