Skip to content

Instantly share code, notes, and snippets.

@vegeta2102
Created May 23, 2020 08:10
Show Gist options
  • Save vegeta2102/70638de5ac113c9cb75ba02e5249198f to your computer and use it in GitHub Desktop.
Save vegeta2102/70638de5ac113c9cb75ba02e5249198f to your computer and use it in GitHub Desktop.
private val modeChangeListener =
Preference.OnPreferenceChangeListener { preference, newValue ->
Log.i("newValue", newValue.toString())
newValue as? String
when (newValue) {
getString(R.string.pf_light_on) -> {
updateTheme(AppCompatDelegate.MODE_NIGHT_YES)
}
getString(R.string.pf_light_off) -> {
updateTheme(AppCompatDelegate.MODE_NIGHT_NO)
}
else -> {
if (BuildCompat.isAtLeastQ()) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
}
}
}
true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment