Created
May 23, 2020 08:10
-
-
Save vegeta2102/70638de5ac113c9cb75ba02e5249198f to your computer and use it in GitHub Desktop.
This file contains 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
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