Skip to content

Instantly share code, notes, and snippets.

@aasumitro
Created January 25, 2018 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aasumitro/c23df0cd9a339c9a4672c0fa258ba1cb to your computer and use it in GitHub Desktop.
Save aasumitro/c23df0cd9a339c9a4672c0fa258ba1cb to your computer and use it in GitHub Desktop.
Kotlin Preferences Test
class PrefsUtil @Inject constructor(private val sharedPreferences: SharedPreferences) {
fun putBoolean(key: String, value: Boolean): Boolean {
val editor: SharedPreferences.Editor = sharedPreferences.edit()
editor.putBoolean(key, value)
return editor.commit()
}
fun getBoolean(key: String, defaultValue: Boolean): Boolean =
sharedPreferences.getBoolean(key, defaultValue)
fun clearPrefs() = sharedPreferences.edit().clear().clear().apply()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment