在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):MarcinMoskala/KotlinPreferences开源软件地址(OpenSource Url):https://github.com/MarcinMoskala/KotlinPreferences开源编程语言(OpenSource Language):Kotlin 100.0%开源软件介绍(OpenSource Introduction):KotlinPreferencesKotlin Android Library, that makes preference usage simple and fun. KotlinPreferences now have a brother. With KotlinPreferences, you can define different preference fields this way: var SharedPreferences.canEatPie: Boolean by bindToPreferenceField(true) And use it like any SharedPreference property: preferences.canEatPie = true
if(preferences.canEatPie) //... There are different ways to define this properties. Here are some possibilities: (see full example here and usage here) With default value: var SharedPreferences.canEatPie: Boolean by bindToPreferenceField(true)
var SharedPreferences.allPieInTheWorld: Long by bindToPreferenceField(0) Nullable: var SharedPreferences.monstersKilled: Int? by bindToPreferenceFieldNullable()
var SharedPreferences.experience: Float? by bindToPreferenceFieldNullable()
var SharedPreferences.className: String? by bindToPreferenceFieldNullable() Can also keep other objects: var SharedPreferences.character: Character by bindToPreferenceFieldNullable()
var SharedPreferences.savedGame: Game? by bindToPreferenceFieldNullable() Node that this objects are serialized do string using Gson. If they include some, types that needs some serializers, then you need to set gson with converters. Instructions here. Also keys can be specyfied: (this is important to make values immtuable to property name in case of changes in the app) var SharedPreferences.monstersKilled: Int? by bindToPreferenceFieldNullable("MonstersKilledKey")
var SharedPreferences.allPieInTheWorld: Long by bindToPreferenceField(0, "AllPieKey") InstallTo add KotlinPreferences to the project, add in build.gradle file: dependencies {
compile 'com.github.marcinmoskala:kotlinpreferences:1.00'
} And while library is located on JitPack, remember to add on module build.gradle (unless you already have it): repositories {
maven { url 'https://jitpack.io' }
} License
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论