Last active
August 22, 2021 20:02
-
-
Save egorikftp/d68b51a159a96ec91aa572346bb59ad5 to your computer and use it in GitHub Desktop.
SharedPref.kt
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
enum class Theme(val storageKey: String) { | |
LIGHT("light"), | |
DARK("dark"), | |
SYSTEM("system") | |
} | |
private const val PREF_DARK_MODE = "pref_dark_mode" | |
private val prefs: SharedPreferences = context.getSharedPreferences("PREFERENCES_NAME", Context.MODE_PRIVATE) | |
fun getTheme(): String = prefs.getString(PREF_DARK_MODE, SYSTEM.storageKey) | |
?: SYSTEM.storageKey | |
fun updateTheme(value: String) { | |
prefs.edit { | |
putString(PREF_DARK_MODE, value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment