aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/prefs
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2021-04-17 17:08:19 -0700
committerAllan Wang <me@allanwang.ca>2021-04-17 17:08:19 -0700
commit39db7f4c3d7b8f3d68ef1a8881b69624b721f6c6 (patch)
treecb24b739861219861b651aa064a91432f30c681b /app/src/main/kotlin/com/pitchedapps/frost/prefs
parent88a5d17814ff9f7c44f79216510d405f057ae454 (diff)
downloadfrost-39db7f4c3d7b8f3d68ef1a8881b69624b721f6c6.tar.gz
frost-39db7f4c3d7b8f3d68ef1a8881b69624b721f6c6.tar.bz2
frost-39db7f4c3d7b8f3d68ef1a8881b69624b721f6c6.zip
Start hilt injection
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/prefs')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/prefs/Prefs.kt53
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/BehaviourPrefs.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/CorePrefs.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/FeedPrefs.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/NotifPrefs.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ShowcasePrefs.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/prefs/sections/ThemePrefs.kt3
7 files changed, 64 insertions, 7 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..56a7cf9d 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,6 +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 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
import org.koin.core.context.GlobalContext
import org.koin.dsl.module
@@ -73,7 +84,7 @@ interface Prefs :
}
}
-class PrefsImpl(
+class PrefsImpl @Inject internal constructor(
private val behaviourPrefs: BehaviourPrefs,
private val corePrefs: CorePrefs,
private val feedPrefs: FeedPrefs,
@@ -106,3 +117,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..aa40c0d2 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,6 +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 javax.inject.Inject
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
@@ -50,7 +51,7 @@ interface BehaviourPrefs : PrefsBase {
var autoExpandTextBox: Boolean
}
-class BehaviourPrefsImpl(
+class BehaviourPrefsImpl @Inject internal constructor(
factory: KPrefFactory
) : KPref("${BuildConfig.APPLICATION_ID}.prefs.behaviour", factory),
BehaviourPrefs, KoinComponent {
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..13fa5729 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,6 +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 javax.inject.Inject
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
@@ -56,7 +57,7 @@ interface CorePrefs : PrefsBase {
var messageScrollToBottom: Boolean
}
-class CorePrefsImpl(
+class CorePrefsImpl @Inject internal constructor(
factory: KPrefFactory
) : KPref("${BuildConfig.APPLICATION_ID}.prefs.core", factory),
CorePrefs, KoinComponent {
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..17e3bfac 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,6 +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 javax.inject.Inject
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
@@ -51,7 +52,7 @@ interface FeedPrefs : PrefsBase {
var showPostReactions: Boolean
}
-class FeedPrefsImpl(
+class FeedPrefsImpl @Inject internal constructor(
factory: KPrefFactory
) : KPref("${BuildConfig.APPLICATION_ID}.prefs.feed", factory),
FeedPrefs, KoinComponent {
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..c33cd92e 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,6 +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 javax.inject.Inject
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
@@ -48,7 +49,7 @@ interface NotifPrefs : PrefsBase {
var notificationFreq: Long
}
-class NotifPrefsImpl(
+class NotifPrefsImpl @Inject internal constructor(
factory: KPrefFactory
) : KPref("${BuildConfig.APPLICATION_ID}.prefs.notif", factory),
NotifPrefs, KoinComponent {
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..d8a51e32 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,7 +36,7 @@ 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 {
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..126c3654 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
@@ -22,6 +22,7 @@ import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.injectors.ThemeProvider
import com.pitchedapps.frost.prefs.OldPrefs
import com.pitchedapps.frost.prefs.PrefsBase
+import javax.inject.Inject
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
@@ -41,7 +42,7 @@ interface ThemePrefs : PrefsBase {
var tintNavBar: Boolean
}
-class ThemePrefsImpl(
+class ThemePrefsImpl @Inject internal constructor(
factory: KPrefFactory
) : KPref("${BuildConfig.APPLICATION_ID}.prefs.theme", factory),
ThemePrefs, KoinComponent {