https://github.com/islamdidarmd/kpref
A class that saves time of writing boilerplate code for saving any kind of data in shared preferences
https://github.com/islamdidarmd/kpref
android java kotlin kpref preference shared
Last synced: about 1 year ago
JSON representation
A class that saves time of writing boilerplate code for saving any kind of data in shared preferences
- Host: GitHub
- URL: https://github.com/islamdidarmd/kpref
- Owner: islamdidarmd
- License: mit
- Created: 2019-03-24T05:40:48.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-30T05:11:18.000Z (over 6 years ago)
- Last Synced: 2025-01-22T23:44:12.117Z (about 1 year ago)
- Topics: android, java, kotlin, kpref, preference, shared
- Language: Kotlin
- Homepage:
- Size: 132 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.MD
Awesome Lists containing this project
README
# Kpref
A class that saves time of writing boilerplate code for saving any kind of data in shared preferences
[](https://jitpack.io/#islamdidarmd/Kpref)
## Installation (with Gradle)
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
```groovy
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
Step 2. Add the dependency
```groovy
dependencies {
implementation 'com.github.islamdidarmd:Kpref:0.1.1'
}
```
### How to use
```kotlin
//save values in a default sharedPreference
Kprefs.initDefault(this)
Kprefs.save("test", 10)
val x: Int? = Kprefs.get("")
//save values in your preference
val pref = getSharedPreferences("my_preference", Context.MODE_PRIVATE)
Kprefs.init(pref)
Kprefs.save("testMyPref", "Saved")
val value: String? = Kprefs.get("")
```
You must call `Kprefs.initDefault(this)` or `Kprefs.init(pref)` before calling any methods
For a complete example, see the sample app