Browse Source

fix xamarin location values when saving the settings with double type

pull/241/head
Christian Arenas 7 years ago
parent
commit
010f805a90
7 changed files with 46 additions and 17 deletions
  1. +1
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml
  2. +5
    -4
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml.cs
  3. +24
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Converters/DoubleConverter.cs
  4. +6
    -6
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Helpers/Settings.cs
  5. +7
    -5
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs
  6. +2
    -2
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/SettingsView.xaml
  7. +1
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/eShopOnContainers.Core.csproj

+ 1
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml View File

@ -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"


+ 5
- 4
src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml.cs View File

@ -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>();


+ 24
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Converters/DoubleConverter.cs View File

@ -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;
}
}
}

+ 6
- 6
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Helpers/Settings.cs View File

@ -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


+ 7
- 5
src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs View File

@ -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()


+ 2
- 2
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/SettingsView.xaml View File

@ -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


+ 1
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Core/eShopOnContainers.Core.csproj View File

@ -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…
Cancel
Save