https://github.com/paulwoitaschek/flowpref
https://github.com/paulwoitaschek/flowpref
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/paulwoitaschek/flowpref
- Owner: PaulWoitaschek
- License: apache-2.0
- Created: 2020-03-16T07:19:07.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-04-08T14:42:08.000Z (6 months ago)
- Last Synced: 2025-04-08T15:43:03.378Z (6 months ago)
- Language: Kotlin
- Size: 247 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DEPRECATED
I recommend to use [Jetpack Datastore](https://developer.android.com/topic/libraries/architecture/datastore) instead.
# FlowPref 
FlowPref is a library for making Preferences composable, typesafe and reactive (by exposing a kotlin Flow).
## Usage
```kotlin
// create a flow pref backed by shared preferences
val sharedPrefs = context.getSharedPreferences("prefName", Context.MODE_PRIVATE)
// ensure this is a singleton across process
val prefs = AndroidPreferences(sharedPrefs)val intPref = prefs.int("prefKey", 42)
// write and get values
intPref.value = 5
println(intPref.value)// flow
scope.launch {
intPref.flow.collect {
println(it)
}
}// use it as a property
var myValue by intPref
myValue = 5
println(myValue)
```## Setup
Add jitpack to your repositories:
```groovy
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
```And add the dependency:
```groovy
dependencies {
// android implementation
implementation 'com.github.PaulWoitaschek.FlowPref:android:x.y.z'
// core only, useful for consuming kotlin-only modules
implementation 'com.github.PaulWoitaschek.FlowPref:core:x.y.z'// an in-memory implementation, useful for testing. Pure kotlin
implementation 'com.github.PaulWoitaschek.FlowPref:in-memory:x.y.z'
}
```