1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
|
#import "MWMSettingsViewController.h"
#import "LocaleTranslator.h"
#import "MWMAuthorizationCommon.h"
#import "MWMNetworkPolicy.h"
#import "MWMSettings.h"
#import "MWMTextToSpeech+CPP.h"
#import "Statistics.h"
#import "SwiftBridge.h"
#import "WebViewController.h"
#import "3party/Alohalytics/src/alohalytics_objc.h"
#include "Framework.h"
#include "map/gps_tracker.hpp"
extern NSString * const kAlohalyticsTapEventKey;
@interface MWMSettingsViewController ()<SettingsTableViewSwitchCellDelegate>
@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * profileCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * unitsCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * zoomButtonsCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * is3dCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * autoDownloadCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * mobileInternetCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * recentTrackCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * fontScaleCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * transliterationCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * compassCalibrationCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * showOffersCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * statisticsCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * nightModeCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * perspectiveViewCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * autoZoomCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * voiceInstructionsCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewSwitchCell * simplifiedColorsCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * helpCell;
@property(weak, nonatomic) IBOutlet SettingsTableViewLinkCell * aboutCell;
@end
@implementation MWMSettingsViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = L(@"settings");
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self configCells];
}
- (void)configCells
{
[self configProfileSection];
[self configCommonSection];
[self configNavigationSection];
[self configInfoSection];
}
- (void)configProfileSection
{
NSString * userName = osm_auth_ios::OSMUserName();
[self.profileCell configWithTitle:L(@"profile") info:userName.length != 0 ? userName : @""];
}
- (void)configCommonSection
{
NSString * units = nil;
switch ([MWMSettings measurementUnits])
{
case MWMUnitsMetric: units = L(@"kilometres"); break;
case MWMUnitsImperial: units = L(@"miles"); break;
}
[self.unitsCell configWithTitle:L(@"measurement_units") info:units];
[self.zoomButtonsCell configWithDelegate:self
title:L(@"pref_zoom_title")
isOn:[MWMSettings zoomButtonsEnabled]];
bool on = true, _ = true;
GetFramework().Load3dMode(_, on);
[self.is3dCell configWithDelegate:self title:L(@"pref_map_3d_buildings_title") isOn:on];
[self.autoDownloadCell configWithDelegate:self
title:L(@"disable_autodownload")
isOn:![MWMSettings autoDownloadEnabled]];
NSString * mobileInternet = nil;
using stage = platform::NetworkPolicy::Stage;
switch (network_policy::GetStage())
{
case stage::Always: mobileInternet = L(@"mobile_data_option_always"); break;
case stage::Session: mobileInternet = L(@"mobile_data_option_today"); break;
case stage::Never: mobileInternet = L(@"mobile_data_option_never"); break;
}
[self.mobileInternetCell configWithTitle:L(@"mobile_data") info:mobileInternet];
NSString * recentTrack = nil;
if (!GpsTracker::Instance().IsEnabled())
{
recentTrack = L(@"duration_disabled");
}
else
{
switch (GpsTracker::Instance().GetDuration().count())
{
case 1: recentTrack = L(@"duration_1_hour"); break;
case 2: recentTrack = L(@"duration_2_hours"); break;
case 6: recentTrack = L(@"duration_6_hours"); break;
case 12: recentTrack = L(@"duration_12_hours"); break;
case 24: recentTrack = L(@"duration_1_day"); break;
default: NSAssert(false, @"Incorrect hours value"); break;
}
}
[self.recentTrackCell configWithTitle:L(@"pref_track_record_title") info:recentTrack];
[self.fontScaleCell configWithDelegate:self
title:L(@"big_font")
isOn:[MWMSettings largeFontSize]];
[self.transliterationCell configWithDelegate:self
title:L(@"whatsnew_transliteration_title")
isOn:[MWMSettings transliteration]];
[self.compassCalibrationCell configWithDelegate:self
title:L(@"pref_calibration_title")
isOn:[MWMSettings compassCalibrationEnabled]];
[self.showOffersCell configWithDelegate:self
title:L(@"showcase_settings_title")
isOn:![MWMSettings adForbidden]];
[self.statisticsCell configWithDelegate:self
title:L(@"allow_statistics")
isOn:[MWMSettings statisticsEnabled]];
}
- (void)configNavigationSection
{
NSString * nightMode = nil;
switch ([MWMSettings theme])
{
case MWMThemeVehicleDay: NSAssert(false, @"Invalid case");
case MWMThemeDay: nightMode = L(@"pref_map_style_default"); break;
case MWMThemeVehicleNight: NSAssert(false, @"Invalid case");
case MWMThemeNight: nightMode = L(@"pref_map_style_night"); break;
case MWMThemeAuto: nightMode = L(@"pref_map_style_auto"); break;
}
[self.nightModeCell configWithTitle:L(@"pref_map_style_title") info:nightMode];
bool _ = true, on = true;
GetFramework().Load3dMode(on, _);
[self.perspectiveViewCell configWithDelegate:self title:L(@"pref_map_3d_title") isOn:on];
[self.autoZoomCell configWithDelegate:self
title:L(@"pref_map_auto_zoom")
isOn:GetFramework().LoadAutoZoom()];
NSString * voiceInstructions = nil;
if ([MWMTextToSpeech isTTSEnabled])
{
NSString * savedLanguage = [MWMTextToSpeech savedLanguage];
if (savedLanguage.length != 0)
{
string const savedLanguageTwine = locale_translator::bcp47ToTwineLanguage(savedLanguage);
voiceInstructions = @(tts::translatedTwine(savedLanguageTwine).c_str());
}
}
else
{
voiceInstructions = L(@"duration_disabled");
}
[self.voiceInstructionsCell configWithTitle:L(@"pref_tts_language_title") info:voiceInstructions];
[self.simplifiedColorsCell configWithDelegate:self
title:L(@"pref_traffic_simplified_colors_title")
isOn:GetFramework().LoadTrafficSimplifiedColors()];
}
- (void)configInfoSection
{
[self.helpCell configWithTitle:L(@"help") info:nil];
[self.aboutCell configWithTitle:L(@"about_menu_title") info:nil];
}
#pragma mark - SettingsTableViewSwitchCellDelegate
- (void)switchCell:(SettingsTableViewSwitchCell *)cell didChangeValue:(BOOL)value
{
if (cell == self.zoomButtonsCell)
{
[Statistics logEvent:kStatEventName(kStatSettings, kStatToggleZoomButtonsVisibility)
withParameters:@{kStatValue : (value ? kStatVisible : kStatHidden)}];
[MWMSettings setZoomButtonsEnabled:value];
}
else if (cell == self.is3dCell)
{
[Statistics logEvent:kStatEventName(kStatSettings, kStat3DBuildings)
withParameters:@{kStatValue : (value ? kStatOn : kStatOff)}];
auto & f = GetFramework();
bool _ = true, is3dBuildings = true;
f.Load3dMode(_, is3dBuildings);
is3dBuildings = static_cast<bool>(value);
f.Save3dMode(_, is3dBuildings);
f.Allow3dMode(_, is3dBuildings);
}
else if (cell == self.autoDownloadCell)
{
[Statistics logEvent:kStatEventName(kStatSettings, kStatAutoDownload)
withParameters:@{kStatValue : (value ? kStatOn : kStatOff)}];
[MWMSettings setAutoDownloadEnabled:!value];
}
else if (cell == self.fontScaleCell)
{
[Statistics logEvent:kStatEventName(kStatSettings, kStatToggleLargeFontSize)
withParameters:@{kStatValue : (value ? kStatOn : kStatOff)}];
[MWMSettings setLargeFontSize:value];
}
else if (cell == self.transliterationCell)
{
[Statistics logEvent:kStatEventName(kStatSettings, kStatToggleTransliteration)
withParameters:@{kStatValue : (value ? kStatOn : kStatOff)}];
[MWMSettings setTransliteration:value];
}
else if (cell == self.compassCalibrationCell)
{
[Statistics logEvent:kStatEventName(kStatSettings, kStatToggleCompassCalibration)
withParameters:@{kStatValue : (value ? kStatOn : kStatOff)}];
[MWMSettings setCompassCalibrationEnabled:value];
}
else if (cell == self.showOffersCell)
{
[Statistics logEvent:kStatEventName(kStatSettings, kStatAd)
withParameters:@{kStatAction : kStatAd, kStatValue : (value ? kStatOn : kStatOff)}];
[MWMSettings setAdForbidden:!value];
}
else if (cell == self.statisticsCell)
{
[Statistics logEvent:kStatEventName(kStatSettings, kStatToggleStatistics)
withParameters:@{
kStatAction : kStatToggleStatistics,
kStatValue : (value ? kStatOn : kStatOff)
}];
[MWMSettings setStatisticsEnabled:value];
}
else if (cell == self.perspectiveViewCell)
{
[Statistics logEvent:kStatEventName(kStatSettings, kStat3D)
withParameters:@{kStatValue : (value ? kStatOn : kStatOff)}];
auto & f = GetFramework();
bool _ = true, is3d = true;
f.Load3dMode(is3d, _);
is3d = static_cast<bool>(value);
f.Save3dMode(is3d, _);
f.Allow3dMode(is3d, _);
}
else if (cell == self.autoZoomCell)
{
[Statistics logEvent:kStatEventName(kStatSettings, kStatAutoZoom)
withParameters:@{kStatValue : value ? kStatOn : kStatOff}];
auto & f = GetFramework();
f.AllowAutoZoom(value);
f.SaveAutoZoom(value);
}
else if (cell == self.simplifiedColorsCell)
{
[Statistics logEvent:kStatEventName(kStatSettings, kStatSimplifiedColors)
withParameters:@{kStatValue : value ? kStatOn : kStatOff}];
auto & f = GetFramework();
f.GetTrafficManager().SetSimplifiedColorScheme(value);
f.SaveTrafficSimplifiedColors(value);
}
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
auto cell = static_cast<SettingsTableViewLinkCell *>([tableView cellForRowAtIndexPath:indexPath]);
if (cell == self.profileCell)
{
[Statistics logEvent:kStatSettingsOpenSection withParameters:@{kStatName : kStatAuthorization}];
[self performSegueWithIdentifier:@"SettingsToProfileSegue" sender:nil];
}
else if (cell == self.unitsCell)
{
[Statistics logEvent:kStatEventName(kStatSettings, kStatChangeMeasureUnits)
withParameters:@{kStatAction : kStatChangeMeasureUnits}];
[self performSegueWithIdentifier:@"SettingsToUnits" sender:nil];
}
else if (cell == self.mobileInternetCell)
{
[Statistics logEvent:kStatEventName(kStatSettings, kStatMobileInternet)
withParameters:@{kStatAction : kStatChangeMobileInternet}];
[self performSegueWithIdentifier:@"SettingsToMobileInternetSegue" sender:nil];
}
else if (cell == self.recentTrackCell)
{
[Statistics logEvent:kStatEventName(kStatSettings, kStatRecentTrack)
withParameters:@{kStatAction : kStatChangeRecentTrack}];
[self performSegueWithIdentifier:@"SettingsToRecentTrackSegue" sender:nil];
}
else if (cell == self.nightModeCell)
{
[Statistics logEvent:kStatEventName(kStatSettings, kStatNightMode)
withParameters:@{kStatAction : kStatChangeNightMode}];
[self performSegueWithIdentifier:@"SettingsToNightMode" sender:nil];
}
else if (cell == self.voiceInstructionsCell)
{
[Statistics logEvent:kStatEventName(kStatSettings, kStatTTS)
withParameters:@{kStatAction : kStatChangeLanguage}];
[self performSegueWithIdentifier:@"SettingsToTTSSegue" sender:nil];
}
else if (cell == self.helpCell)
{
[Statistics logEvent:kStatSettingsOpenSection withParameters:@{kStatName : kStatHelp}];
[Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"help"];
[self performSegueWithIdentifier:@"SettingsToHelp" sender:nil];
}
else if (cell == self.aboutCell)
{
[Statistics logEvent:kStatSettingsOpenSection withParameters:@{kStatName : kStatAbout}];
[self performSegueWithIdentifier:@"SettingsToAbout" sender:nil];
}
}
#pragma mark - UITableViewDataSource
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
switch (section)
{
case 1: return L(@"general_settings");
case 2: return L(@"prefs_group_route");
case 3: return L(@"info");
default: return nil;
}
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
switch (section)
{
case 1: return L(@"allow_statistics_hint");
default: return nil;
}
}
@end
|