2022-03-11 16:10:11 +08:00

83 lines
2.4 KiB
C#

using System.Collections.Generic;
using System.Threading.Tasks;
using Billing.Languages;
using Billing.Models;
using Billing.Store;
using Billing.Themes;
using Xamarin.Essentials;
using Xamarin.Forms;
namespace Billing
{
public class App : Application
{
public static AppTheme CurrentTheme { get; private set; }
public static PlatformCulture CurrentCulture { get; private set; }
public static List<Bill> Bills => bills ??= new List<Bill>();
public static List<Account> Accounts => accounts ??= new List<Account>();
public static List<Category> Categories => categories ??= new List<Category>();
private static List<Bill> bills;
private static List<Account> accounts;
private static List<Category> categories;
public App()
{
CurrentCulture = new PlatformCulture();
InitResources();
MainPage = new MainShell();
Shell.Current.GoToAsync("//Splash");
}
protected override void OnStart()
{
Helper.Debug($"personal folder: {StoreHelper.PersonalFolder}");
Helper.Debug($"cache folder: {StoreHelper.CacheFolder}");
}
internal static async Task InitilalizeData()
{
await Task.WhenAll(
Task.Run(async () => accounts = await StoreHelper.GetAccountsAsync()),
Task.Run(async () => categories = await StoreHelper.GetCategoriesAsync()),
Task.Run(async () => bills = await StoreHelper.GetBillsAsync()));
}
protected override void OnResume()
{
SetTheme(AppInfo.RequestedTheme);
}
private void InitResources()
{
var theme = AppInfo.RequestedTheme;
SetTheme(theme, true);
}
private void SetTheme(AppTheme theme, bool force = false)
{
if (force || theme != CurrentTheme)
{
CurrentTheme = theme;
}
else
{
return;
}
Helper.Debug($"application theme: {theme}");
BaseTheme instance;
if (theme == AppTheme.Dark)
{
instance = Dark.Instance;
}
else
{
instance = Light.Instance;
}
// TODO: status bar
Resources = instance;
}
}
}