diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt | 82 |
1 files changed, 53 insertions, 29 deletions
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) +} |