diff --git a/Billing.Shared/App.cs b/Billing.Shared/App.cs index 9cddec6..3f52985 100644 --- a/Billing.Shared/App.cs +++ b/Billing.Shared/App.cs @@ -30,7 +30,6 @@ namespace Billing InitResources(); MainPage = new MainShell(); - //Shell.Current.GoToAsync("//Splash"); } protected override void OnStart() @@ -39,12 +38,13 @@ namespace Billing Helper.Debug($"cache folder: {StoreHelper.CacheFolder}"); } - internal static async Task InitializeData() + public static async Task InitializeData() { + var instance = await StoreHelper.Instance; await Task.WhenAll( - Task.Run(async () => accounts = await StoreHelper.GetAccountsAsync()), - Task.Run(async () => categories = await StoreHelper.GetCategoriesAsync()), - Task.Run(async () => bills = await StoreHelper.GetBillsAsync())); + Task.Run(async () => accounts = await instance.GetListAsync()), + Task.Run(async () => categories = await instance.GetListAsync()), + Task.Run(async () => bills = await instance.GetListAsync())); } protected override void OnResume() diff --git a/Billing.Shared/Helper.cs b/Billing.Shared/Helper.cs index b4fd510..3ee9136 100644 --- a/Billing.Shared/Helper.cs +++ b/Billing.Shared/Helper.cs @@ -39,6 +39,7 @@ namespace Billing public static void Error(string category, Exception ex) { + MainThread.BeginInvokeOnMainThread(async () => await Shell.Current.DisplayAlert(category, ex.ToString(), "Ok")); } public static void Error(string category, string message) @@ -139,15 +140,10 @@ namespace Billing public delegate void PropertyValueChanged(TOwner obj, TResult old, TResult @new); } - internal class AsyncLazy + public class AsyncLazy { private readonly Lazy> instance; - public AsyncLazy(Func factory) - { - instance = new Lazy>(() => Task.Run(factory)); - } - public AsyncLazy(Func> factory) { instance = new Lazy>(() => Task.Run(factory)); diff --git a/Billing.Shared/Store/StoreHelper.cs b/Billing.Shared/Store/StoreHelper.cs index 2ad5562..a864f65 100644 --- a/Billing.Shared/Store/StoreHelper.cs +++ b/Billing.Shared/Store/StoreHelper.cs @@ -28,68 +28,97 @@ namespace Billing.Store { return false; } - if (database != null) + try { - await database.CloseAsync(); + if (database != null) + { + await database.CloseAsync(); + } + } + catch (Exception ex) + { + Helper.Error("database.close", ex); + } + try + { + File.Copy(file, path, true); + } + catch (Exception ex) + { + Helper.Error("file.import", ex); + } + try + { + database = new SQLiteAsyncConnection(path, + SQLiteOpenFlags.ReadWrite | + SQLiteOpenFlags.Create | + SQLiteOpenFlags.SharedCache); + } + catch (Exception ex) + { + Helper.Error("database.connect", ex); } - File.Copy(file, path, true); - database = new SQLiteAsyncConnection(path, - SQLiteOpenFlags.ReadWrite | - SQLiteOpenFlags.Create | - SQLiteOpenFlags.SharedCache); return true; } - private static readonly AsyncLazy Instance = new(async () => + public static readonly AsyncLazy Instance = new(async () => { var instance = new StoreHelper(); - await database.CreateTablesAsync(); - var count = await database.ExecuteScalarAsync("SELECT COUNT(Id) FROM [Category]"); - if (count <= 0) + try { - // init categories - await database.InsertAllAsync(new List + await database.CreateTablesAsync(); + } catch (Exception ex) + { + Helper.Error("database.init.table", ex); + } + try + { + var count = await database.ExecuteScalarAsync("SELECT COUNT(Id) FROM [Category]"); + if (count <= 0) { - // sample categories - new() { Name = Resource.Clothing, Icon = "clothes" }, - new() { Name = Resource.Food, Icon = "food" }, - new() { Name = Resource.Daily, Icon = "daily" }, - new() { Name = Resource.Trans, Icon = "trans" }, - new() { Name = Resource.Entertainment, Icon = "face" }, - new() { Name = Resource.Learn, Icon = "learn" }, - new() { Name = Resource.Medical, Icon = "medical" }, - new() { Name = Resource.OtherSpending, Icon = "plus" }, + // init categories + await database.InsertAllAsync(new List + { + // sample categories + new() { Name = Resource.Clothing, Icon = "clothes" }, + new() { Name = Resource.Food, Icon = "food" }, + new() { Name = Resource.Daily, Icon = "daily" }, + new() { Name = Resource.Trans, Icon = "trans" }, + new() { Name = Resource.Entertainment, Icon = "face" }, + new() { Name = Resource.Learn, Icon = "learn" }, + new() { Name = Resource.Medical, Icon = "medical" }, + new() { Name = Resource.OtherSpending, Icon = "plus" }, - new() { Type = CategoryType.Income, Name = Resource.Earnings, Icon = "#brand#btc" }, - new() { Type = CategoryType.Income, Name = Resource.OtherIncome, Icon = "plus" }, + new() { Type = CategoryType.Income, Name = Resource.Earnings, Icon = "#brand#btc" }, + new() { Type = CategoryType.Income, Name = Resource.OtherIncome, Icon = "plus" }, - // sub-categories - new() { ParentId = 1, Name = Resource.Jewellery, Icon = "gem" }, - new() { ParentId = 1, Name = Resource.Cosmetics, Icon = "makeup" }, - new() { ParentId = 2, Name = Resource.Brunch, Icon = "brunch" }, - new() { ParentId = 2, Name = Resource.Dinner, Icon = "dinner" }, - new() { ParentId = 2, Name = Resource.Drinks, Icon = "drink" }, - new() { ParentId = 2, Name = Resource.Fruit, Icon = "fruit" }, - new() { ParentId = 3, Name = Resource.UtilityBill, Icon = "bill" }, - new() { ParentId = 3, Name = Resource.PropertyFee, Icon = "fee" }, - new() { ParentId = 3, Name = Resource.Rent, Icon = "rent" }, - new() { ParentId = 3, Name = Resource.Maintenance, Icon = "maintenance" }, - new() { ParentId = 4, Name = Resource.LightRail, Icon = "rail" }, - new() { ParentId = 4, Name = Resource.Taxi, Icon = "taxi" }, - new() { ParentId = 5, Name = Resource.Fitness, Icon = "fitness" }, - new() { ParentId = 5, Name = Resource.Party, Icon = "party" }, - new() { ParentId = 9, Type = CategoryType.Income, Name = Resource.Salary, Icon = "#brand#buffer" }, - new() { ParentId = 9, Type = CategoryType.Income, Name = Resource.Bonus, Icon = "dollar" }, - }); + // sub-categories + new() { ParentId = 1, Name = Resource.Jewellery, Icon = "gem" }, + new() { ParentId = 1, Name = Resource.Cosmetics, Icon = "makeup" }, + new() { ParentId = 2, Name = Resource.Brunch, Icon = "brunch" }, + new() { ParentId = 2, Name = Resource.Dinner, Icon = "dinner" }, + new() { ParentId = 2, Name = Resource.Drinks, Icon = "drink" }, + new() { ParentId = 2, Name = Resource.Fruit, Icon = "fruit" }, + new() { ParentId = 3, Name = Resource.UtilityBill, Icon = "bill" }, + new() { ParentId = 3, Name = Resource.PropertyFee, Icon = "fee" }, + new() { ParentId = 3, Name = Resource.Rent, Icon = "rent" }, + new() { ParentId = 3, Name = Resource.Maintenance, Icon = "maintenance" }, + new() { ParentId = 4, Name = Resource.LightRail, Icon = "rail" }, + new() { ParentId = 4, Name = Resource.Taxi, Icon = "taxi" }, + new() { ParentId = 5, Name = Resource.Fitness, Icon = "fitness" }, + new() { ParentId = 5, Name = Resource.Party, Icon = "party" }, + new() { ParentId = 9, Type = CategoryType.Income, Name = Resource.Salary, Icon = "#brand#buffer" }, + new() { ParentId = 9, Type = CategoryType.Income, Name = Resource.Bonus, Icon = "dollar" }, + }); + } + } + catch (Exception ex) + { + Helper.Error("database.init.category", ex); } return instance; }); - public static async Task> GetAccountsAsync() - { - var instance = await Instance; - return await instance.GetListAsync(); - } public static async Task SaveAccountItemAsync(Account account) { var instance = await Instance; @@ -101,11 +130,6 @@ namespace Billing.Store return await instance.DeleteItemAsync(account); } - public static async Task> GetBillsAsync() - { - var instance = await Instance; - return await instance.GetListAsync(); - } public static async Task SaveBillItemAsync(Bill bill) { var instance = await Instance; @@ -117,11 +141,6 @@ namespace Billing.Store return await instance.DeleteItemAsync(bill); } - public static async Task> GetCategoriesAsync() - { - var instance = await Instance; - return await instance.GetListAsync(); - } public static async Task SaveCategoryItemAsync(Category category) { var instance = await Instance; @@ -137,10 +156,17 @@ namespace Billing.Store { if (database == null) { - database = new SQLiteAsyncConnection(DatabasePath, - SQLiteOpenFlags.ReadWrite | - SQLiteOpenFlags.Create | - SQLiteOpenFlags.SharedCache); + try + { + database = new SQLiteAsyncConnection(DatabasePath, + SQLiteOpenFlags.ReadWrite | + SQLiteOpenFlags.Create | + SQLiteOpenFlags.SharedCache); + } + catch (Exception ex) + { + Helper.Error("database.ctor.connect", ex); + } } } @@ -178,7 +204,7 @@ namespace Billing.Store #region Helper - private Task> GetListAsync() where T : new() + public Task> GetListAsync() where T : new() { try { @@ -191,7 +217,7 @@ namespace Billing.Store return default; } - private Task SaveItemAsync(T item) where T : IIdItem + public Task SaveItemAsync(T item) where T : IIdItem { try { @@ -211,7 +237,7 @@ namespace Billing.Store return Task.FromResult(0); } - private Task DeleteItemAsync(T item) where T : IIdItem + public Task DeleteItemAsync(T item) where T : IIdItem { try { diff --git a/Billing/Billing.Android/Billing.Android.csproj b/Billing/Billing.Android/Billing.Android.csproj index 83f151f..f7c92e0 100644 --- a/Billing/Billing.Android/Billing.Android.csproj +++ b/Billing/Billing.Android/Billing.Android.csproj @@ -60,7 +60,6 @@ - diff --git a/Billing/Billing.Android/Properties/AndroidManifest.xml b/Billing/Billing.Android/Properties/AndroidManifest.xml index c1fd536..94742bc 100644 --- a/Billing/Billing.Android/Properties/AndroidManifest.xml +++ b/Billing/Billing.Android/Properties/AndroidManifest.xml @@ -1,5 +1,5 @@  - + diff --git a/Billing/Billing.iOS/Billing.iOS.csproj b/Billing/Billing.iOS/Billing.iOS.csproj index 97d5b5f..12e621d 100644 --- a/Billing/Billing.iOS/Billing.iOS.csproj +++ b/Billing/Billing.iOS/Billing.iOS.csproj @@ -38,6 +38,7 @@ None x86_64 iPhone Distribution + true true @@ -64,6 +65,8 @@ iPhone Distribution Entitlements.plist SdkOnly + -all + true @@ -166,14 +169,13 @@ - + - @@ -477,14 +479,6 @@ - - - true - {D4EA6D3A-17E6-4300-80A7-2ED19B738C6B} - Billing.ShareExtension - - - \ No newline at end of file diff --git a/Billing/Billing.iOS/Info.plist b/Billing/Billing.iOS/Info.plist index 2d44104..6fc8414 100644 --- a/Billing/Billing.iOS/Info.plist +++ b/Billing/Billing.iOS/Info.plist @@ -42,23 +42,23 @@ OpenSans-SemiBold.ttf CFBundleDocumentTypes - - - CFBundleTypeName - Master SQLite file - LSItemContentTypes - - public.data - - CFBundleTypeIconFiles - - Assets.xcassets/AppIcon.appiconset/Icon180 - - - + + + CFBundleTypeName + Master SQLite file + LSItemContentTypes + + public.data + + CFBundleTypeIconFiles + + Assets.xcassets/AppIcon.appiconset/Icon180 + + + CFBundleVersion - 10 + 11 CFBundleShortVersionString - 0.10.311 + 1.0.312