This commit is contained in:
Harry Bond 2024-12-16 23:33:59 +00:00
parent bfad3195ad
commit d005ee6149
2 changed files with 26 additions and 28 deletions

View file

@ -68,35 +68,31 @@ public enum ThemeSwitcher
public void restart(boolean isRendererActive)
{
mRendererActive = isRendererActive;
// First, set the last saved theme
String storedTheme = Config.getUiThemeSettings(mContext);
Config.setUiThemeSettings(mContext, storedTheme);
int currentMapStyle = Framework.nativeGetMapStyle();
// If current style is different to the style from theme, only set theme
// To handle case of debug commands
if (currentMapStyle != getMapStyle(storedTheme))
{
SetMapStyle(getMapStyle(storedTheme));
setAndroidTheme(storedTheme);
}
else
{
setAndroidTheme(storedTheme);
}
// final String themeToApply = ThemeUtils.getUiTheme(mContext);
// final int style = ;
// setThemeAndMapStyle(theme, style);
// If current style is different to the style from theme, only set theme
// to handle debug commands
if (currentMapStyle != getMapStyle(storedTheme))
SetMapStyle(getMapStyle(storedTheme));
setAndroidTheme(storedTheme);
}
private void setAndroidTheme(@NonNull String theme)
{
if (ThemeUtils.isFollowSystemTheme(mContext, theme))
if (ThemeUtils.isSystemTheme(mContext, theme))
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
else if (ThemeUtils.isAutoTheme(mContext, theme)) //TODO: Proper behaviour
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
else if (ThemeUtils.isNavAutoTheme(mContext, theme)) //TODO: Proper behaviour
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
else if (ThemeUtils.isAutoTheme(mContext, theme))
{
//TODO: Proper behaviour
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
else if (ThemeUtils.isNavAutoTheme(mContext, theme))
{
//TODO: Proper behaviour
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
else if (ThemeUtils.isNightTheme(mContext, theme))
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
else if (ThemeUtils.isDefaultTheme(mContext, theme))
@ -152,6 +148,9 @@ public enum ThemeSwitcher
// }
// }
/**
* calls back to core framework and sets the map style.
*/
private void SetMapStyle(@Framework.MapStyle int style)
{
// Because of the distinct behavior in auto theme, Android Auto employs its own mechanism for theme switching.

View file

@ -1,7 +1,6 @@
package app.organicmaps.util;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.util.TypedValue;
@ -9,7 +8,7 @@ import androidx.annotation.AttrRes;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;
import androidx.appcompat.app.AppCompatDelegate;
import app.organicmaps.R;
public final class ThemeUtils
@ -87,12 +86,12 @@ public final class ThemeUtils
return nightTheme.equals(theme);
}
public static boolean isFollowSystemTheme(@NonNull Context context)
public static boolean isSystemTheme(@NonNull Context context)
{
return isFollowSystemTheme(context, Config.getUiThemeSettings(context));
return isSystemTheme(context, Config.getUiThemeSettings(context));
}
public static boolean isFollowSystemTheme(@NonNull Context context, String theme)
public static boolean isSystemTheme(@NonNull Context context, String theme)
{
String followSystemTheme = context.getString(R.string.theme_follow_system);
return followSystemTheme.equals(theme);
@ -111,7 +110,7 @@ public final class ThemeUtils
public static boolean isAutoTheme(@NonNull Context context)
{
return isFollowSystemTheme(context, Config.getUiThemeSettings(context));
return isSystemTheme(context, Config.getUiThemeSettings(context));
}
public static boolean isAutoTheme(@NonNull Context context, String theme)
@ -122,7 +121,7 @@ public final class ThemeUtils
public static boolean isValidThemeMode(@NonNull Context context, String res)
{
return isFollowSystemTheme(context, res) || isNavAutoTheme(context, res) || isAutoTheme(context, res);
return isSystemTheme(context, res) || isNavAutoTheme(context, res) || isAutoTheme(context, res);
}
public static boolean isValidTheme(@NonNull Context context, String theme)