Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Save all values include default values declared in KotprefModel
SomePref::class.declaredMemberProperties
.forEach { property ->
property.isAccessible = true
(property.getDelegate(SomePref) as? AbstractPref<Any>)?.let {
it.setToPreference(property, property.get(SomePref)!!, SomePref.preferences)
println("save preference ${property.name} -> ${property.get(SomePref)}")
}
(property.getDelegate(SomePref) as? AbstractStringSetPref)?.let {
getSharedPreferences(SomePref.kotprefName, Context.MODE_PRIVATE)
.edit()
.putStringSet(it.preferenceKey, property.get(SomePref) as MutableSet<String>)
.commit()
println("save preference ${property.name} -> ${property.get(SomePref)}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment