question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
simonvarcommented, Oct 19, 2022

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.

2reactions
simonvarcommented, Oct 24, 2022

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dark theme - Android Developers
Use the system setting (Settings -> Display -> Theme) to enable Dark theme. Use the Quick Settings tile to switch themes from the...
Read more >
Switching Between Light and Dark Themes Automatically
In this quick tutorial, I'll show you how to automatically set a dark or light theme in a web application depending on the...
Read more >
Automatically Switch Wallpaper Based on the macOS Theme
In this post, I'll show you how to automatically switch wallpapers based on light or dark mode on macOS using a free app....
Read more >
DayNight — Adding a dark theme to your app | by Chris Banes
The DayNight functionality in AppCompat allows your app to easily switch between a dark ⚫ and light ⚪ theme. This has many benefits...
Read more >
How to disable night mode in my application even if night ...
You must adapt your app for the night mode. Android-Q will out any time soon and all the app will get affected from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found