aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt17
1 files changed, 5 insertions, 12 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt
index be16c7c..fbb8c7d 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt
@@ -3,6 +3,7 @@ package ca.allanwang.kau.kpref
import android.content.Context
import android.content.SharedPreferences
import ca.allanwang.kau.kotlin.ILazyResettable
+import ca.allanwang.kau.logging.KL
/**
* Created by Allan Wang on 2017-06-07.
@@ -22,15 +23,13 @@ import ca.allanwang.kau.kotlin.ILazyResettable
*/
open class KPref {
- lateinit private var c: Context
- lateinit internal var PREFERENCE_NAME: String
- private var initialized = false
+ lateinit var PREFERENCE_NAME: String
+ lateinit var sp: SharedPreferences
fun initialize(c: Context, preferenceName: String) {
- if (initialized) throw KPrefException("KPref object $preferenceName has already been initialized; please only do so once")
- initialized = true
- this.c = c.applicationContext
PREFERENCE_NAME = preferenceName
+ sp = c.applicationContext.getSharedPreferences(preferenceName, Context.MODE_PRIVATE)
+ KL.d("Shared Preference $preferenceName has been initialized")
val toDelete = deleteKeys()
if (toDelete.isNotEmpty()) {
val edit = sp.edit()
@@ -39,12 +38,6 @@ open class KPref {
}
}
- //todo hide this
- val sp: SharedPreferences by lazy {
- if (!initialized) throw KPrefException("KPref object has not yet been initialized; please initialize it with a context and preference name")
- c.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)
- }
-
internal val prefMap: MutableMap<String, ILazyResettable<*>> = mutableMapOf()
fun reset() {