diff --git a/Awful.apk/src/main/java/com/ferg/awfulapp/provider/AwfulTheme.java b/Awful.apk/src/main/java/com/ferg/awfulapp/provider/AwfulTheme.java index bca8d1b9..54544731 100644 --- a/Awful.apk/src/main/java/com/ferg/awfulapp/provider/AwfulTheme.java +++ b/Awful.apk/src/main/java/com/ferg/awfulapp/provider/AwfulTheme.java @@ -136,6 +136,34 @@ public static String getCustomThemePath() { } + /** + * Issue #534: pick the night-mode counterpart of the user-selected + * light theme when the system reports it is currently night. + * + * Returns the supplied light theme unchanged when the system is in + * 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; + default: + return lightTheme; + } + } + + /** * Get a forum's specific theme, if it has one. *