1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-05 23:53:33 +00:00
Files
mobile/src/Android/Utilities/ThemeHelpers.cs
mp-bw 109aeb49e4 [BEEEP] [PS-940] Support for dark theme selection while using Default (System) theme (#1959)
* support for dark theme selection while using Default (System) theme

* refinements
2022-06-21 14:59:30 -04:00

76 lines
2.2 KiB
C#

using Android.Graphics;
using Bit.App.Utilities;
using Xamarin.Forms.Platform.Android;
namespace Bit.Droid.Utilities
{
public class ThemeHelpers
{
public static bool LightTheme = true;
public static Color PrimaryColor
{
get => ThemeManager.GetResourceColor("PrimaryColor").ToAndroid();
}
public static Color MutedColor
{
get => ThemeManager.GetResourceColor("MutedColor").ToAndroid();
}
public static Color BackgroundColor
{
get => ThemeManager.GetResourceColor("BackgroundColor").ToAndroid();
}
public static Color NavBarBackgroundColor
{
get => ThemeManager.GetResourceColor("NavigationBarBackgroundColor").ToAndroid();
}
public static Color FabColor
{
get => ThemeManager.GetResourceColor("FabColor").ToAndroid();
}
public static Color SwitchOnColor
{
get => ThemeManager.GetResourceColor("SwitchOnColor").ToAndroid();
}
public static Color SwitchThumbColor
{
get => ThemeManager.GetResourceColor("SwitchThumbColor").ToAndroid();
}
public static Color TextColor
{
get => ThemeManager.GetResourceColor("TextColor").ToAndroid();
}
public static void SetAppearance(string theme, bool osDarkModeEnabled)
{
SetThemeVariables(theme, osDarkModeEnabled);
}
public static int GetDialogTheme()
{
if (LightTheme)
{
return Android.Resource.Style.ThemeMaterialLightDialog;
}
return Android.Resource.Style.ThemeMaterialDialog;
}
private static void SetThemeVariables(string theme, bool osDarkModeEnabled)
{
if (string.IsNullOrWhiteSpace(theme) && osDarkModeEnabled)
{
theme = ThemeManager.Dark;
}
if (theme == ThemeManager.Dark || theme == ThemeManager.Black || theme == ThemeManager.Nord)
{
LightTheme = false;
}
else
{
LightTheme = true;
}
}
}
}