Browse Source

Add text message when gps system is enabled and change the name GpsUsage to AllowGpsLocation

pull/223/merge
Christian Arenas 7 years ago
parent
commit
f34a4fee2a
4 changed files with 83 additions and 42 deletions
  1. +6
    -2
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml.cs
  2. +6
    -5
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Helpers/Settings.cs
  3. +52
    -25
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs
  4. +19
    -10
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/SettingsView.xaml

+ 6
- 2
src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml.cs View File

@ -50,7 +50,7 @@ namespace eShopOnContainers
await InitNavigation();
}
if (Settings.GpsUsage && !Settings.UseFakeLocation)
if (Settings.AllowGpsLocation && !Settings.UseFakeLocation)
{
await GetRealLocation();
}
@ -77,11 +77,15 @@ namespace eShopOnContainers
locator.AllowsBackgroundUpdates = true;
locator.DesiredAccuracy = 50;
var position = await locator.GetPositionAsync(20000);
var position = await locator.GetPositionAsync();
Settings.Latitude = position.Latitude;
Settings.Longitude = position.Longitude;
}
else
{
Settings.AllowGpsLocation = false;
}
}
private async Task SendCurrentLocation()


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

@ -28,12 +28,12 @@ namespace eShopOnContainers.Core.Helpers
private const string IdUseFakeLocation = "use_fake_location";
private const string IdLatitude = "latitude";
private const string IdLongitude = "flongitude";
private const string IdGpsUsage = "gps_usage";
private const string IdAllowGpsLocation = "allow_gps_location";
private static readonly string AccessTokenDefault = string.Empty;
private static readonly string IdTokenDefault = string.Empty;
private static readonly bool UseMocksDefault = true;
private static readonly bool UseFakeLocationDefault = false;
private static readonly bool GpsUsageValue = false;
private static readonly bool AllowGpsLocationValue = false;
private static readonly double FakeLatitudeValue = 47.604610d;
private static readonly double FakeLongitudeValue = -122.315752d;
private static readonly string UrlBaseDefault = GlobalSetting.Instance.BaseEndpoint;
@ -81,16 +81,17 @@ namespace eShopOnContainers.Core.Helpers
get => AppSettings.GetValueOrDefault<double>(IdLatitude, FakeLatitudeValue);
set => AppSettings.AddOrUpdateValue<double>(IdLatitude, value);
}
public static double Longitude
{
get => AppSettings.GetValueOrDefault<double>(IdLongitude, FakeLongitudeValue);
set => AppSettings.AddOrUpdateValue<double>(IdLongitude, value);
}
public static bool GpsUsage
public static bool AllowGpsLocation
{
get => AppSettings.GetValueOrDefault<bool>(IdGpsUsage, GpsUsageValue);
set => AppSettings.AddOrUpdateValue<bool>(IdGpsUsage, value);
get => AppSettings.GetValueOrDefault<bool>(IdAllowGpsLocation, AllowGpsLocationValue);
set => AppSettings.AddOrUpdateValue<bool>(IdAllowGpsLocation, value);
}
}
}

+ 52
- 25
src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs View File

