Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SettingsViewController.mm « Settings « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 04ac2cc9fbe72b5be405f95eda8fc5215ef00d59 (plain)
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

#import "SettingsViewController.h"
#import "SwitchCell.h"
#import "SelectableCell.h"
#import "LinkCell.h"
#import "WebViewController.h"
#import "UIKitCategories.h"
#import "MapViewController.h"
#import "MapsAppDelegate.h"
#import "Framework.h"
#import "Statistics.h"
#import "MWMMapViewControlsManager.h"

#include "platform/settings.hpp"
#include "platform/platform.hpp"
#include "platform/preferred_languages.hpp"

typedef NS_ENUM(NSUInteger, Section)
{
  SectionMetrics,
  SectionZoomButtons,
  SectionCalibration,
  SectionStatistics,
  SectionCount
};

@interface SettingsViewController () <SwitchCellDelegate>

@end

@implementation SettingsViewController

- (void)viewDidLoad
{
  [super viewDidLoad];
  self.title = L(@"settings");
  self.tableView.backgroundView = nil;
  self.tableView.backgroundColor = [UIColor applicationBackgroundColor];
}

- (void)viewWillAppear:(BOOL)animated
{
  [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
  [super viewWillDisappear:animated];
  GetFramework().Invalidate(true);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  return SectionCount;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  if (section == SectionMetrics)
    return 2;
  else
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  UITableViewCell * cell = nil;
  if (indexPath.section == SectionMetrics)
  {
    cell = [tableView dequeueReusableCellWithIdentifier:[SelectableCell className]];
    Settings::Units units = Settings::Metric;
    (void)Settings::Get("Units", units);
    BOOL selected = units == unitsForIndex(indexPath.row);

    SelectableCell * customCell = (SelectableCell *)cell;
    customCell.accessoryType = selected ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
    customCell.titleLabel.text = indexPath.row == 0 ? L(@"kilometres") : L(@"miles");
  }
  else if (indexPath.section == SectionStatistics)
  {
    cell = [tableView dequeueReusableCellWithIdentifier:[SwitchCell className]];
    SwitchCell * customCell = (SwitchCell *)cell;
    bool on = true;
    (void)Settings::Get("StatisticsEnabled", on);
    customCell.switchButton.on = on;
    customCell.titleLabel.text = L(@"allow_statistics");
    customCell.delegate = self;
  }
  else if (indexPath.section == SectionZoomButtons)
  {
    cell = [tableView dequeueReusableCellWithIdentifier:[SwitchCell className]];
    SwitchCell * customCell = (SwitchCell *)cell;
    bool on = true;
    (void)Settings::Get("ZoomButtonsEnabled", on);
    customCell.switchButton.on = on;
    customCell.titleLabel.text = L(@"pref_zoom_title");
    customCell.delegate = self;
  }
  else if (indexPath.section == SectionCalibration)
  {
    cell = [tableView dequeueReusableCellWithIdentifier:[SwitchCell className]];
    SwitchCell * customCell = (SwitchCell *)cell;
    bool on = false;
    (void)Settings::Get("CompassCalibrationEnabled", on);
    customCell.switchButton.on = on;
    customCell.titleLabel.text = L(@"pref_calibration_title");
    customCell.delegate = self;
  }

  return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
  if (section == SectionStatistics)
    return L(@"allow_statistics_hint");
  else if (section == SectionZoomButtons)
    return L(@"pref_zoom_summary");
  return nil;
}

- (void)switchCell:(SwitchCell *)cell didChangeValue:(BOOL)value
{
  NSIndexPath * indexPath = [self.tableView indexPathForCell:cell];
  if (indexPath.section == SectionStatistics)
  {
    [[Statistics instance] logEvent:@"StatisticsStatusChanged" withParameters:@{@"Enabled" : @(value)}];
    Settings::Set("StatisticsEnabled", (bool)value);
  }
  else if (indexPath.section == SectionZoomButtons)
  {
    Settings::Set("ZoomButtonsEnabled", (bool)value);
    [MapsAppDelegate theApp].m_mapViewController.controlsManager.zoomHidden = !value;
  }
  else if (indexPath.section == SectionCalibration)
  {
    Settings::Set("CompassCalibrationEnabled", (bool)value);
  }
}

Settings::Units unitsForIndex(NSInteger index)
{
  return index == 0 ? Settings::Metric : Settings::Foot;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  if (indexPath.section == SectionMetrics)
  {
    Settings::Units units = unitsForIndex(indexPath.row);
    Settings::Set("Units", units);
    [tableView reloadSections:[NSIndexSet indexSetWithIndex:SectionMetrics] withRowAnimation:UITableViewRowAnimationFade];
    [[MapsAppDelegate theApp].m_mapViewController setupMeasurementSystem];
  }
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
  if (section == SectionMetrics)
    return L(@"measurement_units");
  else
    return nil;
}

@end