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.
Preferoutines is available in JCenter.
// Preferoutines:
implementation "drewhamilton.preferoutines:preferoutines:$version"
// With extra extensions, e.g. for saving enum preferences:
implementation "drewhamilton.preferoutines:preferoutines-extras:$version"
Listen to any preference for as long as you want:
exampleScope.launch {
preferences.getStringFlow("Name", "<None>")
.collect { name -> nameView.text = name }
}
Smoothly handle some common cases with extra extensions for enums and non-nullable String and enum values.
exampleScope.launch {
preferences.getNonNullEnumFlow("Theme", Theme.LIGHT)
.collect { theme -> setTheme(theme.resource) }
}
Copyright 2019 Drew Hamilton
Licensed 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 at
http://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.