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

MWMPlacePage.mm « Classes « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 92ace94e31b55f44fdfb5c02a6db3b8fb1af98c1 (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
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
#import "MapsAppDelegate.h"
#import "MapViewController.h"
#import "MWMBasePlacePageView.h"
#import "MWMBookmarkColorViewController.h"
#import "MWMBookmarkDescriptionViewController.h"
#import "MWMDirectionView.h"
#import "MWMPlacePage.h"
#import "MWMPlacePageActionBar.h"
#import "MWMPlacePageEntity.h"
#import "MWMPlacePageViewManager.h"
#import "SelectSetVC.h"
#import "Statistics.h"

static NSString * const kPlacePageNibIdentifier = @"PlacePageView";
static NSString * const kPlacePageViewCenterKeyPath = @"center";

@interface MWMPlacePage ()

@property (weak, nonatomic, readwrite) MWMPlacePageViewManager * manager;

@end

@implementation MWMPlacePage

- (instancetype)initWithManager:(MWMPlacePageViewManager *)manager
{
  self = [super init];
  if (self)
  {
    [[NSBundle mainBundle] loadNibNamed:kPlacePageNibIdentifier owner:self options:nil];
    self.manager = manager;
    if (!IPAD)
    {
      [self.extendedPlacePageView addObserver:self
                                   forKeyPath:kPlacePageViewCenterKeyPath
                                      options:NSKeyValueObservingOptionNew
                                      context:nullptr];
    }
    dispatch_async(dispatch_get_main_queue(), ^
    {
      [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(keyboardWillShow:)
                                                   name:UIKeyboardWillShowNotification
                                                 object:nil];

      [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(keyboardWillHide)
                                                   name:UIKeyboardWillHideNotification
                                                 object:nil];
    });
  }
  return self;
}

- (void)dealloc
{
  if (!IPAD)
  {
    [self.extendedPlacePageView removeObserver:self forKeyPath:kPlacePageViewCenterKeyPath];
  }
  [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)keyboardWillShow:(NSNotification *)aNotification
{
  NSDictionary * info = [aNotification userInfo];
  self.keyboardHeight = [info[UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
}

- (void)keyboardWillHide
{
  self.keyboardHeight = 0.0;
}

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context
{
  if ([self.extendedPlacePageView isEqual:object] &&
      [keyPath isEqualToString:kPlacePageViewCenterKeyPath])
    [self.manager dragPlacePage:self.extendedPlacePageView.frame];
}

- (void)configure
{
  MWMPlacePageEntity * entity = self.manager.entity;
  [self.basePlacePageView configureWithEntity:entity];
  BOOL const isPrepareRouteMode = MapsAppDelegate.theApp.routingPlaneMode != MWMRoutingPlaneModeNone;
  if (self.actionBar.isPrepareRouteMode == isPrepareRouteMode)
  {
    [self.actionBar configureWithPlacePage:self];
  }
  else
  {
    [self.actionBar removeFromSuperview];
    self.actionBar = [MWMPlacePageActionBar actionBarForPlacePage:self];
  }
}

- (void)show
{
  // Should override this method if you want to show place page with custom animation.
}

- (void)hide
{
  // Should override this method if you want to hide place page with custom animation.
}

- (void)dismiss
{
  [self.extendedPlacePageView removeFromSuperview];
  [self.actionBar removeFromSuperview];
  self.actionBar = nil;
}

#pragma mark - Actions
- (void)apiBack
{
  [self.manager apiBack];
}

- (void)addBookmark
{
  [self.basePlacePageView addBookmark];
  [self.manager addBookmark];
}

- (void)removeBookmark
{
  [self.basePlacePageView removeBookmark];
  [self.manager removeBookmark];
}

- (void)editPlace
{
  [self.manager editPlace];
}

- (void)share
{
  [self.manager share];
}

- (void)route
{
  [self.manager buildRoute];
}

- (void)addPlacePageShadowToView:(UIView *)view offset:(CGSize)offset
{
  CALayer * layer = view.layer;
  layer.masksToBounds = NO;
  layer.shadowColor = UIColor.blackColor.CGColor;
  layer.shadowRadius = 4.;
  layer.shadowOpacity = 0.24f;
  layer.shadowOffset = offset;
  layer.shouldRasterize = YES;
  layer.rasterizationScale = [[UIScreen mainScreen] scale];
}

- (void)setDirectionArrowTransform:(CGAffineTransform)transform
{
  self.basePlacePageView.directionArrow.transform = transform;
}

- (void)setDistance:(NSString *)distance
{
  self.basePlacePageView.distanceLabel.text = distance;
}

- (void)updateMyPositionStatus:(NSString *)status
{
  [self.basePlacePageView updateAndLayoutMyPositionSpeedAndAltitude:status];
}

- (void)changeBookmarkCategory
{
  MWMPlacePageViewManager * manager = self.manager;
  MapViewController * ovc = static_cast<MapViewController *>(manager.ownerViewController);
  ovc.skipPlacePageDismissOnViewDisappear = YES;
  SelectSetVC * vc = [[SelectSetVC alloc] initWithPlacePageManager:manager];
  [ovc.navigationController pushViewController:vc animated:YES];
}

- (void)changeBookmarkColor
{
  MWMBookmarkColorViewController * controller = [[MWMBookmarkColorViewController alloc] initWithNibName:[MWMBookmarkColorViewController className] bundle:nil];
  controller.placePageManager = self.manager;
  [self.manager.ownerViewController.navigationController pushViewController:controller animated:YES];
}

- (void)changeBookmarkDescription
{
  MWMPlacePageViewManager * manager = self.manager;
  MapViewController * ovc = static_cast<MapViewController *>(manager.ownerViewController);
  ovc.skipPlacePageDismissOnViewDisappear = YES;
  MWMBookmarkDescriptionViewController * viewController = [[MWMBookmarkDescriptionViewController alloc] initWithPlacePageManager:manager];
  [ovc.navigationController pushViewController:viewController animated:YES];
}

- (void)reloadBookmark
{
  [self.basePlacePageView reloadBookmarkCell];
}

- (void)willStartEditingBookmarkTitle
{
  [[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatRename)];
// This method should be оverridden.
}

- (void)willFinishEditingBookmarkTitle:(NSString *)title
{
  self.basePlacePageView.titleLabel.text = title;
  [self.basePlacePageView layoutIfNeeded];
}

- (IBAction)didTap:(UITapGestureRecognizer *)sender
{
// This method should be оverridden if you want to process custom tap.
}

- (IBAction)didPan:(UIPanGestureRecognizer *)sender
{
  // This method should be оverridden if you want to process custom pan.
}

- (void)refresh
{
  // This method should be оverridden.
}

#pragma mark - Properties

- (MWMPlacePageActionBar *)actionBar
{
  if (!_actionBar)
    _actionBar = [MWMPlacePageActionBar actionBarForPlacePage:self];
  return _actionBar;
}

@end