SharedPreferences delegates for Android
Switch branches/tags
Clone or download
Pull request Compare This branch is 1 commit ahead, 1 commit behind develop.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
delegates-shared-preferences
demo
gradle/wrapper
.gitignore
.travis.yml
LICENSE
README.md
RELEASE-NOTES.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

Build Status Download

Kotlin Delegates for Android SharedPreferences

A set of Kotlin delegates whose values are stored in Android SharedPreferences.

Gradle Build Configuration

To use the library, add another line to build.gradle in your Android project:

dependencies {
    compile 'it.czerwinski.android:delegates-shared-preferences:0.1'
}

Usage

This library uses the concept of Delegated Properties in Kotlin.

class MainActivity : Activity() {

    // Delegate a property in your Activity to a preference with the desired name:
    val username by stringSharedPreference("DEFAULT_USERNAME")

    // If you need to change the value stored in the preference, simply use "var" instead of "val":
    var fontSize by intSharedPreference("SETTINGS_FONT_SIZE")

    // If you don't want nullable types, provide the default value:
    val parentalControl by booleanSharedPreference("SETTINGS_PARENTAL_CONTROL", defaultValue = true)

    // [...]
}