Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 8534920

Browse files
David BritchDavid Britch
authored andcommitted
Performant SettingViews on iOS
1 parent 33366ea commit 8534920

File tree

2 files changed

+196
-296
lines changed

2 files changed

+196
-296
lines changed

src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs

Lines changed: 21 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@ namespace eShopOnContainers.Core.ViewModels
1313
{
1414
public class SettingsViewModel : ViewModelBase
1515
{
16-
private string _titleUseAzureServices;
17-
private string _descriptionUseAzureServices;
1816
private bool _useAzureServices;
19-
private string _titleUseFakeLocation;
20-
private string _descriptionUseFakeLocation;
2117
private bool _allowGpsLocation;
22-
private string _titleAllowGpsLocation;
23-
private string _descriptionAllowGpsLocation;
2418
private bool _useFakeLocation;
2519
private string _endpoint;
2620
private double _latitude;
@@ -48,21 +42,16 @@ public SettingsViewModel(ISettingsService settingsService, ILocationService loca
4842

4943
public string TitleUseAzureServices
5044
{
51-
get => _titleUseAzureServices;
52-
set
53-
{
54-
_titleUseAzureServices = value;
55-
RaisePropertyChanged(() => TitleUseAzureServices);
56-
}
45+
get { return !UseAzureServices ? "Use Mock Services" : "Use Microservices/Containers from eShopOnContainers"; }
5746
}
5847

5948
public string DescriptionUseAzureServices
6049
{
61-
get => _descriptionUseAzureServices;
62-
set
50+
get
6351
{
64-
_descriptionUseAzureServices = value;
65-
RaisePropertyChanged(() => DescriptionUseAzureServices);
52+
return !UseAzureServices
53+
? "Mock Services are simulated objects that mimic the behavior of real services using a controlled approach."
54+
: "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.";
6655
}
6756
}
6857

@@ -72,30 +61,23 @@ public bool UseAzureServices
7261
set
7362
{
7463
_useAzureServices = value;
75-
7664
UpdateUseAzureServices();
77-
7865
RaisePropertyChanged(() => UseAzureServices);
7966
}
8067
}
8168

8269
public string TitleUseFakeLocation
8370
{
84-
get => _titleUseFakeLocation;
85-
set
86-
{
87-
_titleUseFakeLocation = value;
88-
RaisePropertyChanged(() => TitleUseFakeLocation);
89-
}
71+
get { return !UseFakeLocation ? "Use Real Location" : "Use Fake Location"; }
9072
}
9173

9274
public string DescriptionUseFakeLocation
9375
{
94-
get => _descriptionUseFakeLocation;
95-
set
76+
get
9677
{
97-
_descriptionUseFakeLocation = value;
98-
RaisePropertyChanged(() => DescriptionUseFakeLocation);
78+
return !UseFakeLocation
79+
? "When enabling location, the app will attempt to use the location from the device."
80+
: "Fake Location data is added for marketing campaign testing.";
9981
}
10082
}
10183

@@ -105,30 +87,23 @@ public bool UseFakeLocation
10587
set
10688
{
10789
_useFakeLocation = value;
108-
10990
UpdateFakeLocation();
110-
11191
RaisePropertyChanged(() => UseFakeLocation);
11292
}
11393
}
11494

11595
public string TitleAllowGpsLocation
11696
{
117-
get => _titleAllowGpsLocation;
118-
set
119-
{
120-
_titleAllowGpsLocation = value;
121-
RaisePropertyChanged(() => TitleAllowGpsLocation);
122-
}
97+
get { return !AllowGpsLocation ? "GPS Location Disabled" : "GPS Location Enabled"; }
12398
}
12499

125100
public string DescriptionAllowGpsLocation
126101
{
127-
get => _descriptionAllowGpsLocation;
128-
set
102+
get
129103
{
130-
_descriptionAllowGpsLocation = value;
131-
RaisePropertyChanged(() => DescriptionAllowGpsLocation);
104+
return !AllowGpsLocation
105+
? "When disabling location, you won't receive location campaigns based upon your location."
106+
: "When enabling location, you'll receive location campaigns based upon your location.";
132107
}
133108
}
134109

@@ -148,12 +123,10 @@ public string Endpoint
148123
set
149124
{
150125
_endpoint = value;
151-
152126
if (!string.IsNullOrEmpty(_endpoint))
153127
{
154128
UpdateEndpoint();
155129
}
156-
157130
RaisePropertyChanged(() => Endpoint);
158131
}
159132
}
@@ -164,9 +137,7 @@ public double Latitude
164137
set
165138
{
166139
_latitude = value;
167-
168140
UpdateLatitude();
169-
170141
RaisePropertyChanged(() => Latitude);
171142
}
172143
}
@@ -177,9 +148,7 @@ public double Longitude
177148
set
178149
{
179150
_longitude = value;
180-
181151
UpdateLongitude();
182-
183152
RaisePropertyChanged(() => Longitude);
184153
}
185154
}
@@ -190,9 +159,7 @@ public bool AllowGpsLocation
190159
set
191160
{
192161
_allowGpsLocation = value;
193-
194162
UpdateAllowGpsLocation();
195-
196163
RaisePropertyChanged(() => AllowGpsLocation);
197164
}
198165
}
@@ -207,19 +174,11 @@ public bool AllowGpsLocation
207174

