From f34a4fee2aed24e9abc4a3ede4ef56036bd5b48f Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Wed, 21 Jun 2017 19:39:49 +0200 Subject: [PATCH] Add text message when gps system is enabled and change the name GpsUsage to AllowGpsLocation --- .../eShopOnContainers.Core/App.xaml.cs | 8 +- .../Helpers/Settings.cs | 11 +-- .../ViewModels/SettingsViewModel.cs | 77 +++++++++++++------ .../Views/SettingsView.xaml | 29 ++++--- 4 files changed, 83 insertions(+), 42 deletions(-) diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml.cs b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml.cs index 22dcafce0..9430b1aba 100644 --- a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml.cs +++ b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml.cs @@ -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() diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Helpers/Settings.cs b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Helpers/Settings.cs index 70e1ee040..360cf189b 100644 --- a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Helpers/Settings.cs +++ b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Helpers/Settings.cs @@ -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(IdLatitude, FakeLatitudeValue); set => AppSettings.AddOrUpdateValue(IdLatitude, value); } + public static double Longitude { get => AppSettings.GetValueOrDefault(IdLongitude, FakeLongitudeValue); set => AppSettings.AddOrUpdateValue(IdLongitude, value); } - public static bool GpsUsage + public static bool AllowGpsLocation { - get => AppSettings.GetValueOrDefault(IdGpsUsage, GpsUsageValue); - set => AppSettings.AddOrUpdateValue(IdGpsUsage, value); + get => AppSettings.GetValueOrDefault(IdAllowGpsLocation, AllowGpsLocationValue); + set => AppSettings.AddOrUpdateValue(IdAllowGpsLocation, value); } } } \ No newline at end of file diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs index d3db564f3..a7767f865 100644 --- a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs +++ b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs @@ -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; + } + } } } } \ No newline at end of file diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/SettingsView.xaml b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/SettingsView.xaml index 76cb81b72..d29338735 100644 --- a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/SettingsView.xaml +++ b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/SettingsView.xaml @@ -33,6 +33,14 @@ Value="{StaticResource LittleSize}" /> + +