86 lines
2.1 KiB
C#
86 lines
2.1 KiB
C#
using Xamarin.Forms;
|
|
using Gallery.Services;
|
|
using Xamarin.Essentials;
|
|
using Gallery.Resources;
|
|
using Gallery.Util;
|
|
using Gallery.Resources.Theme;
|
|
|
|
namespace Gallery
|
|
{
|
|
public partial class App : Application
|
|
{
|
|
public static AppTheme CurrentTheme { get; private set; }
|
|
public static PlatformCulture CurrentCulture { get; private set; }
|
|
|
|
public App()
|
|
{
|
|
DependencyService.Register<MockDataStore>();
|
|
}
|
|
|
|
private void InitResource()
|
|
{
|
|
var theme = AppInfo.RequestedTheme;
|
|
SetTheme(theme, true);
|
|
}
|
|
|
|
private void InitPreference()
|
|
{
|
|
|
|
}
|
|
|
|
private void InitLanguage()
|
|
{
|
|
var ci = Environment.GetCurrentCultureInfo();
|
|
Environment.SetCultureInfo(ci);
|
|
CurrentCulture = new PlatformCulture(ci.Name.ToLower());
|
|
}
|
|
|
|
private void SetTheme(AppTheme theme, bool force = false)
|
|
{
|
|
if (force || theme != CurrentTheme)
|
|
{
|
|
CurrentTheme = theme;
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
#if DEBUG
|
|
Log.Print($"application theme: {theme}");
|
|
#endif
|
|
Theme themeInstance = theme switch
|
|
{
|
|
AppTheme.Dark => DarkTheme.Instance,
|
|
_ => LightTheme.Instance
|
|
};
|
|
#if __IOS__
|
|
var style = (StatusBarStyles)themeInstance[Theme.StatusBarStyle];
|
|
Environment.SetStatusBarStyle(style);
|
|
#elif __ANDROID__
|
|
var color = (Color)themeInstance[Theme.NavigationColor];
|
|
Environment.SetStatusBarColor(color);
|
|
#endif
|
|
Resources = themeInstance;
|
|
}
|
|
|
|
protected override void OnStart()
|
|
{
|
|
InitLanguage();
|
|
MainPage = new AppShell();
|
|
|
|
InitResource();
|
|
InitPreference();
|
|
}
|
|
|
|
protected override void OnSleep()
|
|
{
|
|
}
|
|
|
|
protected override void OnResume()
|
|
{
|
|
var theme = AppInfo.RequestedTheme;
|
|
SetTheme(theme);
|
|
}
|
|
}
|
|
}
|