https://github.com/drewhamilton/preferoutines
A collection of extension functions for subscribing to SharedPreferences values as Flows.
https://github.com/drewhamilton/preferoutines
android kotlin-coroutines kotlin-flow sharedpreferences
Last synced: 2 months ago
JSON representation
A collection of extension functions for subscribing to SharedPreferences values as Flows.
- Host: GitHub
- URL: https://github.com/drewhamilton/preferoutines
- Owner: drewhamilton
- License: apache-2.0
- Created: 2019-05-16T21:11:29.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-07-15T16:11:13.000Z (almost 4 years ago)
- Last Synced: 2025-03-27T02:43:18.807Z (3 months ago)
- Topics: android, kotlin-coroutines, kotlin-flow, sharedpreferences
- Language: Kotlin
- Homepage:
- Size: 511 KB
- Stars: 6
- Watchers: 0
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Preferoutines
[](https://github.com/drewhamilton/Preferoutines/actions?query=workflow%3ACI+branch%3Amaster)A collection of extension methods for accessing Android SharedPreferences in Kotlin coroutines.
Preferoutines is in pre-release. The API may undergo breaking changes before version 1.0.0 is released.
## Download
[  ](https://bintray.com/drewhamilton/Preferoutines)Preferoutines is available in JCenter.
```groovy
// Preferoutines:
implementation "drewhamilton.preferoutines:preferoutines:$version"// With extra extensions, e.g. for saving enum preferences:
implementation "drewhamilton.preferoutines:preferoutines-extras:$version"
```## Usage
### Preferoutines
Listen to any preference for as long as you want:
```kotlin
exampleScope.launch {
preferences.getStringFlow("Name", "")
.collect { name -> nameView.text = name }
}
```### Extras
Smoothly handle some common cases with extra extensions for enums and non-nullable String and enum values.
```kotlin
exampleScope.launch {
preferences.getNonNullEnumFlow("Theme", Theme.LIGHT)
.collect { theme -> setTheme(theme.resource) }
}
```## License
```
Copyright 2019 Drew HamiltonLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```