aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt33
1 files changed, 23 insertions, 10 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
index eb8e4b35..8052533b 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
@@ -19,6 +19,7 @@ package com.pitchedapps.frost.utils
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
@@ -29,13 +30,15 @@ import com.pitchedapps.frost.enums.FeedSort
import com.pitchedapps.frost.enums.MainActivityLayout
import com.pitchedapps.frost.enums.Theme
import com.pitchedapps.frost.injectors.InjectorContract
+import org.koin.core.context.GlobalContext
+import org.koin.dsl.module
/**
* Created by Allan Wang on 2017-05-28.
*
* Shared Preference object with lazy cached retrievals
*/
-object Prefs : KPref() {
+class Prefs(factory: KPrefFactory) : KPref("${BuildConfig.APPLICATION_ID}.prefs", factory) {
var lastLaunch: Long by kpref("last_launch", -1L)
@@ -69,15 +72,15 @@ object Prefs : KPref() {
var identifier: Int by kpref("identifier", -1)
- private val loader = lazyResettable { Theme.values[Prefs.theme] }
+ private val loader = lazyResettable { Theme.values[theme] }
val t: Theme by loader
val textColor: Int
- get() = t.textColor
+ get() = t.textColorGetter(this)
val accentColor: Int
- get() = t.accentColor
+ get() = t.accentColorGetter(this)
inline val accentColorForWhite: Int
get() = when {
@@ -87,20 +90,20 @@ object Prefs : KPref() {
}
inline val nativeBgColor: Int
- get() = Prefs.bgColor.withAlpha(30)
+ get() = bgColor.withAlpha(30)
- fun nativeBgColor(unread: Boolean) = Prefs.bgColor
+ fun nativeBgColor(unread: Boolean) = bgColor
.colorToForeground(if (unread) 0.7f else 0.0f)
.withAlpha(30)
val bgColor: Int
- get() = t.bgColor
+ get() = t.backgroundColorGetter(this)
val headerColor: Int
- get() = t.headerColor
+ get() = t.headerColorGetter(this)
val iconColor: Int
- get() = t.iconColor
+ get() = t.iconColorGetter(this)
val themeInjector: InjectorContract
get() = t.injector
@@ -155,6 +158,10 @@ object Prefs : KPref() {
var enablePip: Boolean by kpref("enable_pip", true)
+ /**
+ * Despite the naming, this toggle currently only enables debug logging.
+ * Verbose is never logged in release builds.
+ */
var verboseLogging: Boolean by kpref("verbose_logging", false)
var analytics: Boolean by kpref("analytics", false) {
@@ -194,5 +201,11 @@ object Prefs : KPref() {
inline val mainActivityLayout: MainActivityLayout
get() = MainActivityLayout(mainActivityLayoutType)
- override fun deleteKeys() = arrayOf("search_bar")
+ companion object {
+ fun get(): Prefs = GlobalContext.get().koin.get()
+
+ fun module() = module {
+ single { Prefs(get()) }
+ }
+ }
}