blob: 8af4b8ec7f8c2698673422120fc1ab0f2ef9c34e (
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
|
#import "Common.h"
#import "MWMAPIBar.h"
#import "MWMAPIBarView.h"
#import "UIKitCategories.h"
#include "Framework.h"
static NSString * const kKeyPath = @"subviews";
@interface MWMAPIBar ()
@property (nonatomic) IBOutlet MWMAPIBarView * rootView;
@property (weak, nonatomic) IBOutlet UIImageView * backArrow;
@property (weak, nonatomic) IBOutlet UILabel * backLabel;
@property (weak, nonatomic) IBOutlet UILabel * timeLabel;
@property (nonatomic) NSDateFormatter * timeFormatter;
@property (nonatomic) NSTimer * timer;
@property (weak, nonatomic) UIViewController * controller;
@end
@implementation MWMAPIBar
- (nullable instancetype)initWithController:(nonnull UIViewController *)controller
{
self = [super init];
if (self)
{
self.controller = controller;
[[NSBundle mainBundle] loadNibNamed:@"MWMAPIBarView" owner:self options:nil];
self.timeFormatter = [[NSDateFormatter alloc] init];
self.timeFormatter.dateStyle = NSDateFormatterNoStyle;
self.timeFormatter.timeStyle = NSDateFormatterShortStyle;
}
return self;
}
- (void)dealloc
{
self.isVisible = NO;
}
- (void)timerUpdate
{
self.timeLabel.text = [self.timeFormatter stringFromDate:[NSDate date]];
}
#pragma mark - Actions
- (IBAction)back
{
auto & f = GetFramework();
auto & bm = f.GetBalloonManager();
bm.RemovePin();
bm.Dismiss();
f.GetBookmarkManager().UserMarksClear(UserMarkContainer::API_MARK);
f.Invalidate();
self.isVisible = NO;
NSURL * url = [NSURL URLWithString:@(f.GetApiDataHolder().GetGlobalBackUrl().c_str())];
[[UIApplication sharedApplication] openURL:url];
}
#pragma mark - Properties
@synthesize isVisible = _isVisible;
- (BOOL)isVisible
{
if (isIOSVersionLessThan(9))
return _isVisible;
return NO;
}
- (void)setIsVisible:(BOOL)isVisible
{
// Status bar in iOS 9 already provides back button if the app has been launched from another app.
// For iOS version less than 9 we just try to mimic the default iOS 9 status bar.
if (!isIOSVersionLessThan(9))
return;
if (_isVisible == isVisible)
return;
_isVisible = isVisible;
if (isVisible)
{
self.backLabel.text =
[NSString stringWithFormat:@"%@%@", L(@"back_to"),
@(GetFramework().GetApiDataHolder().GetAppTitle().c_str())];
[self.controller.view addSubview:self.rootView];
[self.controller.view addObserver:self
forKeyPath:kKeyPath
options:NSKeyValueObservingOptionNew
context:nullptr];
[self timerUpdate];
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(timerUpdate)
userInfo:nil
repeats:YES];
}
else
{
[self.rootView.superview removeObserver:self forKeyPath:kKeyPath];
[self.rootView removeFromSuperview];
[self.timer invalidate];
}
[self.controller setNeedsStatusBarAppearanceUpdate];
}
@end
|