diff --git a/Billing.Shared/Helper.cs b/Billing.Shared/Helper.cs index 69223a3..897162c 100644 --- a/Billing.Shared/Helper.cs +++ b/Billing.Shared/Helper.cs @@ -147,6 +147,39 @@ namespace Billing } return status; } + + private static double TransformLatitude(double x, double y) + { + var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.Sqrt(Math.Abs(x)); + ret += (20.0 * Math.Sin(6.0 * x * Math.PI) + 20.0 * Math.Sin(2.0 * x * Math.PI)) * 2.0 / 3.0; + ret += (20.0 * Math.Sin(y * Math.PI) + 40.0 * Math.Sin(y / 3.0 * Math.PI)) * 2.0 / 3.0; + ret += (160.0 * Math.Sin(y / 12.0 * Math.PI) + 320 * Math.Sin(y * Math.PI / 30.0)) * 2.0 / 3.0; + return ret; + } + + private static double TransformLongitude(double x, double y) + { + var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.Sqrt(Math.Abs(x)); + ret += (20.0 * Math.Sin(6.0 * x * Math.PI) + 20.0 * Math.Sin(2.0 * x * Math.PI)) * 2.0 / 3.0; + ret += (20.0 * Math.Sin(x * Math.PI) + 40.0 * Math.Sin(x / 3.0 * Math.PI)) * 2.0 / 3.0; + ret += (150.0 * Math.Sin(x / 12.0 * Math.PI) + 300.0 * Math.Sin(x / 30.0 * Math.PI)) * 2.0 / 3.0; + return ret; + } + + public static (double longitude, double latitude) Wgs84ToGcj02(double longitude, double latitude) + { + var a = 6378245.0; + var ee = 0.00669342162296594323; + var offsetLatitude = TransformLatitude(longitude - 105.0, latitude - 35.0); + var offsetLongitude = TransformLongitude(longitude - 105.0, latitude - 35.0); + var radiusLatitude = latitude / 180.0 * Math.PI; + var magic = Math.Sin(radiusLatitude); + magic = 1 - ee * magic * magic; + var sqrtMagic = Math.Sqrt(magic); + offsetLatitude = offsetLatitude * 180.0 / (a * (1 - ee) / (magic * sqrtMagic) * Math.PI); + offsetLongitude = offsetLongitude * 180.0 / (a / sqrtMagic * Math.Cos(radiusLatitude) * Math.PI); + return (longitude + offsetLongitude, latitude + offsetLatitude); + } } public class AsyncLazy diff --git a/Billing.Shared/Themes/BaseTheme.cs b/Billing.Shared/Themes/BaseTheme.cs index e118f21..9dcd318 100644 --- a/Billing.Shared/Themes/BaseTheme.cs +++ b/Billing.Shared/Themes/BaseTheme.cs @@ -5,6 +5,8 @@ namespace Billing.Themes { public abstract class BaseTheme : ResourceDictionary { + public const double DefaultFontSize = 15.0; + public static Color CurrentPrimaryColor => (Color)Application.Current.Resources[PrimaryColor]; public static Color CurrentTextColor => (Color)Application.Current.Resources[TextColor]; public static Color CurrentSecondaryTextColor => (Color)Application.Current.Resources[SecondaryTextColor]; @@ -42,7 +44,7 @@ namespace Billing.Themes { Setters = { - new Setter { Property = Label.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(Label)) }, + new Setter { Property = Label.FontSizeProperty, Value = DefaultFontSize }, new Setter { Property = Label.TextColorProperty, Value = PrimaryMauiColor }, new Setter { Property = Label.FontFamilyProperty, Value = Definition.RegularFontFamily } } @@ -51,7 +53,7 @@ namespace Billing.Themes { Setters = { - new Setter { Property = Entry.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(Entry)) }, + new Setter { Property = Entry.FontSizeProperty, Value = DefaultFontSize }, new Setter { Property = Entry.FontFamilyProperty, Value = Definition.RegularFontFamily } } }); @@ -59,7 +61,7 @@ namespace Billing.Themes { Setters = { - new Setter { Property = Editor.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(Editor)) }, + new Setter { Property = Editor.FontSizeProperty, Value = DefaultFontSize }, new Setter { Property = Editor.FontFamilyProperty, Value = Definition.RegularFontFamily } } }); @@ -67,7 +69,7 @@ namespace Billing.Themes { Setters = { - new Setter { Property = DatePicker.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(DatePicker)) }, + new Setter { Property = DatePicker.FontSizeProperty, Value = DefaultFontSize }, new Setter { Property = DatePicker.FontFamilyProperty, Value = Definition.RegularFontFamily } } }); @@ -75,7 +77,7 @@ namespace Billing.Themes { Setters = { - new Setter { Property = TimePicker.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(TimePicker)) }, + new Setter { Property = TimePicker.FontSizeProperty, Value = DefaultFontSize }, new Setter { Property = TimePicker.FontFamilyProperty, Value = Definition.RegularFontFamily } } }); @@ -83,7 +85,7 @@ namespace Billing.Themes { Setters = { - new Setter { Property = Picker.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(TimePicker)) }, + new Setter { Property = Picker.FontSizeProperty, Value = DefaultFontSize }, new Setter { Property = Picker.FontFamilyProperty, Value = Definition.RegularFontFamily } } }); diff --git a/Billing.Shared/Views/AddBillPage.xaml.cs b/Billing.Shared/Views/AddBillPage.xaml.cs index 2ae04be..2fcdaf7 100644 --- a/Billing.Shared/Views/AddBillPage.xaml.cs +++ b/Billing.Shared/Views/AddBillPage.xaml.cs @@ -16,13 +16,14 @@ namespace Billing.Views { private static readonly BindableProperty CheckBillProperty = Helper.Create(nameof(CheckBill), defaultValue: new Command(() => { }, () => false)); private static readonly BindableProperty AmountProperty = Helper.Create(nameof(Amount)); - private static readonly BindableProperty NameProperty = Helper.Create(nameof(Name)); + private static readonly BindableProperty NameProperty = Helper.Create(nameof(Name), defaultValue: string.Empty); private static readonly BindableProperty CategoryProperty = Helper.Create(nameof(Category)); private static readonly BindableProperty WalletProperty = Helper.Create(nameof(Wallet)); private static readonly BindableProperty StoreProperty = Helper.Create(nameof(Store)); private static readonly BindableProperty CreatedDateProperty = Helper.Create(nameof(CreatedDate)); private static readonly BindableProperty CreatedTimeProperty = Helper.Create(nameof(CreatedTime)); private static readonly BindableProperty NoteProperty = Helper.Create(nameof(Note)); + private static readonly BindableProperty ViewLocationProperty = Helper.Create(nameof(ViewLocation), defaultValue: new Command(() => { }, () => false)); public Command CheckBill => (Command)GetValue(CheckBillProperty); public string Amount @@ -60,7 +61,7 @@ namespace Billing.Views public Command SelectCategory { get; } public Command SelectWallet { get; } - public Command ViewLocation { get; } + public Command ViewLocation => (Command)GetValue(ViewLocationProperty); public event EventHandler BillChecked; @@ -77,7 +78,6 @@ namespace Billing.Views createDate = date; SelectCategory = new Command(OnSelectCategory); SelectWallet = new Command(OnSelectWallet); - ViewLocation = new Command(() => { }, () => false); InitializeComponent(); Title = Resource.AddBill; @@ -89,10 +89,11 @@ namespace Billing.Views this.bill = bill; SelectCategory = new Command(OnSelectCategory); SelectWallet = new Command(OnSelectWallet); -#if __ANDROID__ - ViewLocation = new Command(() => { }, () => false); -#else - ViewLocation = new Command(OnViewLocation, () => bill != null && bill.Latitude != null && bill.Longitude != null); +#if __IOS__ + if (bill != null && bill.Latitude != null && bill.Longitude != null) + { + SetValue(ViewLocationProperty, new Command(OnViewLocation)); + } #endif InitializeComponent(); Title = Resource.EditBill; @@ -160,6 +161,12 @@ namespace Billing.Views return; } location = await Geolocation.GetLocationAsync(request, tokenSource.Token); +#if __IOS__ + if (bill == null) + { + SetValue(ViewLocationProperty, new Command(OnViewLocation)); + } +#endif } catch (FeatureNotSupportedException) { } catch (FeatureNotEnabledException) { } @@ -170,7 +177,7 @@ namespace Billing.Views } finally { - SetValue(CheckBillProperty, new Command(OnCheckBill)); + SetValue(CheckBillProperty, new Command(OnCheckBill)); } } @@ -292,7 +299,7 @@ namespace Billing.Views private async void OnViewLocation() { - if (bill == null) + if (bill == null && location == null) { return; } @@ -302,7 +309,13 @@ namespace Billing.Views } using (Tap.Start()) { - var page = new ViewLocationPage(bill); + var page = new ViewLocationPage(bill ?? new Bill + { + Name = Name, + Store = Store, + Longitude = location.Longitude, + Latitude = location.Latitude + }); await Navigation.PushAsync(page); } } diff --git a/Billing.Shared/Views/SettingPage.xaml b/Billing.Shared/Views/SettingPage.xaml index 4aa525e..6a2c28e 100644 --- a/Billing.Shared/Views/SettingPage.xaml +++ b/Billing.Shared/Views/SettingPage.xaml @@ -17,18 +17,18 @@ - - - - @@ -42,7 +42,7 @@ - diff --git a/Billing.Shared/Views/ViewLocationPage.cs b/Billing.Shared/Views/ViewLocationPage.cs index edbded6..f1ef086 100644 --- a/Billing.Shared/Views/ViewLocationPage.cs +++ b/Billing.Shared/Views/ViewLocationPage.cs @@ -14,7 +14,8 @@ namespace Billing.Views if (bill.Latitude != null && bill.Longitude != null) { - var position = new Position(bill.Latitude.Value, bill.Longitude.Value); + var (longitude, latitude) = Helper.Wgs84ToGcj02(bill.Longitude.Value, bill.Latitude.Value); + var position = new Position(latitude, longitude); var mapSpan = new MapSpan(position, 0.01, 0.01); Content = new Map(mapSpan) { diff --git a/Billing/Billing.Android/Properties/AndroidManifest.xml b/Billing/Billing.Android/Properties/AndroidManifest.xml index 09677bf..fdd0b61 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/Info.plist b/Billing/Billing.iOS/Info.plist index 8c17c86..4768c4e 100644 --- a/Billing/Billing.iOS/Info.plist +++ b/Billing/Billing.iOS/Info.plist @@ -80,9 +80,9 @@ CFBundleVersion - 18 + 19 CFBundleShortVersionString - 1.2.317 + 1.2.318 LSApplicationQueriesSchemes mailto