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

MWMNightModeController.mm « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 54503066760ba00d5b269b5dc4219837c663dc93 (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
#import "MapsAppDelegate.h"
#import "MWMNightModeController.h"
#import "SelectableCell.h"
#import "Statistics.h"
#import "UIColor+MapsMeColor.h"

#include "Framework.h"

@interface MWMNightModeController ()

@property (weak, nonatomic) IBOutlet SelectableCell * autoSwitch;
@property (weak, nonatomic) IBOutlet SelectableCell * on;
@property (weak, nonatomic) IBOutlet SelectableCell * off;
@property (weak, nonatomic) SelectableCell * selectedCell;

@end

@implementation MWMNightModeController

- (void)viewDidLoad
{
  [super viewDidLoad];
  self.title = L(@"pref_map_style_title");
  if ([MapsAppDelegate isAutoNightMode])
  {
    self.autoSwitch.accessoryType = UITableViewCellAccessoryCheckmark;
    _selectedCell = self.autoSwitch;
    return;
  }

  switch (GetFramework().GetMapStyle())
  {
  case MapStyleDark:
    self.on.accessoryType = UITableViewCellAccessoryCheckmark;
    _selectedCell = self.on;
    break;
  case MapStyleClear:
  case MapStyleLight:
    self.off.accessoryType = UITableViewCellAccessoryCheckmark;
    _selectedCell = self.off;
    break;
  case MapStyleMerged:
  case MapStyleCount:
    break;
  }
}

- (void)setSelectedCell:(SelectableCell *)cell
{
  if ([_selectedCell isEqual:cell])
    return;

  _selectedCell = cell;
  auto & f = GetFramework();
  auto const style = f.GetMapStyle();
  NSString * statValue = nil;
  if ([cell isEqual:self.on])
  {
    [MapsAppDelegate setAutoNightModeOff:YES];
    if (style == MapStyleDark)
      return;
    f.SetMapStyle(MapStyleDark);
    [UIColor setNightMode:YES];
    [self mwm_refreshUI];
    statValue = kStatOn;
  }
  else if ([cell isEqual:self.off])
  {
    [MapsAppDelegate setAutoNightModeOff:YES];
    if (style == MapStyleClear || style == MapStyleLight)
      return;
    f.SetMapStyle(MapStyleClear);
    [UIColor setNightMode:NO];
    [self mwm_refreshUI];
    statValue = kStatOff;
  }
  else if ([cell isEqual:self.autoSwitch])
  {
    [MapsAppDelegate setAutoNightModeOff:NO];
    [MapsAppDelegate changeMapStyleIfNedeed];
    if (style == MapStyleClear || style == MapStyleLight)
      return;
    [UIColor setNightMode:NO];
    f.SetMapStyle(MapStyleClear);
    [self mwm_refreshUI];
    statValue = kStatValue;
  }

  [Statistics logEvent:kStatNightMode
                   withParameters:@{kStatValue : statValue}];
}

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

@end