Skip to content

Fix/splashscreen theme 633 v2#2059

Open
shaominngqing wants to merge 3 commits intoandroid:mainfrom
shaominngqing:fix/splashscreen-theme-633-v2
Open

Fix/splashscreen theme 633 v2#2059
shaominngqing wants to merge 3 commits intoandroid:mainfrom
shaominngqing:fix/splashscreen-theme-633-v2

Conversation

@shaominngqing
Copy link

@shaominngqing shaominngqing commented Feb 3, 2026

Summary

This PR fixes issue #633 where the splash screen does not reflect the user's chosen dark theme configuration during cold starts.

What I have done and why

Problem

When users change the dark theme setting (Light/Dark/Follow System) in the app settings, the splash screen continues to display with the old theme on the next app launch. This creates an inconsistent and jarring user experience.

Solution

This PR implements three key changes:

  1. Apply theme configuration on startup: Modified MainActivity to observe the user's dark theme preference and apply it immediately using AppCompatDelegate.setDefaultNightMode() before the splash screen is displayed.

  2. Dynamic theme updates: Modified SettingsViewModel to apply the theme configuration immediately when changed in settings, ensuring consistency throughout the app lifecycle.

  3. Code organization: Created a shared toNightMode() extension function in the core:ui module to convert DarkThemeConfig enum values to AppCompatDelegate night mode constants, eliminating code duplication and improving maintainability.

Changes Made

Modified Files:

  • app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt

    • Added logic to apply saved dark theme config on startup
    • Refactored Flow processing using filterIsInstance<Success>() for better readability (per Gemini Code Assist feedback)
  • feature/settings/impl/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/settings/impl/SettingsViewModel.kt

    • Apply theme immediately when changed in settings

New Files:

  • core/ui/src/main/kotlin/com/google/samples/apps/nowinandroid/core/ui/DarkThemeConfigExt.kt
    • Shared extension function for theme configuration conversion

Code Review Response

Addressed feedback from Gemini Code Assist:

  • ✅ Moved toNightMode() extension to core:ui module (eliminated code duplication)
  • ✅ Refactored MainActivity Flow logic to use filterIsInstance<Success>() (improved readability)

Testing

  • Verified splash screen displays correct theme after theme change
  • Verified dynamic theme switching in settings works correctly

Related Issues

Fixes #633

Apply AppCompatDelegate.setDefaultNightMode() when the user changes
the dark theme configuration to ensure the system-level night mode
is synchronized. This makes the splash screen display with the
correct theme on cold start.

Changes:
- SettingsViewModel: Apply night mode immediately when user changes theme
- MainActivity: Apply saved theme config on startup

Fixes android#633
- Use first() instead of collect() in MainActivity to avoid redundant
  calls when theme changes at runtime (since SettingsViewModel already
  handles that)
- Extract DarkThemeConfig to night mode mapping into extension functions
  to avoid code duplication and improve maintainability

Based on feedback from gemini-code-assist review
@gemini-code-assist
Copy link

Summary of Changes

Hello @shaominngqing, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where the application's splash screen did not consistently reflect the user's chosen dark theme settings, particularly during cold starts. The changes ensure that the saved dark theme configuration is applied early in the application lifecycle, providing a seamless and consistent visual experience from the splash screen onwards. Additionally, the theme is updated dynamically when changed in the settings.

Highlights

  • Splash Screen Theme Fix: Implemented a fix to ensure the splash screen correctly applies the user's preferred dark theme configuration on application startup, addressing issue [Bug]: Splashscreen theme doesn't change after switching the color theme #633.
  • Dynamic Theme Application: The application's theme is now set using AppCompatDelegate.setDefaultNightMode based on the user's DarkThemeConfig both during initial launch and when the theme setting is updated.
  • Dark Theme Configuration Utility: Introduced a new extension function toNightMode() to convert DarkThemeConfig enum values into AppCompatDelegate night mode constants for consistent theme application.
  • Potential Code Duplication: A DarkThemeConfigExt.kt file containing the toNightMode() extension function has been added in two different packages (app/src/main/kotlin/com/google/samples/apps/nowinandroid/util and feature/settings/impl/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/settings/impl). This might be an intentional modularization choice or an oversight.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt
    • Added imports for AppCompatDelegate and MainActivityUiState.Success.
    • Added import for the new toNightMode extension function.
    • Introduced a lifecycleScope.launch block in onCreate to observe viewModel.uiState and apply the darkThemeConfig to AppCompatDelegate.setDefaultNightMode for splash screen theming.
  • app/src/main/kotlin/com/google/samples/apps/nowinandroid/util/DarkThemeConfigExt.kt
    • New file: Defines the toNightMode() extension function for DarkThemeConfig to map to AppCompatDelegate night mode constants.
  • feature/settings/impl/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/settings/impl/DarkThemeConfigExt.kt
    • New file: Defines the toNightMode() extension function for DarkThemeConfig to map to AppCompatDelegate night mode constants (similar to the one in app/src/main/kotlin/com/google/samples/apps/nowinandroid/util).
  • feature/settings/impl/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/settings/impl/SettingsViewModel.kt
    • Added import for AppCompatDelegate.
    • Modified updateDarkThemeConfig to also call AppCompatDelegate.setDefaultNightMode when the user changes the theme setting, ensuring immediate application of the new theme.
Activity
  • No human activity (comments, reviews) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an issue with the splash screen theme by ensuring the user's selected dark theme configuration is applied at application startup. This is achieved by observing the user data and setting the default night mode in MainActivity. The theme is also applied immediately when changed in the settings. The overall approach is sound. I've provided a suggestion to refactor a piece of Flow-handling logic for better readability and pointed out an instance of code duplication that should be resolved for better maintainability.

Comment on lines 26 to 30
internal fun DarkThemeConfig.toNightMode(): Int = when (this) {
DarkThemeConfig.FOLLOW_SYSTEM -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
DarkThemeConfig.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
DarkThemeConfig.DARK -> AppCompatDelegate.MODE_NIGHT_YES
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This toNightMode() extension function is identical to the one added in app/src/main/kotlin/com/google/samples/apps/nowinandroid/util/DarkThemeConfigExt.kt. This code duplication should be avoided to improve maintainability. Consider moving this function to a shared module that both the app and feature:settings modules can depend on, for example a core:ui or core:common module. This would make the function internal to that shared module but available to both the app and feature:settings modules.

Comment on lines 89 to 96
.map { state ->
if (state is Success) {
state.userData.darkThemeConfig.toNightMode()
} else {
null
}
}
.first { it != null } // Only take the first non-null mode

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This flow processing logic can be made more concise and idiomatic by using filterIsInstance to filter for the Success state, followed by map. This approach is more declarative and improves readability by removing the manual type check and null handling.

                .filterIsInstance<Success>()
                .map { it.userData.darkThemeConfig.toNightMode() }
                .first()

- Move toNightMode() extension to core:ui module to eliminate code duplication
- Refactor MainActivity flow logic to use filterIsInstance<Success>() for better readability
- Remove duplicate DarkThemeConfigExt.kt files from app and feature:settings modules
- Update imports in MainActivity and SettingsViewModel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Splashscreen theme doesn't change after switching the color theme

1 participant