Created
June 4, 2020 00:11
-
-
Save DjangoLC/ce6827e3a47fbc1d46bc016b0369f36b to your computer and use it in GitHub Desktop.
This file contains 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 UserPreferences(context: Context) { | |
companion object { | |
const val USER_PREFERENCES = "USER_PREFERENCES" | |
const val USER_TOKEN = "USER_TOKEN" | |
} | |
private val preferences = context.applicationContext | |
.getSharedPreferences(USER_PREFERENCES, Context.MODE_PRIVATE) | |
fun getString(key: String): String? { | |
return preferences.getString(key, "") | |
} | |
fun save(key: String, value: String) { | |
with(preferences) { | |
edit { | |
putString(key, value) | |
commit() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment