-
-
Save egorikftp/2e2230b2a91e5a43f91e77bcfa686afc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PreferenceDataStore<T>( | |
private val dataStore: DataStore<Preferences>, | |
private val key: Preferences.Key<T>, | |
private val defaultValue: T | |
) : ReadWriteProperty<Any, T> { | |
@WorkerThread | |
override fun getValue(thisRef: Any, property: KProperty<*>) = | |
dataStore.get(key = key, defaultValue = defaultValue) | |
override fun setValue(thisRef: Any, property: KProperty<*>, value: T) { | |
dataStore.set(key = key, value = value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment