Kotpref: Easy SharedPreferences library for Kotlin android
Using SharedPreferences needs some little boilerplate code. And if we store much more data or include/exclude specific data from auto backup, we should consider to split XML file.
Kotpref is the library to make you realizing it simply and ease.
To install, just add app dependency in build.gradle.
Kotpref.init(context) function in
onCreate at Application class.
Kotpref requires defining data model to save into SharedPreferences. Data model can be created by extending `KotprefModel` like below.
You can now write and read by same way with normal property access!!
Saved SharedPreferences XML through Kotpref is separated by Class name. At the above example, file name is
Profile.xml and content is below.
So, you can include/exclude each XML file (KotprefModel object) as auto backup target.
Kotpref core module only support basic SharedPreferences value type (String, Int, Long, Float, Boolean, String set). Although there are sub modules to support kotlin enum and gson serialized object.
Let’s try if you develop Android application with kotlin!
Kotpref and I welcome to your contiribute! Please feel free to give your feedbacks!