Skip to content

Instantly share code, notes, and snippets.

@egorikftp
Last active August 22, 2021 20:10
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 egorikftp/8f99be16689d9984c4b11d6799d49230 to your computer and use it in GitHub Desktop.
Save egorikftp/8f99be16689d9984c4b11d6799d49230 to your computer and use it in GitHub Desktop.
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)
var theme: String
get() = prefs.getString(PREF_DARK_MODE, SYSTEM.storageKey) ?: SYSTEM.storageKey
set(value) {
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