https://github.com/sczerwinski/android-delegates-shared-preferences
SharedPreferences delegates for Android
https://github.com/sczerwinski/android-delegates-shared-preferences
android delegation kotlin kotlin-android sharedpreferences
Last synced: 2 months ago
JSON representation
SharedPreferences delegates for Android
- Host: GitHub
- URL: https://github.com/sczerwinski/android-delegates-shared-preferences
- Owner: sczerwinski
- License: apache-2.0
- Created: 2017-05-11T19:36:39.000Z (about 8 years ago)
- Default Branch: develop
- Last Pushed: 2017-06-11T10:08:43.000Z (almost 8 years ago)
- Last Synced: 2025-01-24T07:28:53.422Z (4 months ago)
- Topics: android, delegation, kotlin, kotlin-android, sharedpreferences
- Language: Kotlin
- Homepage:
- Size: 159 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/sczerwinski/android-delegates-shared-preferences)
[](https://bintray.com/sczerwinski/android/delegates-shared-preferences/_latestVersion)# 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:
```gradle
dependencies {
compile 'it.czerwinski.android:delegates-shared-preferences:0.1'
}
```## Usage
This library uses the concept of
[Delegated Properties](https://kotlinlang.org/docs/reference/delegated-properties.html) in Kotlin.```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)// [...]
}
```