From 853492011ff32cef8471099535a1c6c3c5cdf62f Mon Sep 17 00:00:00 2001 From: David Britch Date: Mon, 11 Jun 2018 12:28:28 +0100 Subject: [PATCH] Performant SettingViews on iOS --- .../ViewModels/SettingsViewModel.cs | 125 +----- .../Views/SettingsView.xaml | 367 +++++++++--------- 2 files changed, 196 insertions(+), 296 deletions(-) diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs index 1969880cd..9ee3d5103 100644 --- a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs +++ b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs @@ -13,14 +13,8 @@ namespace eShopOnContainers.Core.ViewModels { public class SettingsViewModel : ViewModelBase { - private string _titleUseAzureServices; - private string _descriptionUseAzureServices; private bool _useAzureServices; - private string _titleUseFakeLocation; - private string _descriptionUseFakeLocation; private bool _allowGpsLocation; - private string _titleAllowGpsLocation; - private string _descriptionAllowGpsLocation; private bool _useFakeLocation; private string _endpoint; private double _latitude; @@ -48,21 +42,16 @@ namespace eShopOnContainers.Core.ViewModels public string TitleUseAzureServices { - get => _titleUseAzureServices; - set - { - _titleUseAzureServices = value; - RaisePropertyChanged(() => TitleUseAzureServices); - } + get { return !UseAzureServices ? "Use Mock Services" : "Use Microservices/Containers from eShopOnContainers"; } } public string DescriptionUseAzureServices { - get => _descriptionUseAzureServices; - set + get { - _descriptionUseAzureServices = value; - RaisePropertyChanged(() => DescriptionUseAzureServices); + return !UseAzureServices + ? "Mock Services are simulated objects that mimic the behavior of real services using a controlled approach." + : "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."; } } @@ -72,30 +61,23 @@ namespace eShopOnContainers.Core.ViewModels set { _useAzureServices = value; - UpdateUseAzureServices(); - RaisePropertyChanged(() => UseAzureServices); } } public string TitleUseFakeLocation { - get => _titleUseFakeLocation; - set - { - _titleUseFakeLocation = value; - RaisePropertyChanged(() => TitleUseFakeLocation); - } + get { return !UseFakeLocation ? "Use Real Location" : "Use Fake Location"; } } public string DescriptionUseFakeLocation { - get => _descriptionUseFakeLocation; - set + get { - _descriptionUseFakeLocation = value; - RaisePropertyChanged(() => DescriptionUseFakeLocation); + return !UseFakeLocation + ? "When enabling location, the app will attempt to use the location from the device." + : "Fake Location data is added for marketing campaign testing."; } } @@ -105,30 +87,23 @@ namespace eShopOnContainers.Core.ViewModels set { _useFakeLocation = value; - UpdateFakeLocation(); - RaisePropertyChanged(() => UseFakeLocation); } } public string TitleAllowGpsLocation { - get => _titleAllowGpsLocation; - set - { - _titleAllowGpsLocation = value; - RaisePropertyChanged(() => TitleAllowGpsLocation); - } + get { return !AllowGpsLocation ? "GPS Location Disabled" : "GPS Location Enabled"; } } public string DescriptionAllowGpsLocation { - get => _descriptionAllowGpsLocation; - set + get { - _descriptionAllowGpsLocation = value; - RaisePropertyChanged(() => DescriptionAllowGpsLocation); + return !AllowGpsLocation + ? "When disabling location, you won't receive location campaigns based upon your location." + : "When enabling location, you'll receive location campaigns based upon your location."; } } @@ -148,12 +123,10 @@ namespace eShopOnContainers.Core.ViewModels set { _endpoint = value; - if (!string.IsNullOrEmpty(_endpoint)) { UpdateEndpoint(); } - RaisePropertyChanged(() => Endpoint); } } @@ -164,9 +137,7 @@ namespace eShopOnContainers.Core.ViewModels set { _latitude = value; - UpdateLatitude(); - RaisePropertyChanged(() => Latitude); } } @@ -177,9 +148,7 @@ namespace eShopOnContainers.Core.ViewModels set { _longitude = value; - UpdateLongitude(); - RaisePropertyChanged(() => Longitude); } } @@ -190,9 +159,7 @@ namespace eShopOnContainers.Core.ViewModels set { _allowGpsLocation = value; - UpdateAllowGpsLocation(); - RaisePropertyChanged(() => AllowGpsLocation); } } @@ -207,19 +174,11 @@ namespace eShopOnContainers.Core.ViewModels public ICommand ToggleAllowGpsLocationCommand => new Command(ToggleAllowGpsLocation); - public override Task InitializeAsync(object navigationData) - { - UpdateInfoUseAzureServices(); - UpdateInfoFakeLocation(); - UpdateInfoAllowGpsLocation(); - - return base.InitializeAsync(navigationData); - } - private async Task ToggleMockServicesAsync() { ViewModelLocator.UpdateDependencies(!UseAzureServices); - UpdateInfoUseAzureServices(); + RaisePropertyChanged(() => TitleUseAzureServices); + RaisePropertyChanged(() => DescriptionUseAzureServices); var previousPageViewModel = NavigationService.PreviousPageViewModel; if (previousPageViewModel != null) @@ -243,7 +202,8 @@ namespace eShopOnContainers.Core.ViewModels private void ToggleFakeLocationAsync() { ViewModelLocator.UpdateDependencies(!UseAzureServices); - UpdateInfoFakeLocation(); + RaisePropertyChanged(() => TitleUseFakeLocation); + RaisePropertyChanged(() => DescriptionUseFakeLocation); } private async Task ToggleSendLocationAsync() @@ -263,53 +223,10 @@ namespace eShopOnContainers.Core.ViewModels private void ToggleAllowGpsLocation() { - UpdateInfoAllowGpsLocation(); - } - - private void UpdateInfoUseAzureServices() - { - if (!UseAzureServices) - { - TitleUseAzureServices = "Use Mock Services"; - DescriptionUseAzureServices = "Mock Services are simulated objects that mimic the behavior of real services using a controlled approach."; - } - else - { - 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 Real Location"; - DescriptionUseFakeLocation = "When enabling location, the app will attempt to use the location from the device."; - - } - else - { - TitleUseFakeLocation = "Use Fake Location"; - DescriptionUseFakeLocation = "Fake Location data is added for marketing campaign testing."; - } + RaisePropertyChanged(() => TitleAllowGpsLocation); + RaisePropertyChanged(() => DescriptionAllowGpsLocation); } - private void UpdateInfoAllowGpsLocation() - { - if (!AllowGpsLocation) - { - TitleAllowGpsLocation = "GPS Location Disabled"; - DescriptionAllowGpsLocation = "When disabling location, you won't receive location campaigns based upon your location."; - } - else - { - TitleAllowGpsLocation = "GPS Location Enabled"; - DescriptionAllowGpsLocation = "When enabling location, you'll receive location campaigns based upon your location."; - - } - } - private void UpdateUseAzureServices() { // Save use mocks services to local storage diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/SettingsView.xaml b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/SettingsView.xaml index 968b6321b..7d200bbc8 100644 --- a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/SettingsView.xaml +++ b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/SettingsView.xaml @@ -2,12 +2,12 @@ @@ -92,7 +92,7 @@ - + @@ -116,195 +116,178 @@ Animation="{StaticResource MockServicesAnimation}" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -