Skip to content

Instantly share code, notes, and snippets.

@egorikftp

egorikftp/new.kt Secret

Created August 22, 2021 20:50
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/b2a7787bc956812b97e6e39fc7508773 to your computer and use it in GitHub Desktop.
Save egorikftp/b2a7787bc956812b97e6e39fc7508773 to your computer and use it in GitHub Desktop.
enum class Theme(val storageKey: String) {
LIGHT("light"),
DARK("dark"),
SYSTEM("system")
}
// initialization DataStore with extension
private val dataStore: DataStore<Preferences> = context.dataStore
var selectedTheme by PreferenceDataStore<String>(
dataStore = dataStore,
key = stringPreferencesKey(name = "pref_dark_mode"),
defaultValue = SYSTEM.storageKey
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment