diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/prefs')
8 files changed, 89 insertions, 78 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/OldPrefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/OldPrefs.kt index 1abed8fb..cfd8edbd 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/prefs/OldPrefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/OldPrefs.kt @@ -20,6 +20,7 @@ import ca.allanwang.kau.kpref.KPref import ca.allanwang.kau.kpref.KPrefFactory import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.enums.FeedSort +import javax.inject.Inject /** * Created by Allan Wang on 2017-05-28. @@ -29,7 +30,8 @@ import com.pitchedapps.frost.enums.FeedSort * As of 2020-07-18, prefs have been split up into multiple folders */ @Deprecated(level = DeprecationLevel.WARNING, message = "Use pref segments") -class OldPrefs(factory: KPrefFactory) : KPref("${BuildConfig.APPLICATION_ID}.prefs", factory) { +class OldPrefs @Inject internal constructor(factory: KPrefFactory) : + KPref("${BuildConfig.APPLICATION_ID}.prefs", factory) { var lastLaunch: Long by kpref("last_launch", -1L) 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 d31be432..0cf97c56 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt @@ -16,6 +16,9 @@ */ package com.pitchedapps.frost.prefs +import android.content.Context +import ca.allanwang.kau.kpref.KPrefFactory +import ca.allanwang.kau.kpref.KPrefFactoryAndroid import com.pitchedapps.frost.prefs.sections.BehaviourPrefs import com.pitchedapps.frost.prefs.sections.BehaviourPrefsImpl import com.pitchedapps.frost.prefs.sections.CorePrefs @@ -28,8 +31,14 @@ 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.GlobalContext -import org.koin.dsl.module +import dagger.Binds +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.android.qualifiers.ApplicationContext +import dagger.hilt.components.SingletonComponent +import javax.inject.Inject +import javax.inject.Singleton /** * [Prefs] is no longer an actual pref, but we will expose the reset function as it is used elsewhere @@ -46,34 +55,9 @@ interface Prefs : NotifPrefs, ThemePrefs, ShowcasePrefs, - PrefsBase { - companion object { - fun get(): Prefs = GlobalContext.get().get() + PrefsBase - fun module() = module { - single<BehaviourPrefs> { BehaviourPrefsImpl(factory = get()) } - single<CorePrefs> { CorePrefsImpl(factory = get()) } - single<FeedPrefs> { FeedPrefsImpl(factory = get()) } - single<NotifPrefs> { NotifPrefsImpl(factory = get()) } - single<ThemePrefs> { ThemePrefsImpl(factory = get()) } - single<ShowcasePrefs> { ShowcasePrefsImpl(factory = get()) } - single<Prefs> { - PrefsImpl( - behaviourPrefs = get(), - corePrefs = get(), - feedPrefs = get(), - notifPrefs = get(), - themePrefs = get(), - showcasePrefs = get() - ) - } - // Needed for migration - single<OldPrefs> { OldPrefs(factory = get()) } - } - } -} - -class PrefsImpl( +class PrefsImpl @Inject internal constructor( private val behaviourPrefs: BehaviourPrefs, private val corePrefs: CorePrefs, private val feedPrefs: FeedPrefs, @@ -106,3 +90,43 @@ class PrefsImpl( showcasePrefs.deleteKeys() } } + +@Module +@InstallIn(SingletonComponent::class) +interface PrefModule { + @Binds + @Singleton + fun behaviour(to: BehaviourPrefsImpl): BehaviourPrefs + + @Binds + @Singleton + fun core(to: CorePrefsImpl): CorePrefs + + @Binds + @Singleton + fun feed(to: FeedPrefsImpl): FeedPrefs + + @Binds + @Singleton + fun notif(to: NotifPrefsImpl): NotifPrefs + + @Binds + @Singleton + fun theme(to: ThemePrefsImpl): ThemePrefs + + @Binds + @Singleton + fun showcase(to: ShowcasePrefsImpl): ShowcasePrefs + + @Binds + @Singleton + fun prefs(to: PrefsImpl): Prefs +} + +@Module +@InstallIn(SingletonComponent::class) +object PrefFactoryModule { + @Provides + @Singleton + fun factory(@ApplicationContext context: Context): KPrefFactory = KPrefFactoryAndroid(context) +} diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/BehaviourPrefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/BehaviourPrefs.kt index 9d621048..8842d988 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/BehaviourPrefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/BehaviourPrefs.kt @@ -21,8 +21,7 @@ import ca.allanwang.kau.kpref.KPrefFactory import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.prefs.OldPrefs import com.pitchedapps.frost.prefs.PrefsBase -import org.koin.core.component.KoinComponent -import org.koin.core.component.inject +import javax.inject.Inject interface BehaviourPrefs : PrefsBase { var biometricsEnabled: Boolean @@ -50,12 +49,10 @@ interface BehaviourPrefs : PrefsBase { var autoExpandTextBox: Boolean } -class BehaviourPrefsImpl( - factory: KPrefFactory -) : KPref("${BuildConfig.APPLICATION_ID}.prefs.behaviour", factory), - BehaviourPrefs, KoinComponent { - - private val oldPrefs: OldPrefs by inject() +class BehaviourPrefsImpl @Inject internal constructor( + factory: KPrefFactory, + oldPrefs: OldPrefs, +) : KPref("${BuildConfig.APPLICATION_ID}.prefs.behaviour", factory), BehaviourPrefs { override var biometricsEnabled: Boolean by kpref( "biometrics_enabled", diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/CorePrefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/CorePrefs.kt index 6d3885cb..880a7225 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/CorePrefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/CorePrefs.kt @@ -21,8 +21,7 @@ import ca.allanwang.kau.kpref.KPrefFactory import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.prefs.OldPrefs import com.pitchedapps.frost.prefs.PrefsBase -import org.koin.core.component.KoinComponent -import org.koin.core.component.inject +import javax.inject.Inject interface CorePrefs : PrefsBase { var lastLaunch: Long @@ -56,12 +55,10 @@ interface CorePrefs : PrefsBase { var messageScrollToBottom: Boolean } -class CorePrefsImpl( - factory: KPrefFactory -) : KPref("${BuildConfig.APPLICATION_ID}.prefs.core", factory), - CorePrefs, KoinComponent { - - private val oldPrefs: OldPrefs by inject() +class CorePrefsImpl @Inject internal constructor( + factory: KPrefFactory, + oldPrefs: OldPrefs, +) : KPref("${BuildConfig.APPLICATION_ID}.prefs.core", factory), CorePrefs { override var lastLaunch: Long by kpref("last_launch", oldPrefs.lastLaunch /* -1L */) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/FeedPrefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/FeedPrefs.kt index 3fe2cfd8..00df9743 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/FeedPrefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/FeedPrefs.kt @@ -22,8 +22,7 @@ import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.enums.MainActivityLayout import com.pitchedapps.frost.prefs.OldPrefs import com.pitchedapps.frost.prefs.PrefsBase -import org.koin.core.component.KoinComponent -import org.koin.core.component.inject +import javax.inject.Inject interface FeedPrefs : PrefsBase { var webTextScaling: Int @@ -51,12 +50,10 @@ interface FeedPrefs : PrefsBase { var showPostReactions: Boolean } -class FeedPrefsImpl( - factory: KPrefFactory -) : KPref("${BuildConfig.APPLICATION_ID}.prefs.feed", factory), - FeedPrefs, KoinComponent { - - private val oldPrefs: OldPrefs by inject() +class FeedPrefsImpl @Inject internal constructor( + factory: KPrefFactory, + oldPrefs: OldPrefs +) : KPref("${BuildConfig.APPLICATION_ID}.prefs.feed", factory), FeedPrefs { override var webTextScaling: Int by kpref("web_text_scaling", oldPrefs.webTextScaling /* 100 */) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/NotifPrefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/NotifPrefs.kt index a9a6956f..5e34c105 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/NotifPrefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/NotifPrefs.kt @@ -21,8 +21,7 @@ import ca.allanwang.kau.kpref.KPrefFactory import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.prefs.OldPrefs import com.pitchedapps.frost.prefs.PrefsBase -import org.koin.core.component.KoinComponent -import org.koin.core.component.inject +import javax.inject.Inject interface NotifPrefs : PrefsBase { var notificationKeywords: Set<String> @@ -48,12 +47,10 @@ interface NotifPrefs : PrefsBase { var notificationFreq: Long } -class NotifPrefsImpl( - factory: KPrefFactory -) : KPref("${BuildConfig.APPLICATION_ID}.prefs.notif", factory), - NotifPrefs, KoinComponent { - - private val oldPrefs: OldPrefs by inject() +class NotifPrefsImpl @Inject internal constructor( + factory: KPrefFactory, + oldPrefs: OldPrefs, +) : KPref("${BuildConfig.APPLICATION_ID}.prefs.notif", factory), NotifPrefs { override var notificationKeywords: Set<String> by kpref( "notification_keywords", diff --git a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ShowcasePrefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ShowcasePrefs.kt index 516a14c5..dce8b898 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ShowcasePrefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ShowcasePrefs.kt @@ -20,6 +20,7 @@ import ca.allanwang.kau.kpref.KPref import ca.allanwang.kau.kpref.KPrefFactory import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.prefs.PrefsBase +import javax.inject.Inject interface ShowcasePrefs : PrefsBase { /** @@ -35,10 +36,9 @@ interface ShowcasePrefs : PrefsBase { * * Showcase prefs that offer one time helpers to guide new users */ -class ShowcasePrefsImpl( +class ShowcasePrefsImpl @Inject internal constructor( factory: KPrefFactory -) : KPref("${BuildConfig.APPLICATION_ID}.showcase", factory), - ShowcasePrefs { +) : KPref("${BuildConfig.APPLICATION_ID}.showcase", factory), ShowcasePrefs { override val firstWebOverlay: Boolean by kprefSingle("first_web_overlay") 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 47496d6d..b024b2d3 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 @@ -19,11 +19,9 @@ package com.pitchedapps.frost.prefs.sections import ca.allanwang.kau.kpref.KPref import ca.allanwang.kau.kpref.KPrefFactory import com.pitchedapps.frost.BuildConfig -import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.OldPrefs import com.pitchedapps.frost.prefs.PrefsBase -import org.koin.core.component.KoinComponent -import org.koin.core.component.inject +import javax.inject.Inject interface ThemePrefs : PrefsBase { var theme: Int @@ -41,17 +39,16 @@ interface ThemePrefs : PrefsBase { var tintNavBar: Boolean } -class ThemePrefsImpl( - factory: KPrefFactory -) : KPref("${BuildConfig.APPLICATION_ID}.prefs.theme", factory), - ThemePrefs, KoinComponent { +class ThemePrefsImpl @Inject internal constructor( + factory: KPrefFactory, + oldPrefs: OldPrefs, +) : KPref("${BuildConfig.APPLICATION_ID}.prefs.theme", factory), ThemePrefs { - private val oldPrefs: OldPrefs by inject() - private val themeProvider: ThemeProvider by inject() - - override var theme: Int by kpref("theme", oldPrefs.theme /* 0 */) { - themeProvider.setTheme(it) - } + /** + * Note that this is purely for the pref storage. Updating themes should use + * ThemeProvider + */ + override var theme: Int by kpref("theme", oldPrefs.theme /* 0 */) override var customTextColor: Int by kpref( "color_text", |