-
-
Save egorikftp/de0579d1bcd29d783ebec72a5b21a727 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 StringPreference( | |
private val preferences: SharedPreferences, | |
private val name: String, | |
private val defaultValue: String | |
) : ReadWriteProperty<Any, String?> { | |
@WorkerThread | |
override fun getValue(thisRef: Any, property: KProperty<*>) = | |
preferences.getString(name, defaultValue) ?: defaultValue | |
override fun setValue(thisRef: Any, property: KProperty<*>, value: String?) { | |
preferences.edit { | |
putString(name, value) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment