From 5cbcfbcd56fe41a27671084c42015efb364b5793 Mon Sep 17 00:00:00 2001 From: tsanie Date: Thu, 17 Mar 2022 21:34:26 +0800 Subject: [PATCH] release new version --- Billing.Shared/App.cs | 15 ++++++++--- Billing.Shared/SplashPage.xaml.cs | 7 ++++-- Billing.Shared/UI/Definition.cs | 1 + Billing.Shared/Views/SettingPage.xaml.cs | 1 + .../Properties/AndroidManifest.xml | 2 +- Billing/Billing.iOS/AppDelegate.cs | 25 ++++++++++++++++--- Billing/Billing.iOS/Info.plist | 2 +- 7 files changed, 41 insertions(+), 12 deletions(-) diff --git a/Billing.Shared/App.cs b/Billing.Shared/App.cs index cc0fd7f..bc7a981 100644 --- a/Billing.Shared/App.cs +++ b/Billing.Shared/App.cs @@ -14,7 +14,6 @@ namespace Billing public class App : Application { internal const string NewBillAction = "/newbill"; - private const string SaveLocationKey = nameof(SaveLocationKey); public static AppTheme CurrentTheme { get; private set; } public static PlatformCulture CurrentCulture { get; private set; } @@ -35,8 +34,10 @@ namespace Billing public App(string url = null) { if (url == NewBillAction) - { - mainRoute = "//Bills/Details"; + { +#if __ANDROID__ + mainRoute = "//Bills/Details"; +#endif } else { @@ -44,6 +45,7 @@ namespace Billing initialUrl = url; } CurrentCulture = new PlatformCulture(); + saveLocation = Preferences.Get(Definition.SaveLocationKey, false); InitResources(); MainPage = new MainShell(); @@ -101,7 +103,6 @@ namespace Billing public static void SetSaveLocation(bool flag) { saveLocation = flag; - Preferences.Set(SaveLocationKey, flag); } public static async Task InitializeData() @@ -113,7 +114,11 @@ namespace Billing Task.Run(async () => bills = await instance.GetListAsync())); } +#if __ANDROID public static async Task OpenUrl(string url) +#elif __IOS__ + public static bool OpenUrl(string url) +#endif { if (string.IsNullOrEmpty(url)) { @@ -121,11 +126,13 @@ namespace Billing } if (File.Exists(url)) { +#if __ANDROID__ var status = await Helper.CheckAndRequestPermissionAsync(); if (status != PermissionStatus.Granted) { return false; } +#endif _ = Task.Run(async () => { var result = await StoreHelper.ReloadDatabase(url); diff --git a/Billing.Shared/SplashPage.xaml.cs b/Billing.Shared/SplashPage.xaml.cs index 0837cb4..20ebb40 100644 --- a/Billing.Shared/SplashPage.xaml.cs +++ b/Billing.Shared/SplashPage.xaml.cs @@ -12,9 +12,12 @@ namespace Billing protected override async void OnLoaded() { - await App.InitializeData(); + if (!string.IsNullOrEmpty(App.MainRoute)) + { + await App.InitializeData(); - await Shell.Current.GoToAsync(App.MainRoute); + await Shell.Current.GoToAsync(App.MainRoute); + } } } } diff --git a/Billing.Shared/UI/Definition.cs b/Billing.Shared/UI/Definition.cs index 0e1a92b..cc4d62e 100644 --- a/Billing.Shared/UI/Definition.cs +++ b/Billing.Shared/UI/Definition.cs @@ -7,6 +7,7 @@ namespace Billing.UI { public static partial class Definition { + public const string SaveLocationKey = "SaveLocationKey"; public const string PrimaryColorKey = "PrimaryColor"; public const string DefaultIcon = "ic_default"; public const long TransparentColor = 0x00ffffffL; diff --git a/Billing.Shared/Views/SettingPage.xaml.cs b/Billing.Shared/Views/SettingPage.xaml.cs index 24e63de..529d040 100644 --- a/Billing.Shared/Views/SettingPage.xaml.cs +++ b/Billing.Shared/Views/SettingPage.xaml.cs @@ -61,6 +61,7 @@ namespace Billing.Views base.OnDisappearing(); App.SetSaveLocation(SaveLocation); + Preferences.Set(Definition.SaveLocationKey, SaveLocation); Preferences.Set(Definition.PrimaryColorKey, PrimaryColor); } diff --git a/Billing/Billing.Android/Properties/AndroidManifest.xml b/Billing/Billing.Android/Properties/AndroidManifest.xml index 9bd9c43..09677bf 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/AppDelegate.cs b/Billing/Billing.iOS/AppDelegate.cs index 02fb032..a25ca1b 100644 --- a/Billing/Billing.iOS/AppDelegate.cs +++ b/Billing/Billing.iOS/AppDelegate.cs @@ -1,5 +1,4 @@ using Foundation; -using ObjCRuntime; using UIKit; namespace Billing.iOS @@ -38,18 +37,36 @@ namespace Billing.iOS { if (url?.IsFileUrl == true) { - return App.OpenUrl(url.Path).Result; + return App.OpenUrl(url.Path); } return false; } - public override void PerformActionForShortcutItem(UIApplication application, UIApplicationShortcutItem shortcutItem, UIOperationHandler completionHandler) + public override async void PerformActionForShortcutItem(UIApplication application, UIApplicationShortcutItem shortcutItem, UIOperationHandler completionHandler) { if (shortcutItem == null || string.IsNullOrEmpty(shortcutItem.Type)) { return; } - Xamarin.Essentials.MainThread.BeginInvokeOnMainThread(async () => await Xamarin.Forms.Shell.Current.GoToAsync("//Bills/Details")); + if (App.Accounts.Count == 0) + { + await App.InitializeData(); + } + Xamarin.Essentials.MainThread.BeginInvokeOnMainThread(async () => + { + var state = Xamarin.Forms.Shell.Current.CurrentState.Location; + var route = state.OriginalString; + var current = Xamarin.Forms.Shell.Current; + if (!route.StartsWith("//Bills")) + { + await current.GoToAsync("//Bills"); + } + else if (route.EndsWith("/Details") || route.StartsWith("//Bills/D_FAULT_AddBillPage")) + { + return; + } + await current.GoToAsync("Details"); + }); } } } \ No newline at end of file diff --git a/Billing/Billing.iOS/Info.plist b/Billing/Billing.iOS/Info.plist index 8d34333..3b5d7bb 100644 --- a/Billing/Billing.iOS/Info.plist +++ b/Billing/Billing.iOS/Info.plist @@ -80,7 +80,7 @@ CFBundleVersion - 16 + 17 CFBundleShortVersionString 1.2.317 LSApplicationQueriesSchemes