diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs
index 4596eb25c..8bfe9ed25 100644
--- a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs
+++ b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs
@@ -4,38 +4,51 @@ using Xamarin.Forms;
using System.Threading.Tasks;
using eShopOnContainers.Core.Helpers;
using eShopOnContainers.Core.Models.User;
+using System;
+using eShopOnContainers.Core.Models.Location;
+using eShopOnContainers.Core.Services.Location;
namespace eShopOnContainers.Core.ViewModels
{
public class SettingsViewModel : ViewModelBase
{
- private string _title;
- private string _description;
+ private string _titleUseAzureServices;
+ private string _descriptionUseAzureServices;
private bool _useAzureServices;
+ private string _titleUseFakeLocation;
+ private string _descriptionUseFakeLocation;
+ private bool _useFakeLocation;
private string _endpoint;
+ private double _latitude;
+ private double _longitude;
+ private ILocationService _locationService;
- public SettingsViewModel()
+ public SettingsViewModel(ILocationService locationService)
{
UseAzureServices = !Settings.UseMocks;
+ _useFakeLocation = Settings.UseFakeLocation;
+ _latitude = Settings.FakeLatitude;
+ _longitude = Settings.FakeLongitude;
+ _locationService = locationService;
}
- public string Title
+ public string TitleUseAzureServices
{
- get { return _title; }
+ get { return _titleUseAzureServices; }
set
{
- _title = value;
- RaisePropertyChanged(() => Title);
+ _titleUseAzureServices = value;
+ RaisePropertyChanged(() => TitleUseAzureServices);
}
}
- public string Description
+ public string DescriptionUseAzureServices
{
- get { return _description; }
+ get { return _descriptionUseAzureServices; }
set
{
- _description = value;
- RaisePropertyChanged(() => Description);
+ _descriptionUseAzureServices = value;
+ RaisePropertyChanged(() => DescriptionUseAzureServices);
}
}
@@ -52,6 +65,39 @@ namespace eShopOnContainers.Core.ViewModels
}
}
+ public string TitleUseFakeLocation
+ {
+ get { return _titleUseFakeLocation; }
+ set
+ {
+ _titleUseFakeLocation = value;
+ RaisePropertyChanged(() => TitleUseFakeLocation);
+ }
+ }
+
+ public string DescriptionUseFakeLocation
+ {
+ get { return _descriptionUseFakeLocation; }
+ set
+ {
+ _descriptionUseFakeLocation = value;
+ RaisePropertyChanged(() => DescriptionUseFakeLocation);
+ }
+ }
+
+ public bool UseFakeLocation
+ {
+ get { return _useFakeLocation; }
+ set
+ {
+ _useFakeLocation = value;
+
+ // Save use fake location services to local storage
+ Settings.UseFakeLocation = _useFakeLocation;
+ RaisePropertyChanged(() => UseFakeLocation);
+ }
+ }
+
public string Endpoint
{
get { return _endpoint; }
@@ -68,12 +114,47 @@ namespace eShopOnContainers.Core.ViewModels
}
}
+ public double Latitude
+ {
+ get { return _latitude; }
+ set
+ {
+ _latitude = value;
+
+ UpdateLatitude(_latitude);
+
+ RaisePropertyChanged(() => Latitude);
+ }
+ }
+
+ public double Longitude
+ {
+ get { return _longitude; }
+ set
+ {
+ _longitude = value;
+
+ UpdateLongitude(_longitude);
+
+ RaisePropertyChanged(() => Longitude);
+ }
+ }
+
public ICommand ToggleMockServicesCommand => new Command(async () => await ToggleMockServicesAsync());
+ public ICommand ToggleFakeLocationCommand => new Command(() => ToggleFakeLocationAsync());
+
+ public ICommand ToggleSendLocationCommand => new Command(async () => await ToggleSendLocationAsync());
+
public override Task InitializeAsync(object navigationData)
{
UpdateInfo();
+ UpdateInfoFakeLocation();
+
Endpoint = Settings.UrlBase;
+ _latitude = Settings.FakeLatitude;
+ _longitude = Settings.FakeLongitude;
+ _useFakeLocation = Settings.UseFakeLocation;
return base.InitializeAsync(navigationData);
}
@@ -100,17 +181,48 @@ namespace eShopOnContainers.Core.ViewModels
}
}
- private void UpdateInfo()
+ private void ToggleFakeLocationAsync()
+ {
+ ViewModelLocator.RegisterDependencies(!UseAzureServices);
+ UpdateInfoFakeLocation();
+ }
+
+ private async Task ToggleSendLocationAsync()
+ {
+ LocationRequest locationRequest = new LocationRequest
+ {
+ Latitude = _latitude,
+ Longitude = _longitude
+ };
+
+ await _locationService.UpdateUserLocation(locationRequest);
+ }
+
+ private void UpdateInfo()
{
if (!UseAzureServices)
{
- Title = "Use Mock Services";
- Description = "Mock Services are simulated objects that mimic the behavior of real services using a controlled approach.";
+ TitleUseAzureServices = "Use Mock Services";
+ DescriptionUseAzureServices = "Mock Services are simulated objects that mimic the behavior of real services using a controlled approach.";
}
else
{
- Title = "Use Microservices/Containers from eShopOnContainers";
- Description = "When enabling the use of microservices/containers, the app will attempt to use real services deployed as Docker containers at the specified base endpoint, which will must be reachable through the network.";
+ TitleUseAzureServices = "Use Microservices/Containers from eShopOnContainers";
+ DescriptionUseAzureServices = "When enabling the use of microservices/containers, the app will attempt to use real services deployed as Docker containers at the specified base endpoint, which will must be reachable through the network.";
+ }
+ }
+
+ private void UpdateInfoFakeLocation()
+ {
+ if (!UseFakeLocation)
+ {
+ TitleUseFakeLocation = "Use Fake Location";
+ DescriptionUseFakeLocation = "Fake Location are added for marketing campaign testing.";
+ }
+ else
+ {
+ TitleUseFakeLocation = "Use Real Location";
+ DescriptionUseFakeLocation = "When enabling the use of real location, the app will attempt to use real location from the device.";
}
}
@@ -119,5 +231,17 @@ namespace eShopOnContainers.Core.ViewModels
// Update remote endpoint (save to local storage)
Settings.UrlBase = endpoint;
}
+
+ private void UpdateLatitude(double latitude)
+ {
+ // Update fake latitude (save to local storage)
+ Settings.FakeLatitude = latitude;
+ }
+
+ private void UpdateLongitude(double longitude)
+ {
+ // Update fake longitude (save to local storage)
+ Settings.FakeLongitude = longitude;
+ }
}
}
\ 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 7db37dd66..a8da35daa 100644
--- a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/SettingsView.xaml
+++ b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/SettingsView.xaml
@@ -108,11 +108,11 @@
Grid.Column="0"
Grid.Row="1">
@@ -160,8 +160,79 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Margin="12, 0, 12, 12"
+ IsVisible="{Binding UseFakeLocation}">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+