@ -8,6 +8,7 @@
using Base;
using Models.Location;
using Services.Location;
using Plugin.Geolocator;
public class SettingsViewModel : ViewModelBase
{
@ -16,14 +17,16 @@
private bool _useAzureServices;
private string _titleUseFakeLocation;
private string _descriptionUseFakeLocation;
private bool _gpsUsage;
private string _titleGpsUsage;
private string _descriptionGpsUsage;
private bool _allowGpsLocation;
private string _titleAllowGpsLocation;
private string _descriptionAllowGpsLocation;
private bool _useFakeLocation;
private string _endpoint;
private double _latitude;
private double _longitude;
private string _gpsWarningMessage;
private readonly ILocationService _locationService;
public SettingsViewModel(ILocationService locationService)
@ -35,7 +38,8 @@
_latitude = Settings.Latitude;
_longitude = Settings.Longitude;
_useFakeLocation = Settings.UseFakeLocation;
_gpsUsage = Settings.GpsUsage;
_allowGpsLocation = Settings.AllowGpsLocation;
_gpsWarningMessage = string.Empty;
}
public string TitleUseAzureServices
@ -104,23 +108,33 @@
}
}
public string TitleGpsUsage
public string TitleAllowGpsLocation
{
get => _titleAllowGpsLocation;
set
{
_titleAllowGpsLocation = value;
RaisePropertyChanged(() => TitleAllowGpsLocation);
}
}
public string DescriptionAllowGpsLocation
{
get => _titleGpsUsage;
get => _descriptionAllowGpsLocation;
set
{
_titleGpsUsage = value;
RaisePropertyChanged(() => TitleGpsUsage);
_descriptionAllowGpsLocation = value;
RaisePropertyChanged(() => DescriptionAllowGpsLocation);
}
}
public string DescriptionGpsUsage
public string GpsWarningMessage
{
get => _descriptionGpsUsage;
get => _gpsWarningMessage;
set
{
_descriptionGpsUsage = value;
RaisePropertyChanged(() => DescriptionGpsUsage);
_gpsWarningMessage = value;
RaisePropertyChanged(() => GpsWarningMessage);
}
}
@ -166,16 +180,16 @@
}
}
public bool GpsUsage
public bool AllowGpsLocation
{
get => _gpsUsage;
get => _allowGpsLocation;
set
{
_gpsUsage = value;
_allowGpsLocation = value;
UpdateGpsUsage();
RaisePropertyChanged(() => GpsUsage);
RaisePropertyChanged(() => AllowGpsLocation);
}
}
@ -187,7 +201,7 @@
public ICommand ToggleSendLocationCommand => new Command(async () => await ToggleSendLocationAsync());
public ICommand ToggleGpsUsageCommand => new Command(ToggleGpsUsage);
public ICommand ToggleAllowGpsLocationCommand => new Command(ToggleAllowGpsLocation);
public override Task InitializeAsync(object navigationData)
{
@ -242,7 +256,7 @@
}
}
private void ToggleGpsUsage()
private void ToggleAllowGpsLocation()
{
UpdateInfoGpsUsage();
}
@ -277,15 +291,15 @@
private void UpdateInfoGpsUsage()
{
if (!GpsUsage)
if (!AllowGpsLocation)
{
TitleGpsUsage = "Enable GPS";
DescriptionGpsUsage = "When enabling the use of device gps you will get the location campaigns through your real location.";
TitleAllowGpsLocation = "Allow GPS location";
DescriptionAllowGpsLocation = "When allowing the use of device gps you will get the location campaigns through your real location.";
}
else
{
TitleGpsUsage = "Disable GPS";
DescriptionGpsUsage = "When disabling the use of device gps you won't get the location campaigns through your real location.";
TitleAllowGpsLocation = "Deny GPS location";
DescriptionAllowGpsLocation = "When denying the use of device gps you won't get the location campaigns through your real location.";
}
}
@ -321,7 +335,20 @@
private void UpdateGpsUsage()
{
Settings.GpsUsage = _gpsUsage;
if (_allowGpsLocation)
{
var locator = CrossGeolocator.Current;
if (!locator.IsGeolocationEnabled)
{
_allowGpsLocation = !_allowGpsLocation;
GpsWarningMessage = "Enable your GPS system in your device";
}
else
{
Settings.AllowGpsLocation = _allowGpsLocation;
GpsWarningMessage = string.Empty;
}
}
}
}
}

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

@ -33,6 +33,14 @@
Value="{StaticResource LittleSize}" />
</Style>
<Style x:Key="SettingsWarningMessageStyle"
TargetType="{x:Type Label}"
BasedOn="{StaticResource SettingsTitleStyle}">
<Setter Property="FontSize"
Value="{StaticResource LittleSize}" />
<Setter Property="TextColor" Value="Red" />
</Style>
<Style x:Key="SettingsToggleButtonStyle"
TargetType="{x:Type controls:ToggleButton}">
<Setter Property="HeightRequest"
@ -101,8 +109,6 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid
Grid.Row="0"
@ -247,29 +253,32 @@
Margin="12, 0, 12, 12"
IsVisible="{Binding UseFakeLocation, Converter={StaticResource InverseBoolConverter}}">
</StackLayout>
<Grid
<!--<Grid
Grid.Row="6"
Grid.Column="0"
Grid.ColumnSpan="2"/>
Grid.ColumnSpan="2"/>-->
<StackLayout
Grid.Column="0"
Grid.Row="7"
Grid.Row="6"
IsVisible="{Binding UseFakeLocation, Converter={StaticResource InverseBoolConverter}}">
<Label
Text="{Binding TitleGpsUsage}"
Text="{Binding TitleAllowGpsLocation}"
TextColor="{StaticResource GreenColor}"
Style="{StaticResource SettingsTitleStyle}"/>
<Label
Text="{Binding DescriptionGpsUsage}"
Text="{Binding DescriptionAllowGpsLocation}"
Style="{StaticResource SettingsDescriptionStyle}"/>
<Label
Text="{Binding GpsWarningMessage}"
Style="{StaticResource SettingsWarningMessageStyle}"/>
</StackLayout>
<!-- ON / OFF -->
<controls:ToggleButton
Grid.Column="1"
Grid.Row="7"
Grid.Row="6"
Animate="True"
Checked="{Binding GpsUsage, Mode=TwoWay}"
Command="{Binding ToggleGpsUsageCommand}"
Checked="{Binding AllowGpsLocation, Mode=TwoWay}"
Command="{Binding ToggleAllowGpsLocationCommand}"
Style="{StaticResource SettingsToggleButtonStyle}"
IsVisible="{Binding UseFakeLocation, Converter={StaticResource InverseBoolConverter}}">
<controls:ToggleButton.CheckedImage>


Loading…
Cancel
Save