Fix splashscreen theme not updating after theme change (#633)#2058
Fix splashscreen theme not updating after theme change (#633)#2058shaominngqing wants to merge 2 commits intoandroid:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @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 a user experience inconsistency where the app's splash screen would briefly display with an incorrect theme (e.g., light mode) before switching to the user's preferred dark theme during a cold start. The changes ensure that the system-level theme is synchronized with the user's settings both immediately upon change and during initial application launch, providing a seamless visual experience from the very beginning. Highlights
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request effectively resolves the splash screen theme inconsistency by ensuring that the AppCompatDelegate.setDefaultNightMode() is applied both when the user changes the theme setting in SettingsViewModel and during the app's cold startup in MainActivity. This dual approach guarantees that the splash screen correctly reflects the user's preferred theme, eliminating the unpleasant flash previously observed. The changes align well with the problem description and proposed solution.
app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt
Show resolved
Hide resolved
.../main/kotlin/com/google/samples/apps/nowinandroid/feature/settings/impl/SettingsViewModel.kt
Outdated
Show resolved
Hide resolved
1ac6b0f to
4212fe5
Compare
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
4212fe5 to
02fa916
Compare
Summary
This PR fixes the issue where the splash screen doesn't reflect the user's dark theme preference when the app is cold-started after changing the theme setting.
Problem
When a user changes the theme from the app settings (e.g., from light to dark), the preference is saved but
AppCompatDelegate.setDefaultNightMode()is not called. As a result, on the next cold start, the splash screen still uses the old theme (light) and then switches to the app's new theme (dark), causing an unpleasant flash.Solution
This PR applies
AppCompatDelegate.setDefaultNightMode()in two places:This ensures the system-level night mode is synchronized with the user's preference, making the splash screen display correctly from the start.
Testing
Manual testing:
Changes
SettingsViewModel.kt: AddedAppCompatDelegate.setDefaultNightMode()callMainActivity.kt: Added startup logic to apply saved theme configReference
Fixes #633