Skip to content

Instantly share code, notes, and snippets.

@egorikftp

egorikftp/new.kt Secret

Created Aug 22, 2021
Embed
What would you like to do?
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