From 1f9198a1c05223edc7abb095f483d02cda5f1122 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 1 Jul 2019 14:39:46 -0700 Subject: Add in memory kpref variant --- core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt') 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 7a6330f..fc7a76a 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt @@ -36,14 +36,18 @@ import ca.allanwang.kau.logging.KL * You may optionally override [deleteKeys]. This will be called on initialization * And delete all keys returned from that method */ -open class KPref { +open class KPref(builder: KPrefBuilder = KPrefBuilderAndroid) : KPrefBuilder by builder { lateinit var PREFERENCE_NAME: String lateinit var sp: SharedPreferences - fun initialize(c: Context, preferenceName: String) { + fun initialize( + c: Context, + preferenceName: String, + sharedPrefs: SharedPreferences = c.applicationContext.getSharedPreferences(preferenceName, Context.MODE_PRIVATE) + ) { PREFERENCE_NAME = preferenceName - sp = c.applicationContext.getSharedPreferences(preferenceName, Context.MODE_PRIVATE) + sp = sharedPrefs KL.d { "Shared Preference $preferenceName has been initialized" } val toDelete = deleteKeys() if (toDelete.isNotEmpty()) { -- cgit v1.2.3