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

MWMSideMenuManager.mm « SideMenu « MapViewControls « CustomViews « Classes « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2c2c4b2f8ba756f1a8d94d46412ec984773b3fb9 (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
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
//
//  MWMSideMenuManager.m
//  Maps
//
//  Created by Ilya Grechuhin on 24.04.15.
//  Copyright (c) 2015 MapsWithMe. All rights reserved.
//

#import "BookmarksRootVC.h"
#import "CountryTreeVC.h"
#import "Framework.h"
#import "LocationManager.h"
#import "MapsAppDelegate.h"
#import "MapViewController.h"
#import "MWMMapViewControlsCommon.h"
#import "MWMMapViewControlsManager.h"
#import "MWMSideMenuButton.h"
#import "MWMSideMenuButtonDelegate.h"
#import "MWMSideMenuDelegate.h"
#import "MWMSideMenuManager.h"
#import "MWMSideMenuView.h"
#import "SettingsAndMoreVC.h"
#import "ShareActionSheet.h"

#import "3party/Alohalytics/src/alohalytics_objc.h"

#include "map/information_display.hpp"

static NSString * const kMWMSideMenuViewsNibName = @"MWMSideMenuViews";

extern NSString * const kAlohalyticsTapEventKey;

@interface MWMSideMenuManager() <MWMSideMenuInformationDisplayProtocol, MWMSideMenuTapProtocol>

@property (weak, nonatomic) MapViewController * controller;
@property (nonatomic) IBOutlet MWMSideMenuButton * menuButton;
@property (nonatomic) IBOutlet MWMSideMenuView * sideMenu;

@end

@implementation MWMSideMenuManager

- (instancetype)initWithParentController:(MapViewController *)controller
{
  self = [super init];
  if (self)
  {
    self.controller = controller;
    [[NSBundle mainBundle] loadNibNamed:kMWMSideMenuViewsNibName owner:self options:nil];
    [self.controller.view addSubview:self.menuButton];
    [self.menuButton setup];
    self.menuButton.delegate = self;
    self.sideMenu.delegate = self;
    [self addCloseMenuWithTap];
    self.state = MWMSideMenuStateInactive;
  }
  return self;
}

- (void)addCloseMenuWithTap
{
  UITapGestureRecognizer * const tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleMenu)];
  [self.sideMenu.dimBackground addGestureRecognizer:tap];
}

#pragma mark - Actions

- (IBAction)menuActionOpenBookmarks
{
  self.state = MWMSideMenuStateInactive;
  [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"bookmarks"];
  BookmarksRootVC * const vc = [[BookmarksRootVC alloc] init];
  [self.controller.navigationController pushViewController:vc animated:YES];
}

- (IBAction)menuActionDownloadMaps
{
  self.state = MWMSideMenuStateInactive;
  [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"downloader"];
  CountryTreeVC * const vc = [[CountryTreeVC alloc] initWithNodePosition:-1];
  [self.controller.navigationController pushViewController:vc animated:YES];
}

- (IBAction)menuActionOpenSettings
{
  self.state = MWMSideMenuStateInactive;
  [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"settingsAndMore"];
  SettingsAndMoreVC * const vc = [[SettingsAndMoreVC alloc] initWithStyle:UITableViewStyleGrouped];
  [self.controller.navigationController pushViewController:vc animated:YES];
}

- (IBAction)menuActionShareLocation
{
  self.state = MWMSideMenuStateInactive;
  [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"share@"];
  CLLocation const * const location = [MapsAppDelegate theApp].m_locationManager.lastLocation;
  if (!location)
  {
    [[[UIAlertView alloc] initWithTitle:L(@"unknown_current_position") message:nil delegate:nil cancelButtonTitle:L(@"ok") otherButtonTitles:nil] show];
    return;
  }
  CLLocationCoordinate2D const coord = location.coordinate;
  ShareInfo * const info = [[ShareInfo alloc] initWithText:nil lat:coord.latitude lon:coord.longitude myPosition:YES];
  self.controller.shareActionSheet = [[ShareActionSheet alloc] initWithInfo:info viewController:self.controller];
  UIView const * const parentView = self.controller.view;
  [self.controller.shareActionSheet showFromRect:CGRectMake(parentView.midX, parentView.height - 40.0, 0.0, 0.0)];
}

- (IBAction)menuActionOpenSearch
{
  self.controller.controlsManager.hidden = YES;
  [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"search"];
  [self.controller.searchView setState:SearchViewStateFullscreen animated:YES];
}

- (void)toggleMenu
{
  if (self.state == MWMSideMenuStateActive)
    self.state = MWMSideMenuStateInactive;
  else if (self.state == MWMSideMenuStateInactive)
    self.state = MWMSideMenuStateActive;
}

- (void)handleSingleTap
{
  [self toggleMenu];
}

- (void)handleDoubleTap
{
  [self menuActionOpenSearch];
}

#pragma mark - MWMSideMenuInformationDisplayProtocol

- (void)setRulerPivot:(m2::PointD)pivot
{
  // Workaround for old ios when layoutSubviews are called in undefined order.
  dispatch_async(dispatch_get_main_queue(), ^
  {
    GetFramework().GetInformationDisplay().SetWidgetPivot(InformationDisplay::WidgetType::Ruler, pivot);
  });
}

- (void)setCopyrightLabelPivot:(m2::PointD)pivot
{
  // Workaround for old ios when layoutSubviews are called in undefined order.
  dispatch_async(dispatch_get_main_queue(), ^
  {
    GetFramework().GetInformationDisplay().SetWidgetPivot(InformationDisplay::WidgetType::CopyrightLabel, pivot);
  });
}

- (void)showMenu
{
  self.menuButton.alpha = 1.0;
  self.sideMenu.alpha = 0.0;
  [self.controller.view addSubview:self.sideMenu];
  [UIView animateWithDuration:framesDuration(3) animations:^
  {
    self.menuButton.alpha = 0.0;
    self.sideMenu.alpha = 1.0;
  }
  completion:^(BOOL finished)
  {
    [self.menuButton setHidden:YES animated:NO];
  }];
}

- (void)hideMenu
{
  [UIView animateWithDuration:framesDuration(3) animations:^
  {
    self.menuButton.alpha = 1.0;
    self.sideMenu.alpha = 0.0;
  }
  completion:^(BOOL finished)
  {
    [self.sideMenu removeFromSuperview];
  }];
}

#pragma mark - Properties

- (void)setState:(MWMSideMenuState)state
{
  if (_state == state)
    return;
  switch (state)
  {
    case MWMSideMenuStateActive:
      [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"menu"];
      self.sideMenu.outOfDateCount = GetFramework().GetCountryTree().GetActiveMapLayout().GetOutOfDateCount();
      [self showMenu];
      [self.sideMenu setup];
      break;
    case MWMSideMenuStateInactive:
      if (_state == MWMSideMenuStateActive)
      {
        [self.menuButton setHidden:NO animated:NO];
        [self hideMenu];
      }
      else
      {
        [self.menuButton setHidden:NO animated:YES];
      }
      break;
    case MWMSideMenuStateHidden:
      [self.menuButton setHidden:YES animated:YES];
      [self hideMenu];
      break;
  }
  _state = state;
  [self.controller updateStatusBarStyle];
}

@end