blob: d0770476c1301812a9dd88704240cf47c10a9221 (
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
#import "MWMPlacePageActionBar.h"
#import "AppInfo.h"
#import "MWMActionBarButton.h"
#import "MWMCommon.h"
#import "MWMPlacePageProtocol.h"
#import "MWMRouter.h"
#import "MapViewController.h"
#import "MapsAppDelegate.h"
#include "Framework.h"
#include "std/vector.hpp"
extern NSString * const kAlohalyticsTapEventKey;
@interface MWMPlacePageActionBar ()<MWMActionBarButtonDelegate>
{
vector<EButton> m_visibleButtons;
vector<EButton> m_additionalButtons;
}
@property(copy, nonatomic) IBOutletCollection(UIView) NSArray<UIView *> * buttons;
@property(weak, nonatomic) IBOutlet UIImageView * separator;
@property(weak, nonatomic) id<MWMActionBarSharedData> data;
@property(weak, nonatomic) id<MWMActionBarProtocol> delegate;
@end
@implementation MWMPlacePageActionBar
+ (MWMPlacePageActionBar *)actionBarWithDelegate:(id<MWMActionBarProtocol>)delegate
{
MWMPlacePageActionBar * bar =
[[NSBundle.mainBundle loadNibNamed:[self className] owner:nil options:nil] firstObject];
bar.delegate = delegate;
return bar;
}
- (void)configureWithData:(id<MWMActionBarSharedData>)data
{
self.data = data;
self.isBookmark = data.isBookmark;
[self configureButtons];
self.autoresizingMask = UIViewAutoresizingNone;
[self setNeedsLayout];
}
- (void)configureButtons
{
m_visibleButtons.clear();
m_additionalButtons.clear();
auto data = self.data;
BOOL const isBooking = data.isBooking;
BOOL const isOpentable = data.isOpentable;
BOOL const isBookingSearch = data.isBookingSearch;
BOOL const isSponsored = isBooking || isOpentable || isBookingSearch;
BOOL const isPhoneCallAvailable =
[AppInfo sharedInfo].canMakeCalls && data.phoneNumber.length > 0;
BOOL const isApi = data.isApi;
auto const navigationState = [MWMNavigationDashboardManager manager].state;
BOOL const isNavigationActive = navigationState == MWMNavigationDashboardStateNavigation;
BOOL const isP2P = !isNavigationActive && navigationState != MWMNavigationDashboardStateHidden;
BOOL const isMyPosition = data.isMyPosition;
BOOL const isRoutePoint = data.isRoutePoint;
BOOL const isNeedToAddIntermediatePoint = [MWMRouter canAddIntermediatePoint];
EButton sponsoredButton = EButton::BookingSearch;
if (isBooking)
sponsoredButton = EButton::Booking;
else if (isOpentable)
sponsoredButton = EButton::Opentable;
BOOL thereAreExtraButtons = true;
if (isRoutePoint)
{
thereAreExtraButtons = false;
m_visibleButtons.push_back(EButton::RemoveStop);
}
else if (isNeedToAddIntermediatePoint)
{
thereAreExtraButtons = false;
if (!isNavigationActive)
{
m_visibleButtons.push_back(EButton::RouteFrom);
m_additionalButtons.push_back(EButton::Bookmark);
}
else
{
m_visibleButtons.push_back(EButton::Bookmark);
}
m_visibleButtons.push_back(EButton::RouteTo);
m_visibleButtons.push_back(EButton::AddStop);
m_visibleButtons.push_back(EButton::More);
if (isSponsored)
m_additionalButtons.push_back(sponsoredButton);
if (isPhoneCallAvailable)
m_additionalButtons.push_back(EButton::Call);
if (isApi)
m_additionalButtons.push_back(EButton::Api);
m_additionalButtons.push_back(EButton::Share);
}
else if (self.isAreaNotDownloaded)
{
thereAreExtraButtons = false;
m_visibleButtons.push_back(EButton::Download);
m_visibleButtons.push_back(EButton::Bookmark);
m_visibleButtons.push_back(EButton::RouteTo);
m_visibleButtons.push_back(EButton::Share);
}
else if (isMyPosition && isP2P)
{
thereAreExtraButtons = false;
m_visibleButtons.push_back(EButton::Bookmark);
m_visibleButtons.push_back(EButton::RouteFrom);
m_visibleButtons.push_back(EButton::RouteTo);
m_visibleButtons.push_back(EButton::More);
m_additionalButtons.push_back(EButton::Share);
}
else if (isMyPosition)
{
thereAreExtraButtons = false;
m_visibleButtons.push_back(EButton::Bookmark);
if (!isNavigationActive)
m_visibleButtons.push_back(EButton::RouteFrom);
m_visibleButtons.push_back(EButton::Share);
}
else if (isApi && isSponsored)
{
m_visibleButtons.push_back(EButton::Api);
m_visibleButtons.push_back(sponsoredButton);
m_additionalButtons.push_back(EButton::Bookmark);
if (!isNavigationActive)
m_additionalButtons.push_back(EButton::RouteFrom);
m_additionalButtons.push_back(EButton::Share);
}
else if (isApi && isPhoneCallAvailable)
{
m_visibleButtons.push_back(EButton::Api);
m_visibleButtons.push_back(EButton::Call);
m_additionalButtons.push_back(EButton::Bookmark);
if (!isNavigationActive)
m_additionalButtons.push_back(EButton::RouteFrom);
m_additionalButtons.push_back(EButton::Share);
}
else if (isApi && isP2P)
{
m_visibleButtons.push_back(EButton::Api);
if (!isNavigationActive)
m_visibleButtons.push_back(EButton::RouteFrom);
m_additionalButtons.push_back(EButton::Bookmark);
m_additionalButtons.push_back(EButton::Share);
}
else if (isApi)
{
m_visibleButtons.push_back(EButton::Api);
m_visibleButtons.push_back(EButton::Bookmark);
if (!isNavigationActive)
m_additionalButtons.push_back(EButton::RouteFrom);
m_additionalButtons.push_back(EButton::Share);
}
else if (isSponsored && isP2P)
{
m_visibleButtons.push_back(EButton::Bookmark);
if (!isNavigationActive)
m_visibleButtons.push_back(EButton::RouteFrom);
m_additionalButtons.push_back(sponsoredButton);
m_additionalButtons.push_back(EButton::Share);
}
else if (isPhoneCallAvailable && isP2P)
{
m_visibleButtons.push_back(EButton::Bookmark);
if (!isNavigationActive)
m_visibleButtons.push_back(EButton::RouteFrom);
m_additionalButtons.push_back(EButton::Call);
m_additionalButtons.push_back(EButton::Share);
}
else if (isSponsored)
{
m_visibleButtons.push_back(sponsoredButton);
m_visibleButtons.push_back(EButton::Bookmark);
if (!isNavigationActive)
m_additionalButtons.push_back(EButton::RouteFrom);
m_additionalButtons.push_back(EButton::Share);
}
else if (isPhoneCallAvailable)
{
m_visibleButtons.push_back(EButton::Call);
m_visibleButtons.push_back(EButton::Bookmark);
if (!isNavigationActive)
m_additionalButtons.push_back(EButton::RouteFrom);
m_additionalButtons.push_back(EButton::Share);
}
else
{
m_visibleButtons.push_back(EButton::Bookmark);
if (!isNavigationActive)
m_visibleButtons.push_back(EButton::RouteFrom);
}
if (thereAreExtraButtons)
{
m_visibleButtons.push_back(EButton::RouteTo);
m_visibleButtons.push_back(m_additionalButtons.empty() ? EButton::Share : EButton::More);
}
for (UIView * v in self.buttons)
{
[v.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
auto const buttonIndex = v.tag - 1;
NSAssert(buttonIndex >= 0, @"Invalid button index.");
if (buttonIndex < 0 || buttonIndex >= m_visibleButtons.size())
continue;
auto const type = m_visibleButtons[buttonIndex];
[MWMActionBarButton addButtonToSuperview:v
delegate:self
buttonType:type
isSelected:type == EButton::Bookmark ? self.isBookmark : NO];
}
}
- (void)setDownloadingState:(MWMCircularProgressState)state
{
self.progressFromActiveButton.state = state;
}
- (void)setDownloadingProgress:(CGFloat)progress
{
self.progressFromActiveButton.progress = progress;
}
- (MWMCircularProgress *)progressFromActiveButton
{
if (!self.isAreaNotDownloaded)
return nil;
for (UIView * view in self.buttons)
{
MWMActionBarButton * button = view.subviews.firstObject;
NSAssert(button, @"Subviews can't be empty!");
if (!button || button.type != EButton::Download)
continue;
return button.mapDownloadProgress;
}
return nil;
}
- (void)setIsAreaNotDownloaded:(BOOL)isAreaNotDownloaded
{
if (_isAreaNotDownloaded == isAreaNotDownloaded)
return;
_isAreaNotDownloaded = isAreaNotDownloaded;
[self configureButtons];
}
- (UIView *)shareAnchor
{
UIView * last = nil;
auto const size = self.buttons.count;
for (UIView * v in self.buttons)
{
if (v.tag == size)
last = v;
}
return last;
}
#pragma mark - MWMActionBarButtonDelegate
- (void)tapOnButtonWithType:(EButton)type
{
id<MWMActionBarProtocol> delegate = self.delegate;
switch (type)
{
case EButton::Api: [delegate apiBack]; break;
case EButton::Download: [delegate downloadSelectedArea]; break;
case EButton::Opentable:
case EButton::Booking: [delegate book:NO]; break;
case EButton::BookingSearch: [delegate searchBookingHotels]; break;
case EButton::Call: [delegate call]; break;
case EButton::Bookmark:
if (self.isBookmark)
[delegate removeBookmark];
else
[delegate addBookmark];
self.isBookmark = !self.isBookmark;
break;
case EButton::RouteFrom: [delegate routeFrom]; break;
case EButton::RouteTo: [delegate routeTo]; break;
case EButton::Share: [delegate share]; break;
case EButton::More: [self showActionSheet]; break;
case EButton::AddStop: [delegate addStop]; break;
case EButton::RemoveStop: [delegate removeStop]; break;
case EButton::Spacer: break;
}
}
#pragma mark - ActionSheet
- (void)showActionSheet
{
NSString * cancel = L(@"cancel");
auto data = self.data;
BOOL const isTitleNotEmpty = data.title.length > 0;
NSString * title = isTitleNotEmpty ? data.title : data.subtitle;
NSString * subtitle = isTitleNotEmpty ? data.subtitle : nil;
UIViewController * vc = static_cast<UIViewController *>([MapViewController controller]);
NSMutableArray<NSString *> * titles = [@[] mutableCopy];
for (auto const buttonType : m_additionalButtons)
{
BOOL const isSelected = buttonType == EButton::Bookmark ? data.isBookmark : NO;
if (NSString * title = titleForButton(buttonType, isSelected))
[titles addObject:title];
else
NSAssert(false, @"Title can't be nil!");
}
UIAlertController * alertController =
[UIAlertController alertControllerWithTitle:title
message:subtitle
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction * cancelAction =
[UIAlertAction actionWithTitle:cancel style:UIAlertActionStyleCancel handler:nil];
for (auto i = 0; i < titles.count; i++)
{
UIAlertAction * commonAction =
[UIAlertAction actionWithTitle:titles[i]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[self tapOnButtonWithType:self->m_additionalButtons[i]];
}];
[alertController addAction:commonAction];
}
[alertController addAction:cancelAction];
if (IPAD)
{
UIPopoverPresentationController * popPresenter =
[alertController popoverPresentationController];
popPresenter.sourceView = self.shareAnchor;
popPresenter.sourceRect = self.shareAnchor.bounds;
}
[vc presentViewController:alertController animated:YES completion:nil];
}
#pragma mark - Layout
- (void)layoutSubviews
{
[super layoutSubviews];
self.width = self.superview.width;
if (IPAD)
self.maxY = self.superview.height;
self.separator.width = self.width;
CGFloat const buttonWidth = self.width / m_visibleButtons.size();
for (UIView * button in self.buttons)
{
button.minX = buttonWidth * (button.tag - 1);
button.width = buttonWidth;
}
}
@end
|