Use when statement instead of if. Change var to val.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -36,21 +36,17 @@ abstract class BaseActivity : AppCompatActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) {
|
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) {
|
||||||
if (key == "language") {
|
when(key) {
|
||||||
setLanguage(sharedPreferences.getString("language", null))
|
"language" -> setLanguage(sharedPreferences.getString(key, null))
|
||||||
}
|
"screen_on" -> keepScreenOn(sharedPreferences.getBoolean(key, false))
|
||||||
if (key == "screen_on") {
|
"theme" -> updateTheme(sharedPreferences.getString(key, null))
|
||||||
keepScreenOn(sharedPreferences.getBoolean("screen_on", false))
|
|
||||||
}
|
|
||||||
if (key == "theme") {
|
|
||||||
updateTheme(sharedPreferences.getString("theme", null))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun updateTheme(theme: String?) {
|
private fun updateTheme(theme: String?) {
|
||||||
|
|
||||||
var themeValue = when (theme) {
|
val themeValue = when (theme) {
|
||||||
"light" -> AppCompatDelegate.MODE_NIGHT_NO
|
"light" -> AppCompatDelegate.MODE_NIGHT_NO
|
||||||
"dark" -> AppCompatDelegate.MODE_NIGHT_YES
|
"dark" -> AppCompatDelegate.MODE_NIGHT_YES
|
||||||
"default" -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
"default" -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||||
|
|||||||
Reference in New Issue
Block a user