-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Deprecate kpref double * Update kpref tests and migration * Fix kpref file * Update changelog * Replace changelog angle brackets
- Loading branch information
Showing
6 changed files
with
137 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefTransaction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package ca.allanwang.kau.kpref | ||
|
||
import android.content.SharedPreferences | ||
|
||
internal interface KPrefTransaction<T> { | ||
fun get(prefs: SharedPreferences, key: String, fallback: T): T | ||
fun set(editor: SharedPreferences.Editor, key: String, data: T) | ||
} | ||
|
||
internal object KPrefBooleanTransaction : KPrefTransaction<Boolean> { | ||
override fun get(prefs: SharedPreferences, key: String, fallback: Boolean) = | ||
prefs.getBoolean(key, fallback) | ||
|
||
override fun set(editor: SharedPreferences.Editor, key: String, data: Boolean) { | ||
editor.putBoolean(key, data) | ||
} | ||
} | ||
|
||
internal object KPrefIntTransaction : KPrefTransaction<Int> { | ||
override fun get(prefs: SharedPreferences, key: String, fallback: Int) = | ||
prefs.getInt(key, fallback) | ||
|
||
override fun set(editor: SharedPreferences.Editor, key: String, data: Int) { | ||
editor.putInt(key, data) | ||
} | ||
} | ||
|
||
internal object KPrefLongTransaction : KPrefTransaction<Long> { | ||
override fun get(prefs: SharedPreferences, key: String, fallback: Long) = | ||
prefs.getLong(key, fallback) | ||
|
||
override fun set(editor: SharedPreferences.Editor, key: String, data: Long) { | ||
editor.putLong(key, data) | ||
} | ||
} | ||
|
||
internal object KPrefFloatTransaction : KPrefTransaction<Float> { | ||
override fun get(prefs: SharedPreferences, key: String, fallback: Float) = | ||
prefs.getFloat(key, fallback) | ||
|
||
override fun set(editor: SharedPreferences.Editor, key: String, data: Float) { | ||
editor.putFloat(key, data) | ||
} | ||
} | ||
|
||
internal object KPrefStringTransaction : KPrefTransaction<String> { | ||
override fun get(prefs: SharedPreferences, key: String, fallback: String) = | ||
prefs.getString(key, fallback) | ||
|
||
override fun set(editor: SharedPreferences.Editor, key: String, data: String) { | ||
editor.putString(key, data) | ||
} | ||
} | ||
|
||
internal object KPrefSetTransaction : KPrefTransaction<Set<String>> { | ||
override fun get(prefs: SharedPreferences, key: String, fallback: Set<String>) = | ||
prefs.getStringSet(key, fallback)!! | ||
|
||
override fun set(editor: SharedPreferences.Editor, key: String, data: Set<String>) { | ||
editor.putStringSet(key, data) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters