Android Library to make SharedPreferences usage easier.

Overview

KotlinPreferences

Kotlin Android Library, that makes preference usage simple and fun.

Build Status Awesome Kotlin Badge GitHub license

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")

Install

To 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

Copyright 2017 Marcin Moskała

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
A fragment binding library - the easier, efficient way.

Byda allprojects { repositories { ... maven { url 'https://jitpack.io' } } } dependencies { implementation 'com.github.Codzure:B

A React Native library making file access easier for developers as first class citizens, without the tears

React Native File Gateway A React Native library making file access easier for developers as first class citizens, without the tears. ⚠️ NOTE: This li

Android utilities for easier and faster Kotlin programming.
Android utilities for easier and faster Kotlin programming.

Android utilities for easier and faster Kotlin programming. Download Gradle compile 'com.costular:kotlin-utils:0.1' How to use It depends on utilities

Native android app made with Kotlin & Compose with example usage of Ktor, SqlDelight.
Native android app made with Kotlin & Compose with example usage of Ktor, SqlDelight.

Delight-Playground 🎉 Native Android application built with Kotlin and Jetpack Compose. This app also illustrates the usage of advance libraries such

Wrapper of FusedLocationProviderClient for Android to support modern usage like LiveData and Flow

FancyLocationProvider Wrapper of FusedLocationProviderClient for Android to support modern usage like LiveData or Flow. Install Add Jitpack repository

Sample application to demonstrate Multi-module Clean MVVM Architecture and usage of Android Hilt, Kotlin Flow, Navigation Graph, Unit tests etc.
Sample application to demonstrate Multi-module Clean MVVM Architecture and usage of Android Hilt, Kotlin Flow, Navigation Graph, Unit tests etc.

MoneyHeist-Chars Sample application to demonstrate Multi-module Clean MVVM Architecture and usage of Android Hilt, Kotlin Flow, Navigation Graph, Room

SharedPreference usage made fun in Kotlin

PreferenceHolder Kotlin Android Library, that makes preference usage simple and fun. To stay up-to-date with news about library This library is younge

A set of extension properties on Int, Long, Double, and Duration, that makes it easier to work with Kotlin Duration

Kotlin Duration Extensions Gradle Groovy repositories { mavenCentral() } implementation 'com.eygraber:kotlin-duration-extensions:1.0.1' Kotlin rep

Disk Usage/Free Utility - a better 'df' alternative
Disk Usage/Free Utility - a better 'df' alternative

duf Disk Usage/Free Utility (Linux, BSD, macOS & Windows) Features User-friendly, colorful output Adjusts to your terminal's theme & width Sort the re

Comments
  • ArrayList goes empty after restarting app

    ArrayList goes empty after restarting app

    Hi, i use below line to add product (data class) to cart in sharedpreference: var CartItems: ArrayList<ResDataClass.Companion.Product> by bindToPreferenceField(arrayListOf()) when app is alive CartItems has values but after restarting app CartItems goes Empty everything except array in sharedpreference has value something's wrong in saving arrays in sharedpreference plz fix it thanks

    opened by nightfury96 0
  • Implement possibility to apply changes immediately with commit() instead of apply()

    Implement possibility to apply changes immediately with commit() instead of apply()

    Existing users will not need to change anything: It is entirely opt-in, without the need for any more options to be set when defining the properties.

    This feature is required in some multithreaded projects in order to avoid race conditions.

    opened by felixdivo 1
Releases(v1.1-beta)
Owner
Marcin Moskała
Teacher, speaker, consultant, founder of Kot. Academy, author of Android Development with Kotlin.
Marcin Moskała
Elixir is a library designed to make minecraft login easier.

Elixir Elixir is a library designed to make minecraft login easier. Usage We have a maven repo for this project. repositories { maven { url = "htt

null 4 Aug 11, 2022
A collection of small utility functions to make it easier to deal with some otherwise nullable APIs on Android.

requireKTX requireKTX is a collection of small utility functions to make it easier to deal with some otherwise nullable APIs on Android, using the sam

Márton Braun 82 Oct 1, 2022
[Android Library] A SharedPreferences helper library to save and fetch the values easily.

Preference Helper A SharedPreferences helper library to save and fetch the values easily. Featured in Use in your project Add this to your module's bu

Naveen T P 13 Apr 4, 2020
A Kotlin library for reactive and boilerplate-free SharedPreferences in Android

KPreferences A Kotlin library for reactive and boilerplate-free Shared Preferences in Android. With KPreferences you can use Kotlin's marvelous delega

Mohamad Amin Mohamadi 19 Dec 16, 2020
The most complete and powerful data-binding library and persistence infra for Kotlin 1.3, Android & Splitties Views DSL, JavaFX & TornadoFX, JSON, JDBC & SQLite, SharedPreferences.

Lychee (ex. reactive-properties) Lychee is a library to rule all the data. ToC Approach to declaring data Properties Other data-binding libraries Prop

Mike 112 Dec 9, 2022
Easy lightweight SharedPreferences library for Android in Kotlin using delegated properties

Easy lightweight SharedPreferences library for Android in Kotlin using delegated properties Idea Delegated properties in Kotlin allow you to execute a

null 25 Dec 27, 2022
Kotpref - Android SharedPreferences delegation library for Kotlin

Kotpref Android SharedPreference delegation for Kotlin. Install repositories { mavenCentral() } dependencies { // core implementation 'co

Takao Chiba 684 Dec 22, 2022
Adapter library for SharedPreferences

EasyPrefs Adapter library for SharedPreferences which reduces boilerplate needed to store simple data, but open enough to not interfere with your own

Kacper Wojciechowski 6 Nov 23, 2021
Android SharedPreferences Helper

PocketDB Android SharedPreferences Helper This is SharedPreferences Helper like a database noSql. Support AES encryption Latest Version Download depen

Muhammad Utsman 9 Jun 20, 2021
Stateful is a Kotlin library which makes Android application development faster and easier.

Stateful Stateful is a Kotlin library which makes Android application development faster and easier. It helps you delete all the boilerplate code for

PicsArt 67 Oct 3, 2022