Replace if with when for better readability

pull/1718/head
Andrea Severi 9 months ago
parent 23187117f9
commit 13d8eee34c
No known key found for this signature in database
GPG Key ID: BF5DFA9B836FBEC3

@ -185,21 +185,17 @@ private fun setAppTheme(
themeSettings: ThemeSettings, themeSettings: ThemeSettings,
) { ) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val mode = if (themeSettings.shouldFollowSystemTheme) { val mode = when {
UiModeManager.MODE_NIGHT_AUTO themeSettings.shouldFollowSystemTheme -> UiModeManager.MODE_NIGHT_AUTO
} else if (themeSettings.darkTheme) { themeSettings.darkTheme -> UiModeManager.MODE_NIGHT_YES
UiModeManager.MODE_NIGHT_YES else -> UiModeManager.MODE_NIGHT_NO
} else {
UiModeManager.MODE_NIGHT_NO
} }
uiModeManager.setApplicationNightMode(mode) uiModeManager.setApplicationNightMode(mode)
} else { } else {
val mode = if (themeSettings.shouldFollowSystemTheme) { val mode = when {
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM themeSettings.shouldFollowSystemTheme -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
} else if (themeSettings.darkTheme) { themeSettings.darkTheme -> AppCompatDelegate.MODE_NIGHT_YES
AppCompatDelegate.MODE_NIGHT_YES else -> AppCompatDelegate.MODE_NIGHT_NO
} else {
AppCompatDelegate.MODE_NIGHT_NO
} }
AppCompatDelegate.setDefaultNightMode(mode) AppCompatDelegate.setDefaultNightMode(mode)
} }

Loading…
Cancel
Save