https://github.com/justprodev/android-sharedprefs-codegen
A clean way to access the Android app shared preferences
https://github.com/justprodev/android-sharedprefs-codegen
android android-app android-application android-library android-studio sharedpreferences
Last synced: about 1 year ago
JSON representation
A clean way to access the Android app shared preferences
- Host: GitHub
- URL: https://github.com/justprodev/android-sharedprefs-codegen
- Owner: justprodev
- License: apache-2.0
- Created: 2021-12-24T18:07:17.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-27T04:34:38.000Z (over 4 years ago)
- Last Synced: 2025-01-06T07:13:01.177Z (about 1 year ago)
- Topics: android, android-app, android-application, android-library, android-studio, sharedpreferences
- Language: Kotlin
- Homepage:
- Size: 76.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# A clean way to access the shared preferences
**Using**
Create the interface
```kotlin
@SharedPreferences
interface ExamplePreferences {
@Default("3")
var intField: Int?
var stringField: String?
var floatField: Float?
var booleanField: Boolean?
@Default("123")
var floatField2: Float?
@Default("true")
var booleanField2: Boolean?
}
```
- You can access generated class like "ExamplePreferencesImpl(context)" just after build.
- You can use String/Int/Float/Boolean fields.
- By default, all fields should be nullable. (@Default fields can be non-nullable)
- To remove a value from shared preferences: "field=null" (Exception: @Default fields can be non-nullable)
- To define default value, use Default field annotation
- A preference will be named as your interface ("ExamplePreferences"), and sharedpreferences fields will be named as interface fields
**Install**
1. Add `kspVersion=1.6.10-1.0.2` (or other version corresponds to your kotlin's version) to `gradle.properties`
2. Add to `build.gradle` in a module (like `app` or other):
```
plugins {
id 'com.google.devtools.ksp' version "$kspVersion"
// other plugins
}
dependencies {
implementation 'com.github.justprodev:android-sharedprefs-codegen:1.0'
ksp 'com.github.justprodev:android-sharedprefs-codegen:1.0'
testImplementation 'com.github.justprodev:android-sharedprefs-codegen:1.0'
// other dependencies
}
```
*You should have `maven { url 'https://jitpack.io' }` in your repositories list