diff options
Diffstat (limited to 'core/src/main/kotlin')
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt | 10 | ||||
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt | 6 |
2 files changed, 12 insertions, 4 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 a45d66d..7f75370 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt @@ -42,7 +42,7 @@ open class KPref private constructor( internal val prefMap: MutableMap<String, ILazyResettable<*>> = mutableMapOf() - fun add(entry : KPrefDelegate<*>) { + fun add(entry: KPrefDelegate<*>) { if (prefMap.containsKey(entry.key)) throw KPrefException("${entry.key} is already used elsewhere in preference $preferenceName") prefMap[entry.key] = entry @@ -53,4 +53,12 @@ open class KPref private constructor( } operator fun get(key: String): ILazyResettable<*>? = prefMap[key] + + /** + * Exposed key deletion function from builder. + * To avoid recursion, this type uses vararg + */ + fun deleteKeys(vararg keys: String) { + deleteKeys(keys) + } } diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt index b8fb8ea..7a35ac2 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt @@ -71,7 +71,7 @@ interface KPrefBuilder { /** * Remove keys from pref so they revert to the default */ - fun KPref.deleteKeys(keys: Array<String>) + fun KPref.deleteKeys(keys: Array<out String>) } class KPrefBuilderAndroid(val sp: SharedPreferences) : KPrefBuilder { @@ -143,7 +143,7 @@ class KPrefBuilderAndroid(val sp: SharedPreferences) : KPrefBuilder { override fun KPref.kprefSingle(key: String) = KPrefSingleDelegateAndroid(key, this, this@KPrefBuilderAndroid) - override fun KPref.deleteKeys(keys: Array<String>) { + override fun KPref.deleteKeys(keys: Array<out String>) { // Remove pref listing sp.edit().apply { keys.forEach { remove(it) } @@ -179,7 +179,7 @@ object KPrefBuilderInMemory : KPrefBuilder { override fun KPref.kprefSingle(key: String) = KPrefSingleDelegateInMemory(key, this) - override fun KPref.deleteKeys(keys: Array<String>) { + override fun KPref.deleteKeys(keys: Array<out String>) { // Clear cached values keys.forEach { prefMap[it]?.invalidate() } } |