Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SharedPref.kt
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