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

This commit is contained in:
Christian Arenas 2017-06-21 19:39:49 +02:00
parent 5f4d42520d
commit f34a4fee2a
4 changed files with 83 additions and 42 deletions

View File

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

View File

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

View File

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

View File

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