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

MWMRecentTrackSettingsController.mm « Settings « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5e3b726ec98567f5fb06b88f451ad9ba9bc88fa4 (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
#import "MWMRecentTrackSettingsController.h"
#import "Statistics.h"
#import "SwiftBridge.h"

#include "Framework.h"

#include "map/gps_tracker.hpp"

extern NSString * const kUDTrackWarningAlertWasShown = @"TrackWarningAlertWasShown";

typedef NS_ENUM(NSUInteger, DurationInHours) { One = 1, Two = 2, Six = 6, Twelve = 12, Day = 24 };

@interface MWMRecentTrackSettingsController ()

@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * none;
@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * oneHour;
@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * twoHours;
@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * sixHours;
@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * twelveHours;
@property(weak, nonatomic) IBOutlet SettingsTableViewSelectableCell * oneDay;
@property(weak, nonatomic) SettingsTableViewSelectableCell * selectedCell;

@end

@implementation MWMRecentTrackSettingsController

- (void)viewDidLoad
{
  [super viewDidLoad];
  self.title = L(@"pref_track_record_title");

  if (!GpsTracker::Instance().IsEnabled())
  {
    _selectedCell = self.none;
  }
  else
  {
    switch (GpsTracker::Instance().GetDuration().count())
    {
    case One: _selectedCell = self.oneHour; break;
    case Two: _selectedCell = self.twoHours; break;
    case Six: _selectedCell = self.sixHours; break;
    case Twelve: _selectedCell = self.twelveHours; break;
    case Day: _selectedCell = self.oneDay; break;
    default: NSAssert(false, @"Incorrect hours value"); break;
    }
  }
  self.selectedCell.accessoryType = UITableViewCellAccessoryCheckmark;
}

- (void)setSelectedCell:(SettingsTableViewSelectableCell *)selectedCell
{
  _selectedCell = selectedCell;
  auto & f = GetFramework();
  auto & tracker = GpsTracker::Instance();
  NSString * statValue = nil;
  if ([selectedCell isEqual:self.none])
  {
    f.DisconnectFromGpsTracker();
    tracker.SetEnabled(false);
    statValue = kStatOff;
  }
  else
  {
    if (!tracker.IsEnabled())
    {
      tracker.SetEnabled(true);
      NSUserDefaults * ud = [NSUserDefaults standardUserDefaults];
      [ud setBool:NO forKey:kUDTrackWarningAlertWasShown];
      [ud synchronize];
    }
    f.ConnectToGpsTracker();

    if ([selectedCell isEqual:self.oneHour])
      tracker.SetDuration(hours(One));
    else if ([selectedCell isEqual:self.twoHours])
      tracker.SetDuration(hours(Two));
    else if ([selectedCell isEqual:self.sixHours])
      tracker.SetDuration(hours(Six));
    else if ([selectedCell isEqual:self.twelveHours])
      tracker.SetDuration(hours(Twelve));
    else
      tracker.SetDuration(hours(Day));

    statValue = [NSString stringWithFormat:@"%@ hour(s)", @(tracker.GetDuration().count())];
  }
  selectedCell.accessoryType = UITableViewCellAccessoryCheckmark;
  [Statistics logEvent:kStatChangeRecentTrack withParameters:@{kStatValue : statValue}];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  SettingsTableViewSelectableCell * selectedCell = self.selectedCell;
  selectedCell.accessoryType = UITableViewCellAccessoryNone;
  selectedCell = [tableView cellForRowAtIndexPath:indexPath];
  selectedCell.selected = NO;
  self.selectedCell = selectedCell;
}

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
  NSAssert(section == 0, @"Incorrect sections count");
  return L(@"recent_track_help_text");
}

@end