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 Bills => bills ??= new List(); public static List Accounts => accounts ??= new List(); public static List Categories => categories ??= new List(); private static List bills; private static List accounts; private static List 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; } } }