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:WebNavigatingEventArgsConverter x:Key="WebNavigatingEventArgsConverter" />
|
||||||
<converters:WebNavigatedEventArgsConverter x:Key="WebNavigatedEventArgsConverter" />
|
<converters:WebNavigatedEventArgsConverter x:Key="WebNavigatedEventArgsConverter" />
|
||||||
<converters:StringNullOrEmptyBoolConverter x:Key="StringNullOrEmptyBoolConverter" />
|
<converters:StringNullOrEmptyBoolConverter x:Key="StringNullOrEmptyBoolConverter" />
|
||||||
|
<converters:DoubleConverter x:Key="DoubleConverter" />
|
||||||
|
|
||||||
<!-- STYLES -->
|
<!-- STYLES -->
|
||||||
<Style x:Key="ValidationErrorLabelStyle"
|
<Style x:Key="ValidationErrorLabelStyle"
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
using eShopOnContainers.Core.Helpers;
|
using eShopOnContainers.Core.Helpers;
|
||||||
using eShopOnContainers.Services;
|
using eShopOnContainers.Services;
|
||||||
using eShopOnContainers.Core.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
@ -79,8 +80,8 @@ namespace eShopOnContainers
|
|||||||
|
|
||||||
var position = await locator.GetPositionAsync();
|
var position = await locator.GetPositionAsync();
|
||||||
|
|
||||||
Settings.Latitude = position.Latitude;
|
Settings.Latitude = position.Latitude.ToString();
|
||||||
Settings.Longitude = position.Longitude;
|
Settings.Longitude = position.Longitude.ToString();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -92,8 +93,8 @@ namespace eShopOnContainers
|
|||||||
{
|
{
|
||||||
var location = new Location
|
var location = new Location
|
||||||
{
|
{
|
||||||
Latitude = Settings.Latitude,
|
Latitude = double.Parse(Settings.Latitude, CultureInfo.InvariantCulture),
|
||||||
Longitude = Settings.Longitude
|
Longitude = double.Parse(Settings.Longitude, CultureInfo.InvariantCulture)
|
||||||
};
|
};
|
||||||
|
|
||||||
var locationService = ViewModelLocator.Resolve<ILocationService>();
|
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);
|
set => AppSettings.AddOrUpdateValue<bool>(IdUseFakeLocation, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double Latitude
|
public static string Latitude
|
||||||
{
|
{
|
||||||
get => AppSettings.GetValueOrDefault<double>(IdLatitude, FakeLatitudeDefault);
|
get => AppSettings.GetValueOrDefault<string>(IdLatitude, FakeLatitudeDefault.ToString());
|
||||||
set => AppSettings.AddOrUpdateValue<double>(IdLatitude, value);
|
set => AppSettings.AddOrUpdateValue<string>(IdLatitude, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double Longitude
|
public static string Longitude
|
||||||
{
|
{
|
||||||
get => AppSettings.GetValueOrDefault<double>(IdLongitude, FakeLongitudeDefault);
|
get => AppSettings.GetValueOrDefault<string>(IdLongitude, FakeLongitudeDefault.ToString());
|
||||||
set => AppSettings.AddOrUpdateValue<double>(IdLongitude, value);
|
set => AppSettings.AddOrUpdateValue<string>(IdLongitude, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool AllowGpsLocation
|
public static bool AllowGpsLocation
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace eShopOnContainers.Core.ViewModels
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace eShopOnContainers.Core.ViewModels
|
||||||
{
|
{
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
@ -34,8 +36,8 @@
|
|||||||
|
|
||||||
_useAzureServices = !Settings.UseMocks;
|
_useAzureServices = !Settings.UseMocks;
|
||||||
_endpoint = Settings.UrlBase;
|
_endpoint = Settings.UrlBase;
|
||||||
_latitude = Settings.Latitude;
|
_latitude = double.Parse(Settings.Latitude, CultureInfo.CurrentCulture);
|
||||||
_longitude = Settings.Longitude;
|
_longitude = double.Parse(Settings.Longitude, CultureInfo.CurrentCulture);
|
||||||
_useFakeLocation = Settings.UseFakeLocation;
|
_useFakeLocation = Settings.UseFakeLocation;
|
||||||
_allowGpsLocation = Settings.AllowGpsLocation;
|
_allowGpsLocation = Settings.AllowGpsLocation;
|
||||||
_gpsWarningMessage = string.Empty;
|
_gpsWarningMessage = string.Empty;
|
||||||
@ -325,13 +327,13 @@
|
|||||||
private void UpdateLatitude()
|
private void UpdateLatitude()
|
||||||
{
|
{
|
||||||
// Update fake latitude (save to local storage)
|
// Update fake latitude (save to local storage)
|
||||||
Settings.Latitude = _latitude;
|
Settings.Latitude = _latitude.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateLongitude()
|
private void UpdateLongitude()
|
||||||
{
|
{
|
||||||
// Update fake longitude (save to local storage)
|
// Update fake longitude (save to local storage)
|
||||||
Settings.Longitude = _longitude;
|
Settings.Longitude = _longitude.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateAllowGpsLocation()
|
private void UpdateAllowGpsLocation()
|
||||||
|
@ -219,7 +219,7 @@
|
|||||||
Text="Latitude"
|
Text="Latitude"
|
||||||
Style="{StaticResource HeaderLabelStyle}"/>
|
Style="{StaticResource HeaderLabelStyle}"/>
|
||||||
<Entry
|
<Entry
|
||||||
Text="{Binding Latitude, Mode=TwoWay}"
|
Text="{Binding Latitude, Mode=TwoWay, Converter={StaticResource DoubleConverter}}"
|
||||||
Keyboard="Text">
|
Keyboard="Text">
|
||||||
<Entry.Style>
|
<Entry.Style>
|
||||||
<OnPlatform
|
<OnPlatform
|
||||||
@ -233,7 +233,7 @@
|
|||||||
Text="Longitude"
|
Text="Longitude"
|
||||||
Style="{StaticResource HeaderLabelStyle}"/>
|
Style="{StaticResource HeaderLabelStyle}"/>
|
||||||
<Entry
|
<Entry
|
||||||
Text="{Binding Longitude, Mode=TwoWay}"
|
Text="{Binding Longitude, Mode=TwoWay, Converter={StaticResource DoubleConverter}}"
|
||||||
Keyboard="Text">
|
Keyboard="Text">
|
||||||
<Entry.Style>
|
<Entry.Style>
|
||||||
<OnPlatform
|
<OnPlatform
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Controls\CustomTabbedPage.cs" />
|
<Compile Include="Controls\CustomTabbedPage.cs" />
|
||||||
<Compile Include="Controls\ToggleButton.cs" />
|
<Compile Include="Controls\ToggleButton.cs" />
|
||||||
|
<Compile Include="Converters\DoubleConverter.cs" />
|
||||||
<Compile Include="Converters\StringNullOrEmptyBoolConverter.cs" />
|
<Compile Include="Converters\StringNullOrEmptyBoolConverter.cs" />
|
||||||
<Compile Include="Converters\CountToBoolConverter.cs" />
|
<Compile Include="Converters\CountToBoolConverter.cs" />
|
||||||
<Compile Include="Converters\DatetimeConverter.cs" />
|
<Compile Include="Converters\DatetimeConverter.cs" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user