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

MWMAPIBar.mm « APIBar « MapViewControls « CustomViews « Classes « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ecbd6f6ab2f3146740d560a2819dffb493a4f9ff (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
#import "MWMCommon.h"
#import "MWMAPIBar.h"
#import "MWMAPIBarView.h"
#import "Statistics.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
{
  [Statistics logEvent:kStatEventName(kStatAPI, kStatBack)];
  Framework & f = GetFramework();
  f.DeactivateMapSelection(true);
  UserMarkNotifyGuard guard(f.GetBookmarkManager(), UserMarkType::API_MARK);
  guard.m_controller.Clear();
  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 (isIOS8)
    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 (!isIOS8)
    return;
  if (_isVisible == isVisible)
    return;
  _isVisible = isVisible;
  UIViewController * controller = self.controller;
  if (isVisible)
  {
    self.backLabel.text = [NSString
        stringWithFormat:L(@"back_to"), @(GetFramework().GetApiDataHolder().GetAppTitle().c_str())];
    [controller.view addSubview:self.rootView];
    [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
  {
    [controller.view removeObserver:self forKeyPath:kKeyPath];
    [self.rootView removeFromSuperview];
    [self.timer invalidate];
  }
  [controller setNeedsStatusBarAppearanceUpdate];
}

@end