208175
public ICommand ToggleAllowGpsLocationCommand => new Command(ToggleAllowGpsLocation);
209176

210-
public override Task InitializeAsync(object navigationData)
211-
{
212-
UpdateInfoUseAzureServices();
213-
UpdateInfoFakeLocation();
214-
UpdateInfoAllowGpsLocation();
215-
216-
return base.InitializeAsync(navigationData);
217-
}
218-
219177
private async Task ToggleMockServicesAsync()
220178
{
221179
ViewModelLocator.UpdateDependencies(!UseAzureServices);
222-
UpdateInfoUseAzureServices();
180+
RaisePropertyChanged(() => TitleUseAzureServices);
181+
RaisePropertyChanged(() => DescriptionUseAzureServices);
223182

224183
var previousPageViewModel = NavigationService.PreviousPageViewModel;
225184
if (previousPageViewModel != null)
@@ -243,7 +202,8 @@ private async Task ToggleMockServicesAsync()
243202
private void ToggleFakeLocationAsync()
244203
{
245204
ViewModelLocator.UpdateDependencies(!UseAzureServices);
246-
UpdateInfoFakeLocation();
205+
RaisePropertyChanged(() => TitleUseFakeLocation);
206+
RaisePropertyChanged(() => DescriptionUseFakeLocation);
247207
}
248208

249209
private async Task ToggleSendLocationAsync()
@@ -263,53 +223,10 @@ private async Task ToggleSendLocationAsync()
263223

264224
private void ToggleAllowGpsLocation()
265225
{
266-
UpdateInfoAllowGpsLocation();
267-
}
268-
269-
private void UpdateInfoUseAzureServices()
270-
{
271-
if (!UseAzureServices)
272-
{
273-
TitleUseAzureServices = "Use Mock Services";
274-
DescriptionUseAzureServices = "Mock Services are simulated objects that mimic the behavior of real services using a controlled approach.";
275-
}
276-
else
277-
{
278-
TitleUseAzureServices = "Use Microservices/Containers from eShopOnContainers";
279-
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.";
280-
}
281-
}
282-
283-
private void UpdateInfoFakeLocation()
284-
{
285-
if (!UseFakeLocation)
286-
{
287-
TitleUseFakeLocation = "Use Real Location";
288-
DescriptionUseFakeLocation = "When enabling location, the app will attempt to use the location from the device.";
289-
290-
}
291-
else
292-
{
293-
TitleUseFakeLocation = "Use Fake Location";
294-
DescriptionUseFakeLocation = "Fake Location data is added for marketing campaign testing.";
295-
}
226+
RaisePropertyChanged(() => TitleAllowGpsLocation);
227+
RaisePropertyChanged(() => DescriptionAllowGpsLocation);
296228
}
297229

298-
private void UpdateInfoAllowGpsLocation()
299-
{
300-
if (!AllowGpsLocation)
301-
{
302-
TitleAllowGpsLocation = "GPS Location Disabled";
303-
DescriptionAllowGpsLocation = "When disabling location, you won't receive location campaigns based upon your location.";
304-
}
305-
else
306-
{
307-
TitleAllowGpsLocation = "GPS Location Enabled";
308-
DescriptionAllowGpsLocation = "When enabling location, you'll receive location campaigns based upon your location.";
309-
310-
}
311-
}
312-
313230
private void UpdateUseAzureServices()
314231
{
315232
// Save use mocks services to local storage

0 commit comments

Comments
 (0)