Last active
June 10, 2020 00:47
-
-
Save shafty023/cd04db60d0cb7e7ea267ffff495cf959 to your computer and use it in GitHub Desktop.
Messy preferences
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
@Singleton | |
class Preferences(context: Context) { | |
private val prefs: SharedPreferences = context.getSharedPreferences("Prefs", Context.MODE_PRIVATE) | |
companion object { | |
const val PREF_CURRENT_STATE = "CurrentState" | |
const val PREF_LAST_KNOWN_ERROR = "LastKnownError" | |
const val PREF_LAST_ACTION_PERFORMED = "LastActionPerformed" | |
} | |
fun getCurrentState() = prefs.getInt(PREF_CURRENT_STATE, 0) | |
fun setCurrentState(currentState: Int) { | |
prefs.edit().putInt(PREF_CURRENT_STATE, currentState).apply() | |
} | |
fun getLastKnownError() = prefs.getString(PREF_LAST_KNOWN_ERROR, "") | |
fun setLastKnownError(lastKnownError: String) { | |
prefs.edit().putString(PREF_LAST_KNOWN_ERROR, lastKnownError).apply() | |
} | |
fun getLastActionPerformed() = prefs.getString(PREF_LAST_ACTION_PERFORMED, "") | |
fun setLastActionPerformed(lastAction: String) { | |
prefs.edit().putString(PREF_LAST_ACTION_PERFORMED, lastAction).apply() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment