Use when statement instead of if. Change var to val.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-01-05 18:27:36 +01:00
parent f8b35bddda
commit 94cdbcad0b

View File

@@ -36,21 +36,17 @@ abstract class BaseActivity : AppCompatActivity(),
}
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) {
if (key == "language") {
setLanguage(sharedPreferences.getString("language", null))
}
if (key == "screen_on") {
keepScreenOn(sharedPreferences.getBoolean("screen_on", false))
}
if (key == "theme") {
updateTheme(sharedPreferences.getString("theme", null))
when(key) {
"language" -> setLanguage(sharedPreferences.getString(key, null))
"screen_on" -> keepScreenOn(sharedPreferences.getBoolean(key, false))
"theme" -> updateTheme(sharedPreferences.getString(key, null))
}
}
private fun updateTheme(theme: String?) {
var themeValue = when (theme) {
val themeValue = when (theme) {
"light" -> AppCompatDelegate.MODE_NIGHT_NO
"dark" -> AppCompatDelegate.MODE_NIGHT_YES
"default" -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM