KMP Object Preference Loader
-
What's new in 3.1
- Objectify now works both on Android and JVM project.
-
What's new in 3.0
- Replace (migrate) shared preferences with datastore preferences.
-
Dependence:
compile 'bz.tsung.kmp:objectify:3.1.3'
-
Usage:
-
Init
// for android AndroidObjectify.init( context = context, keysToMigrate = setOf(key1, key2), migrateAll = false, storeName = "awesome_app") // for jvm JvmObjectify.init( storePath = "/my/path/to/settings", storeName = "awesome_app")
-
Save
ObjectPreferenceLoader(keyOfPreference, Model::class.java).set(model)
-
Load
val model: Model = ObjectPreferenceLoader(keyOfPreference, Model::class.java).get()
-
List
val models: ArrayList<Model> = ObjectPreferenceLoader(keyOfPreference, object : TypeToken<ArrayList<Model>>() {}.type).get()
-
Remove
IntPreferenceLoader(keyOfPreference).remove()
-
-
Warning:
PreferenceLoader.clear() method will remove all preferences!
-
Tips:
In case u want to register type for gson, u can pass gson to constructor:
ObjectPreferenceLoader(keyOfPreference, Model::class.java, gson)
-
Developer:
Tsung Wu (@ionull) [email protected]