Browse Source

Add Location Setting objects to view and ViewModel

pull/809/head
Christian Arenas 7 years ago
parent
commit
6a1d37b84f
2 changed files with 214 additions and 19 deletions
  1. +140
    -16
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs
  2. +74
    -3
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/SettingsView.xaml

+ 140
- 16
src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs View File

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

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

@ -108,11 +108,11 @@
Grid.Column="0"
Grid.Row="1">
<Label
Text="{Binding Title}"
Text="{Binding TitleUseAzureServices}"
TextColor="{StaticResource GreenColor}"
Style="{StaticResource SettingsTitleStyle}"/>
<Label
Text="{Binding Description}"
Text="{Binding DescriptionUseAzureServices}"
Style="{StaticResource SettingsDescriptionStyle}"/>
</StackLayout>
<!-- ON / OFF -->
@ -160,8 +160,79 @@
<Grid
Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="2"/>
<StackLayout
Grid.Column="0"
Grid.Row="4">
<Label
Text="{Binding TitleUseFakeLocation}"
TextColor="{StaticResource GreenColor}"
Style="{StaticResource SettingsTitleStyle}"/>
<Label
Text="{Binding DescriptionUseFakeLocation}"
Style="{StaticResource SettingsDescriptionStyle}"/>
</StackLayout>
<!-- ON / OFF -->
<controls:ToggleButton
Grid.Column="1"
Grid.Row="4"
Animate="True"
Checked="{Binding UseFakeLocation, Mode=TwoWay}"
Command="{Binding ToggleFakeLocationCommand}"
Style="{StaticResource SettingsToggleButtonStyle}">
<controls:ToggleButton.CheckedImage>
<OnPlatform x:TypeArguments="ImageSource"
Android="switch_on.png"
iOS="switchOn.png"
WinPhone="Assets/switchOn.png"/>
</controls:ToggleButton.CheckedImage>
<controls:ToggleButton.UnCheckedImage>
<OnPlatform x:TypeArguments="ImageSource"
Android="switch_off.png"
iOS="switchOff.png"
WinPhone="Assets/switchOff.png"/>
</controls:ToggleButton.UnCheckedImage>
</controls:ToggleButton>
<!-- ENDPOINT -->
<StackLayout
Grid.Row="5"
Grid.Column="0"
Grid.ColumnSpan="2"
BackgroundColor="Gray"/>
Margin="12, 0, 12, 12"
IsVisible="{Binding UseFakeLocation}">
<Label
Text="Latitude"
Style="{StaticResource HeaderLabelStyle}"/>
<Entry
Text="{Binding Latitude, Mode=TwoWay}"
Keyboard="Numeric">
<Entry.Style>
<OnPlatform
x:TypeArguments="Style"
iOS="{StaticResource EntryStyle}"
Android="{StaticResource EntryStyle}"
WinPhone="{StaticResource UwpEntryStyle}"/>
</Entry.Style>
</Entry>
<Label
Text="Longitude"
Style="{StaticResource HeaderLabelStyle}"/>
<Entry
Text="{Binding Longitude, Mode=TwoWay}"
Keyboard="Numeric">
<Entry.Style>
<OnPlatform
x:TypeArguments="Style"
iOS="{StaticResource EntryStyle}"
Android="{StaticResource EntryStyle}"
WinPhone="{StaticResource UwpEntryStyle}"/>
</Entry.Style>
</Entry>
<Button
Command="{Binding ToggleSendLocationCommand}"
Text="Send Location"/>
</StackLayout>
</Grid>
</StackLayout>
</ScrollView>


Loading…
Cancel
Save