2020-05-05 12:13:50 +08:00

89 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using Pixiview.UI.Theme;
using Pixiview.Utils;
using Xamarin.Forms;
namespace Pixiview
{
public class App : Application
{
// public properties
public static Theme CurrentTheme { get; private set; }
public static Dictionary<string, object> ExtraResources { get; private set; }
public App()
{
InitResources();
}
private void InitResources()
{
var service = DependencyService.Get<IEnvironmentService>();
var p = service.GetEnvironment();
ExtraResources = new Dictionary<string, object>
{
{ ThemeBase.IconLightFontFamily, p.IconLightFontFamily },
{ ThemeBase.IconRegularFontFamily, p.IconRegularFontFamily },
{ ThemeBase.IconSolidFontFamily, p.IconSolidFontFamily },
{ ThemeBase.IconLeft, p.IconLeft }
};
var theme = service.GetApplicationTheme();
SetTheme(theme, true);
}
private void SetTheme(Theme theme, bool force = false)
{
if (force || theme != CurrentTheme)
{
CurrentTheme = theme;
}
else
{
return;
}
DebugPrint($"application theme: {theme}");
ThemeBase themeInstance;
if (theme == Theme.Dark)
{
themeInstance = DarkTheme.Instance;
}
else
{
themeInstance = LightTheme.Instance;
}
//DependencyService.Get<IEnvironmentService>().SetStatusBarColor
Resources = themeInstance;
}
protected override void OnStart()
{
MainPage = UIFactory.CreateNavigationPage(new MainPage());
}
protected override void OnSleep()
{
}
protected override void OnResume()
{
var theme = DependencyService.Get<IEnvironmentService>().GetApplicationTheme();
SetTheme(theme);
}
public static void DebugPrint(string message)
{
Debug.WriteLine("[{0:HH:mm:ss.ffff}] - {1}", DateTime.Now, message);
}
public static void DebugError(string category, string message)
{
Debug.Fail(string.Format("[{0:HH:mm:ss.ffff}] - {1} - {2}", DateTime.Now, category, message));
}
}
}