Skip to content

Instantly share code, notes, and snippets.


egorikftp/new.kt Secret

Created August 22, 2021 20:47
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> {
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