android: Fix black backgrounds bug
Start using a specific night mode check because black backgrounds could apply incorrectly when using the light app mode, dark system mode, and black backgrounds. Launching the settings activity will show light mode colors/navigation bars but with black backgrounds.
This commit is contained in:
parent
033adb9723
commit
f2cadc4ce1
|
@ -33,7 +33,13 @@ object ThemeHelper {
|
||||||
DEFAULT -> activity.setTheme(R.style.Theme_Yuzu_Main)
|
DEFAULT -> activity.setTheme(R.style.Theme_Yuzu_Main)
|
||||||
MATERIAL_YOU -> activity.setTheme(R.style.Theme_Yuzu_Main_MaterialYou)
|
MATERIAL_YOU -> activity.setTheme(R.style.Theme_Yuzu_Main_MaterialYou)
|
||||||
}
|
}
|
||||||
if (preferences.getBoolean(Settings.PREF_BLACK_BACKGROUNDS, false)) {
|
|
||||||
|
// Using a specific night mode check because this could apply incorrectly when using the
|
||||||
|
// light app mode, dark system mode, and black backgrounds. Launching the settings activity
|
||||||
|
// will then show light mode colors/navigation bars but with black backgrounds.
|
||||||
|
if (preferences.getBoolean(Settings.PREF_BLACK_BACKGROUNDS, false)
|
||||||
|
&& isNightMode(activity)
|
||||||
|
) {
|
||||||
activity.setTheme(R.style.ThemeOverlay_Yuzu_Dark)
|
activity.setTheme(R.style.ThemeOverlay_Yuzu_Dark)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,18 +90,24 @@ object ThemeHelper {
|
||||||
activity.window,
|
activity.window,
|
||||||
activity.window.decorView
|
activity.window.decorView
|
||||||
)
|
)
|
||||||
val systemReportedThemeMode =
|
|
||||||
activity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
|
||||||
when (themeMode) {
|
when (themeMode) {
|
||||||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM -> when (systemReportedThemeMode) {
|
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM -> when (isNightMode(activity)) {
|
||||||
Configuration.UI_MODE_NIGHT_NO -> setLightModeSystemBars(windowController)
|
false -> setLightModeSystemBars(windowController)
|
||||||
Configuration.UI_MODE_NIGHT_YES -> setDarkModeSystemBars(windowController)
|
true -> setDarkModeSystemBars(windowController)
|
||||||
}
|
}
|
||||||
AppCompatDelegate.MODE_NIGHT_NO -> setLightModeSystemBars(windowController)
|
AppCompatDelegate.MODE_NIGHT_NO -> setLightModeSystemBars(windowController)
|
||||||
AppCompatDelegate.MODE_NIGHT_YES -> setDarkModeSystemBars(windowController)
|
AppCompatDelegate.MODE_NIGHT_YES -> setDarkModeSystemBars(windowController)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isNightMode(activity: AppCompatActivity): Boolean {
|
||||||
|
return when (activity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
|
||||||
|
Configuration.UI_MODE_NIGHT_NO -> false
|
||||||
|
Configuration.UI_MODE_NIGHT_YES -> true
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setLightModeSystemBars(windowController: WindowInsetsControllerCompat) {
|
private fun setLightModeSystemBars(windowController: WindowInsetsControllerCompat) {
|
||||||
windowController.isAppearanceLightStatusBars = true
|
windowController.isAppearanceLightStatusBars = true
|
||||||
windowController.isAppearanceLightNavigationBars = true
|
windowController.isAppearanceLightNavigationBars = true
|
||||||
|
|
Reference in New Issue