diff --git a/Billing.Shared/Store/StoreHelper.cs b/Billing.Shared/Store/StoreHelper.cs index 265b89c..11584cc 100644 --- a/Billing.Shared/Store/StoreHelper.cs +++ b/Billing.Shared/Store/StoreHelper.cs @@ -206,7 +206,11 @@ namespace Billing.Store } writer.Flush(); - await database.ExecuteAsync("DELETE FROM [Logs]; DELETE FROM [sqlite_sequence] WHERE [name] = 'Logs'"); + await database.RunInTransactionAsync(conn => + { + conn.Execute("DELETE FROM [Logs]"); + conn.Execute("DELETE FROM [sqlite_sequence] WHERE [name] = 'Logs'"); + }); return file; } catch diff --git a/Billing.Shared/Views/AddBillPage.xaml b/Billing.Shared/Views/AddBillPage.xaml index 6958b35..2ebdf1d 100644 --- a/Billing.Shared/Views/AddBillPage.xaml +++ b/Billing.Shared/Views/AddBillPage.xaml @@ -10,6 +10,7 @@ BindingContext="{x:Reference billPage}"> + @@ -49,9 +50,6 @@ - diff --git a/Billing.Shared/Views/AddBillPage.xaml.cs b/Billing.Shared/Views/AddBillPage.xaml.cs index 2fcdaf7..c7d6984 100644 --- a/Billing.Shared/Views/AddBillPage.xaml.cs +++ b/Billing.Shared/Views/AddBillPage.xaml.cs @@ -316,6 +316,7 @@ namespace Billing.Views Longitude = location.Longitude, Latitude = location.Latitude }); + page.Synced += (sender, loc) => location = loc; await Navigation.PushAsync(page); } } diff --git a/Billing.Shared/Views/ViewLocationPage.cs b/Billing.Shared/Views/ViewLocationPage.cs index 2fb6c55..6a876f0 100644 --- a/Billing.Shared/Views/ViewLocationPage.cs +++ b/Billing.Shared/Views/ViewLocationPage.cs @@ -1,17 +1,37 @@ -using Billing.Models; +using System; +using System.Threading; +using System.Threading.Tasks; +using Billing.Models; using Billing.UI; +using Xamarin.Essentials; +using Xamarin.Forms; using Xamarin.Forms.Maps; using Xamarin.Forms.PlatformConfiguration.iOSSpecific; +using Map = Xamarin.Forms.Maps.Map; namespace Billing.Views { public class ViewLocationPage : BillingPage { + public event EventHandler Synced; + + private readonly Bill bill; + + private CancellationTokenSource tokenSource; + public ViewLocationPage(Bill bill) { On().SetUseSafeArea(false); + this.bill = bill; Title = bill.Name; + ToolbarItems.Add(new ToolbarItem + { + IconImageSource = "location.png", + Order = ToolbarItemOrder.Primary, + Command = new Command(OnSynced) + }); + if (bill.Latitude != null && bill.Longitude != null) { var (longitude, latitude) = (bill.Longitude.Value, bill.Latitude.Value).Wgs84ToGcj02(); @@ -32,5 +52,78 @@ namespace Billing.Views }; } } + + protected override void OnDisappearing() + { + if (tokenSource != null && !tokenSource.IsCancellationRequested) + { + tokenSource.Cancel(); + } + base.OnDisappearing(); + } + + private async void OnSynced() + { + if (Tap.IsBusy) + { + return; + } + using (Tap.Start()) + { + if (tokenSource != null) + { + return; + } + var location = await GetCurrentLocation(); + if (location != null) + { + Synced?.Invoke(this, location); + + MainThread.BeginInvokeOnMainThread(() => + { + var (longitude, latitude) = (location.Longitude, location.Latitude).Wgs84ToGcj02(); + var position = new Position(latitude, longitude); + var mapSpan = new MapSpan(position, 0.01, 0.01); + Content = new Map(mapSpan) + { + Pins = + { + new Pin + { + Label = bill.Name, + Type = PinType.Generic, + Position = position, + Address = bill.Store + } + } + }; + }); + } + } + } + + private async Task GetCurrentLocation() + { + try + { + var request = new GeolocationRequest(GeolocationAccuracy.Best, TimeSpan.FromSeconds(10)); + tokenSource = new CancellationTokenSource(); + var status = await Helper.CheckAndRequestPermissionAsync(); + if (status != PermissionStatus.Granted) + { + return null; + } + return await Geolocation.GetLocationAsync(request, tokenSource.Token); + } + catch (FeatureNotSupportedException) { } + catch (FeatureNotEnabledException) { } + catch (PermissionException) { } + catch (Exception ex) + { + Helper.Error("location.get", ex); + } + tokenSource = null; + return null; + } } } \ No newline at end of file diff --git a/Billing/Billing.Android/Billing.Android.csproj b/Billing/Billing.Android/Billing.Android.csproj index c36f648..04ae76e 100644 --- a/Billing/Billing.Android/Billing.Android.csproj +++ b/Billing/Billing.Android/Billing.Android.csproj @@ -72,9 +72,9 @@ - - - + + + diff --git a/Billing/Billing.Android/Properties/AndroidManifest.xml b/Billing/Billing.Android/Properties/AndroidManifest.xml index 9de3091..68500d3 100644 --- a/Billing/Billing.Android/Properties/AndroidManifest.xml +++ b/Billing/Billing.Android/Properties/AndroidManifest.xml @@ -1,5 +1,5 @@  - + diff --git a/Billing/Billing.Android/Resources/drawable-mdpi/location.png b/Billing/Billing.Android/Resources/drawable-mdpi/location.png new file mode 100644 index 0000000..11812b1 Binary files /dev/null and b/Billing/Billing.Android/Resources/drawable-mdpi/location.png differ diff --git a/Billing/Billing.Android/Resources/drawable-mdpi/pin.png b/Billing/Billing.Android/Resources/drawable-mdpi/pin.png new file mode 100644 index 0000000..8d1115d Binary files /dev/null and b/Billing/Billing.Android/Resources/drawable-mdpi/pin.png differ diff --git a/Billing/Billing.Android/Resources/drawable-mdpi/sync.png b/Billing/Billing.Android/Resources/drawable-mdpi/sync.png new file mode 100644 index 0000000..690ca26 Binary files /dev/null and b/Billing/Billing.Android/Resources/drawable-mdpi/sync.png differ diff --git a/Billing/Billing.Android/Resources/drawable-xhdpi/location.png b/Billing/Billing.Android/Resources/drawable-xhdpi/location.png new file mode 100644 index 0000000..5a484be Binary files /dev/null and b/Billing/Billing.Android/Resources/drawable-xhdpi/location.png differ diff --git a/Billing/Billing.Android/Resources/drawable-xhdpi/pin.png b/Billing/Billing.Android/Resources/drawable-xhdpi/pin.png new file mode 100644 index 0000000..9f2d3cb Binary files /dev/null and b/Billing/Billing.Android/Resources/drawable-xhdpi/pin.png differ diff --git a/Billing/Billing.Android/Resources/drawable-xhdpi/sync.png b/Billing/Billing.Android/Resources/drawable-xhdpi/sync.png new file mode 100644 index 0000000..eccd239 Binary files /dev/null and b/Billing/Billing.Android/Resources/drawable-xhdpi/sync.png differ diff --git a/Billing/Billing.Android/Resources/drawable-xxhdpi/location.png b/Billing/Billing.Android/Resources/drawable-xxhdpi/location.png new file mode 100644 index 0000000..da44789 Binary files /dev/null and b/Billing/Billing.Android/Resources/drawable-xxhdpi/location.png differ diff --git a/Billing/Billing.Android/Resources/drawable-xxhdpi/pin.png b/Billing/Billing.Android/Resources/drawable-xxhdpi/pin.png new file mode 100644 index 0000000..b873583 Binary files /dev/null and b/Billing/Billing.Android/Resources/drawable-xxhdpi/pin.png differ diff --git a/Billing/Billing.Android/Resources/drawable-xxhdpi/sync.png b/Billing/Billing.Android/Resources/drawable-xxhdpi/sync.png new file mode 100644 index 0000000..645a53a Binary files /dev/null and b/Billing/Billing.Android/Resources/drawable-xxhdpi/sync.png differ diff --git a/Billing/Billing.Android/Resources/drawable/location.png b/Billing/Billing.Android/Resources/drawable/location.png new file mode 100644 index 0000000..ce6ef9a Binary files /dev/null and b/Billing/Billing.Android/Resources/drawable/location.png differ diff --git a/Billing/Billing.Android/Resources/drawable/pin.png b/Billing/Billing.Android/Resources/drawable/pin.png new file mode 100644 index 0000000..53a000c Binary files /dev/null and b/Billing/Billing.Android/Resources/drawable/pin.png differ diff --git a/Billing/Billing.Android/Resources/drawable/sync.png b/Billing/Billing.Android/Resources/drawable/sync.png new file mode 100644 index 0000000..3025051 Binary files /dev/null and b/Billing/Billing.Android/Resources/drawable/sync.png differ diff --git a/Billing/Billing.iOS/Billing.iOS.csproj b/Billing/Billing.iOS/Billing.iOS.csproj index d0d2c6e..a7d690e 100644 --- a/Billing/Billing.iOS/Billing.iOS.csproj +++ b/Billing/Billing.iOS/Billing.iOS.csproj @@ -100,6 +100,15 @@ + + + + + + + + + @@ -179,9 +188,9 @@ - - - + + + diff --git a/Billing/Billing.iOS/Info.plist b/Billing/Billing.iOS/Info.plist index 89eeacc..fa778bd 100644 --- a/Billing/Billing.iOS/Info.plist +++ b/Billing/Billing.iOS/Info.plist @@ -80,9 +80,9 @@ CFBundleVersion - 20 + 21 CFBundleShortVersionString - 1.2.328 + 1.2.411 LSApplicationQueriesSchemes mailto diff --git a/Billing/Billing.iOS/Resources/location.png b/Billing/Billing.iOS/Resources/location.png new file mode 100644 index 0000000..11812b1 Binary files /dev/null and b/Billing/Billing.iOS/Resources/location.png differ diff --git a/Billing/Billing.iOS/Resources/location@2x.png b/Billing/Billing.iOS/Resources/location@2x.png new file mode 100644 index 0000000..5a484be Binary files /dev/null and b/Billing/Billing.iOS/Resources/location@2x.png differ diff --git a/Billing/Billing.iOS/Resources/location@3x.png b/Billing/Billing.iOS/Resources/location@3x.png new file mode 100644 index 0000000..da44789 Binary files /dev/null and b/Billing/Billing.iOS/Resources/location@3x.png differ diff --git a/Billing/Billing.iOS/Resources/pin.png b/Billing/Billing.iOS/Resources/pin.png new file mode 100644 index 0000000..8d1115d Binary files /dev/null and b/Billing/Billing.iOS/Resources/pin.png differ diff --git a/Billing/Billing.iOS/Resources/pin@2x.png b/Billing/Billing.iOS/Resources/pin@2x.png new file mode 100644 index 0000000..9f2d3cb Binary files /dev/null and b/Billing/Billing.iOS/Resources/pin@2x.png differ diff --git a/Billing/Billing.iOS/Resources/pin@3x.png b/Billing/Billing.iOS/Resources/pin@3x.png new file mode 100644 index 0000000..b873583 Binary files /dev/null and b/Billing/Billing.iOS/Resources/pin@3x.png differ diff --git a/Billing/Billing.iOS/Resources/sync.png b/Billing/Billing.iOS/Resources/sync.png new file mode 100644 index 0000000..690ca26 Binary files /dev/null and b/Billing/Billing.iOS/Resources/sync.png differ diff --git a/Billing/Billing.iOS/Resources/sync@2x.png b/Billing/Billing.iOS/Resources/sync@2x.png new file mode 100644 index 0000000..eccd239 Binary files /dev/null and b/Billing/Billing.iOS/Resources/sync@2x.png differ diff --git a/Billing/Billing.iOS/Resources/sync@3x.png b/Billing/Billing.iOS/Resources/sync@3x.png new file mode 100644 index 0000000..645a53a Binary files /dev/null and b/Billing/Billing.iOS/Resources/sync@3x.png differ