Skip to content

feat(theme): add forSystemNightMode helper on AwfulTheme (#534)#807

Open
jim-daf wants to merge 2 commits intoAwful:developfrom
jim-daf:feat/issue-534-system-night-mode-helper
Open

feat(theme): add forSystemNightMode helper on AwfulTheme (#534)#807
jim-daf wants to merge 2 commits intoAwful:developfrom
jim-daf:feat/issue-534-system-night-mode-helper

Conversation

@jim-daf
Copy link
Copy Markdown

@jim-daf jim-daf commented Apr 25, 2026

Towards #534.

The issue notes that the existing AppCompat day/night helper does not fit, because Awful's theme system already chooses a forum-aware theme rather than just a parent style. The plumbing the author asked for is "given the current user-selected theme, return the dark variant when the system reports night".

This PR adds exactly that helper on AwfulTheme. It is conservative, only translates the standard DEFAULT and CUSTOM_DEFAULT light themes to their DARK counterparts, and returns the input theme unchanged for everything else (including custom CSS the user picked deliberately). Activities and the WebView host can call this in a follow-up wherever they currently look up forForum.

@NonNull
public static AwfulTheme forSystemNightMode(@NonNull Context context, @NonNull AwfulTheme lightTheme) {
    int mode = context.getResources().getConfiguration().uiMode
            & Configuration.UI_MODE_NIGHT_MASK;
    if (mode != Configuration.UI_MODE_NIGHT_YES) {
        return lightTheme;
    }
    switch (lightTheme) {
        case DEFAULT:
        case CLASSIC:
            return DARK;
        case CUSTOM_DEFAULT:
            return CUSTOM_DARK;
        default:
            return lightTheme;
    }
}

Wiring the call sites is intentionally a separate change so this PR stays small and reviewable.

@jim-daf jim-daf marked this pull request as ready for review April 25, 2026 19:26
Copilot AI review requested due to automatic review settings April 25, 2026 19:26
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a theme-selection helper to bridge Awful’s forum-aware theming system with Android’s system night mode state, enabling callers to opt into “use dark variant at night” without changing existing call sites yet.

Changes:

  • Added AwfulTheme.forSystemNightMode(Context, AwfulTheme) to map selected light themes to dark counterparts when uiMode reports night.
  • Documented the intended conservative mapping behavior and rationale in AwfulTheme.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +150 to +152
int mode = context.getResources().getConfiguration().uiMode
& Configuration.UI_MODE_NIGHT_MASK;
if (mode != Configuration.UI_MODE_NIGHT_YES) {
Comment on lines +144 to +160
* day mode or in the unspecified state. Mapping is conservative,
* only the standard app themes are translated. Custom themes are
* returned as-is so users keep their explicit choice.
*/
@NonNull
public static AwfulTheme forSystemNightMode(@NonNull Context context, @NonNull AwfulTheme lightTheme) {
int mode = context.getResources().getConfiguration().uiMode
& Configuration.UI_MODE_NIGHT_MASK;
if (mode != Configuration.UI_MODE_NIGHT_YES) {
return lightTheme;
}
switch (lightTheme) {
case DEFAULT:
case CLASSIC:
return DARK;
case CUSTOM_DEFAULT:
return CUSTOM_DARK;
Comment on lines +155 to +159
switch (lightTheme) {
case DEFAULT:
case CLASSIC:
return DARK;
case CUSTOM_DEFAULT:
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.

2 participants