fix xamarin location values when saving the settings with double type
This commit is contained in:
		
							parent
							
								
									64782e1d1a
								
							
						
					
					
						commit
						010f805a90
					
				| @ -111,6 +111,7 @@ | ||||
|             <converters:WebNavigatingEventArgsConverter x:Key="WebNavigatingEventArgsConverter" /> | ||||
|             <converters:WebNavigatedEventArgsConverter x:Key="WebNavigatedEventArgsConverter" /> | ||||
|             <converters:StringNullOrEmptyBoolConverter x:Key="StringNullOrEmptyBoolConverter" /> | ||||
|             <converters:DoubleConverter x:Key="DoubleConverter" /> | ||||
| 
 | ||||
|             <!-- STYLES --> | ||||
|             <Style x:Key="ValidationErrorLabelStyle" | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| using System; | ||||
| using System.Globalization; | ||||
| using eShopOnContainers.Core.Helpers; | ||||
| using eShopOnContainers.Services; | ||||
| using eShopOnContainers.Core.ViewModels.Base; | ||||
| @ -79,8 +80,8 @@ namespace eShopOnContainers | ||||
| 
 | ||||
|                 var position = await locator.GetPositionAsync(); | ||||
| 
 | ||||
|                 Settings.Latitude = position.Latitude; | ||||
|                 Settings.Longitude = position.Longitude; | ||||
|                 Settings.Latitude = position.Latitude.ToString(); | ||||
|                 Settings.Longitude = position.Longitude.ToString(); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
| @ -92,8 +93,8 @@ namespace eShopOnContainers | ||||
|         { | ||||
|             var location = new Location | ||||
|             { | ||||
|                 Latitude = Settings.Latitude, | ||||
|                 Longitude = Settings.Longitude | ||||
|                 Latitude = double.Parse(Settings.Latitude, CultureInfo.InvariantCulture), | ||||
|                 Longitude = double.Parse(Settings.Longitude, CultureInfo.InvariantCulture) | ||||
|             }; | ||||
| 
 | ||||
|             var locationService = ViewModelLocator.Resolve<ILocationService>(); | ||||
|  | ||||
| @ -0,0 +1,24 @@ | ||||
| using System; | ||||
| using System.Globalization; | ||||
| using Xamarin.Forms; | ||||
| 
 | ||||
| namespace eShopOnContainers.Core.Converters | ||||
| { | ||||
|     public class DoubleConverter : IValueConverter | ||||
|     { | ||||
|         public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||||
|         { | ||||
|             if (value is double) | ||||
|                 return value.ToString(); | ||||
|             return value; | ||||
|         } | ||||
| 
 | ||||
|         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||||
|         { | ||||
|             double doub; | ||||
|             if (double.TryParse(value as string, out doub)) | ||||
|                 return doub; | ||||
|             return value; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -69,16 +69,16 @@ namespace eShopOnContainers.Core.Helpers | ||||
|             set => AppSettings.AddOrUpdateValue<bool>(IdUseFakeLocation, value); | ||||
|         } | ||||
| 
 | ||||
|         public static double Latitude | ||||
|         public static string Latitude | ||||
|         { | ||||
|             get => AppSettings.GetValueOrDefault<double>(IdLatitude, FakeLatitudeDefault); | ||||
|             set => AppSettings.AddOrUpdateValue<double>(IdLatitude, value); | ||||
|             get => AppSettings.GetValueOrDefault<string>(IdLatitude, FakeLatitudeDefault.ToString()); | ||||
|             set => AppSettings.AddOrUpdateValue<string>(IdLatitude, value); | ||||
|         } | ||||
| 
 | ||||
|         public static double Longitude | ||||
|         public static string Longitude | ||||
|         { | ||||
|             get => AppSettings.GetValueOrDefault<double>(IdLongitude, FakeLongitudeDefault); | ||||
|             set => AppSettings.AddOrUpdateValue<double>(IdLongitude, value); | ||||
|             get => AppSettings.GetValueOrDefault<string>(IdLongitude, FakeLongitudeDefault.ToString()); | ||||
|             set => AppSettings.AddOrUpdateValue<string>(IdLongitude, value); | ||||
|         } | ||||
| 
 | ||||
|         public static bool AllowGpsLocation | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| namespace eShopOnContainers.Core.ViewModels | ||||
| using System.Globalization; | ||||
| 
 | ||||
| namespace eShopOnContainers.Core.ViewModels | ||||
| { | ||||
|     using System.Windows.Input; | ||||
|     using Xamarin.Forms; | ||||
| @ -34,8 +36,8 @@ | ||||
| 
 | ||||
|             _useAzureServices = !Settings.UseMocks; | ||||
|             _endpoint = Settings.UrlBase; | ||||
|             _latitude = Settings.Latitude; | ||||
|             _longitude = Settings.Longitude; | ||||
|             _latitude = double.Parse(Settings.Latitude, CultureInfo.CurrentCulture); | ||||
|             _longitude = double.Parse(Settings.Longitude, CultureInfo.CurrentCulture); | ||||
|             _useFakeLocation = Settings.UseFakeLocation; | ||||
|             _allowGpsLocation = Settings.AllowGpsLocation; | ||||
|             _gpsWarningMessage = string.Empty; | ||||
| @ -325,13 +327,13 @@ | ||||
|         private void UpdateLatitude() | ||||
|         { | ||||
|             // Update fake latitude (save to local storage) | ||||
|             Settings.Latitude = _latitude; | ||||
|             Settings.Latitude = _latitude.ToString(); | ||||
|         } | ||||
| 
 | ||||
|         private void UpdateLongitude() | ||||
|         { | ||||
|             // Update fake longitude (save to local storage) | ||||
|             Settings.Longitude = _longitude; | ||||
|             Settings.Longitude = _longitude.ToString(); | ||||
|         } | ||||
| 
 | ||||
|         private void UpdateAllowGpsLocation() | ||||
|  | ||||
| @ -219,7 +219,7 @@ | ||||
|                             Text="Latitude" | ||||
|                             Style="{StaticResource HeaderLabelStyle}"/> | ||||
|                         <Entry | ||||
|                             Text="{Binding Latitude, Mode=TwoWay}" | ||||
|                             Text="{Binding Latitude, Mode=TwoWay, Converter={StaticResource DoubleConverter}}" | ||||
|                             Keyboard="Text"> | ||||
|                             <Entry.Style> | ||||
|                                 <OnPlatform  | ||||
| @ -233,7 +233,7 @@ | ||||
|                             Text="Longitude" | ||||
|                             Style="{StaticResource HeaderLabelStyle}"/> | ||||
|                         <Entry | ||||
|                             Text="{Binding Longitude, Mode=TwoWay}" | ||||
|                             Text="{Binding Longitude, Mode=TwoWay, Converter={StaticResource DoubleConverter}}" | ||||
|                             Keyboard="Text"> | ||||
|                             <Entry.Style> | ||||
|                                 <OnPlatform  | ||||
|  | ||||
| @ -49,6 +49,7 @@ | ||||
|     </Compile> | ||||
|     <Compile Include="Controls\CustomTabbedPage.cs" /> | ||||
|     <Compile Include="Controls\ToggleButton.cs" /> | ||||
|     <Compile Include="Converters\DoubleConverter.cs" /> | ||||
|     <Compile Include="Converters\StringNullOrEmptyBoolConverter.cs" /> | ||||
|     <Compile Include="Converters\CountToBoolConverter.cs" /> | ||||
|     <Compile Include="Converters\DatetimeConverter.cs" /> | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user