Android icon indicating copy to clipboard operation
Android copied to clipboard

[Bug] App theme stays Light when system theme is set to automatically switch between Dark and Light themes

Open iskandergaba opened this issue 3 years ago • 8 comments

Describe the bug

When I set the system theme to be dark from sunset to sunrise, and set the DDG theme to system default, the app remains in light theme all the time.

How to Reproduce

  1. Set your phone's dark mode to be automatically enabled from sunset to sunrise.
  2. Open DDG app.
  3. Go to Settings.
  4. Set Theme option to "System Default".
  5. Observe that the app always stays in light mode, even during the night.

Expected behavior

The app should be in dark mode from sunset to sunrise in your geographical region, and in light mode from sunrise to sunset. All other apps behave accordingly (Firefox, Bitwarden, Aegis, and Signal are few OSS app examples that behave correctly, might be useful when investigating the root cause of the problem)

Environment

- DDG App Version: 5.111.0
- Device: OnePlus 7T Pro
- OS: Android 11

iskandergaba avatar Feb 06 '22 20:02 iskandergaba

Florisboard had the same issue, if that could help come up with a fix?

https://github.com/florisboard/florisboard/issues/1557

ghost avatar Feb 20 '22 12:02 ghost

This issue occurs only below Android 12

mimi89999 avatar Apr 30 '22 15:04 mimi89999

Also, with System Default web content follows device theme. Only DDG UI does not.

mimi89999 avatar Apr 30 '22 15:04 mimi89999

We faced this problem last week, our investigations leads us to appcompat library upgrade we did, apparently, this bug was happening due to our upgrade to 1.4.1 This bug is documented and reported here https://issuetracker.google.com/issues/188681415

ateek avatar May 01 '22 12:05 ateek

Is there any progress to share on the matter?

ghost avatar Jul 16 '22 16:07 ghost

Dd

Buchko2 avatar Jul 16 '22 16:07 Buchko2

I've got this issue, still isn't fixed.

OnePlus 8T, Android 12

iLynux8888 avatar Aug 27 '22 18:08 iLynux8888

The issue also occurs with battery saver. The system will turn dark, but not the app (Android 12)

ghost avatar Sep 09 '22 14:09 ghost

I still have this issue. To fix it, I have to go into Developer mode in the Android settings and override whatever the issue is. Whenever my phone resets, I have to go back into the Android Developer mode and turn the setting override back on. It's really annoying. Please fix.

bell-kevin avatar Oct 12 '22 19:10 bell-kevin

I think there is need just small fix in Theming.kt:

fun AppCompatActivity.applyTheme(theme: DuckDuckGoTheme): BroadcastReceiver? {
    if (theme == DuckDuckGoTheme.SYSTEM_DEFAULT) {
        val themeId =
            when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
                Configuration.UI_MODE_NIGHT_YES -> THEME_MAP[Pair(manifestThemeId(), DuckDuckGoTheme.DARK)]
                Configuration.UI_MODE_NIGHT_NO -> THEME_MAP[Pair(manifestThemeId(), DuckDuckGoTheme.LIGHT)]
                else -> THEME_MAP[Pair(manifestThemeId(), DuckDuckGoTheme.LIGHT)]
            }
        if (themeId != null) setTheme(themeId)
    } 
    ....
}

And, by the way, in DuckDuckGoActivity there is fun isDarkThemeEnabled(): Boolean which duplicate wrong logic from applyTheme and not in use.

simonvar avatar Oct 19 '22 16:10 simonvar

I think there is need just small fix in Theming.kt:

fun AppCompatActivity.applyTheme(theme: DuckDuckGoTheme): BroadcastReceiver? {
    if (theme == DuckDuckGoTheme.SYSTEM_DEFAULT) {
        val themeId =
            when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
                Configuration.UI_MODE_NIGHT_YES -> THEME_MAP[Pair(manifestThemeId(), DuckDuckGoTheme.DARK)]
                Configuration.UI_MODE_NIGHT_NO -> THEME_MAP[Pair(manifestThemeId(), DuckDuckGoTheme.LIGHT)]
                else -> THEME_MAP[Pair(manifestThemeId(), DuckDuckGoTheme.LIGHT)]
            }
        if (themeId != null) setTheme(themeId)
    } 
    ....
}

And, by the way, in DuckDuckGoActivity there is fun isDarkThemeEnabled(): Boolean which duplicate wrong logic from applyTheme and not in use.

My brother, you figured it out. Guys, push the fix.

iLynux8888 avatar Oct 19 '22 18:10 iLynux8888

Yeah! Push the fix!

bell-kevin avatar Oct 19 '22 19:10 bell-kevin

@malmstein cool theme refactoring, but please fix auto night mode, also this bug now in getThemedDrawable too. UiModeManager provides only static information about night mode (yes/no/auto/custom), needs to get dynamic info about mode from Configuration. I'll provide PR with fix.

simonvar avatar Oct 24 '22 09:10 simonvar

@malmstein can you take a look to the comments inside this issue and the @simonvar proposal? Not sure if you are already addressing the issue inside your current project.

cmonfortep avatar Oct 28 '22 12:10 cmonfortep

Fixed in https://github.com/duckduckgo/Android/pull/2447

malmstein avatar Dec 09 '22 13:12 malmstein