Last active
January 21, 2020 03:31
-
-
Save chibatching/9186eebec7600ab50834c7f96143da63 to your computer and use it in GitHub Desktop.
Save all values include default values declared in KotprefModel
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
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