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

MWMActionBarButton.mm « Classes « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7e67a3bf1af3610324cde28573184bc458cd6fef (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
#import "MWMActionBarButton.h"
#import "MWMButton.h"
#import "UIColor+MapsMeColor.h"

NSString * titleForButton(EButton type, BOOL isSelected)
{
  switch (type)
  {
  case EButton::Api:
    return L(@"back");
  case EButton::Booking:
    return L(@"bookingcom_book_button");
  case EButton::Call:
    return L(@"placepage_call_button");
  case EButton::Bookmark:
    return L(isSelected ? @"delete" : @"save");
  case EButton::RouteFrom:
    return L(@"p2p_from_here");
  case EButton::RouteTo:
    return L(@"p2p_to_here");
  case EButton::Share:
    return L(@"share");
  case EButton::More:
    return L(@"placepage_more_button");
  case EButton::Spacer:
    return nil;
  }
}

@interface MWMActionBarButton ()

@property (weak, nonatomic) IBOutlet MWMButton * button;
@property (weak, nonatomic) IBOutlet UILabel * label;

@property (weak, nonatomic) id<MWMActionBarButtonDelegate> delegate;
@property (nonatomic) EButton type;

@end

@implementation MWMActionBarButton

- (void)configButtonWithDelegate:(id<MWMActionBarButtonDelegate>)delegate type:(EButton)type isSelected:(BOOL)isSelected
{
  self.delegate = delegate;
  self.type = type;
  [self configButton:isSelected];
}

- (void)configButton:(BOOL)isSelected
{
  self.label.text = titleForButton(self.type, isSelected);
  switch (self.type)
  {
  case EButton::Api:
    [self.button setImage:[UIImage imageNamed:@"ic_back_api"] forState:UIControlStateNormal];
    break;
  case EButton::Booking:
    [self.button setImage:[UIImage imageNamed:@"ic_booking_logo"] forState:UIControlStateNormal];
    self.label.textColor = [UIColor whiteColor];
    self.backgroundColor = [UIColor bookingBackground];
    break;
  case EButton::Call:
    [self.button setImage:[UIImage imageNamed:@"ic_placepage_phone_number"] forState:UIControlStateNormal];
    break;
  case EButton::Bookmark:
    [self setupBookmarkButton:isSelected];
    break;
  case EButton::RouteFrom:
    [self.button setImage:[UIImage imageNamed:@"ic_route_from"] forState:UIControlStateNormal];
    break;
  case EButton::RouteTo:
    [self.button setImage:[UIImage imageNamed:@"ic_route_to"] forState:UIControlStateNormal];
    break;
  case EButton::Share:
    [self.button setImage:[UIImage imageNamed:@"ic_menu_share"] forState:UIControlStateNormal];
    break;
  case EButton::More:
    [self.button setImage:[UIImage imageNamed:@"ic_placepage_more"] forState:UIControlStateNormal];
    break;
  case EButton::Spacer:
    [self.button removeFromSuperview];
    [self.label removeFromSuperview];
    break;
  }
}

+ (void)addButtonToSuperview:(UIView *)view
                    delegate:(id<MWMActionBarButtonDelegate>)delegate
                  buttonType:(EButton)type
                  isSelected:(BOOL)isSelected
{
  if (view.subviews.count)
    return;
  MWMActionBarButton * button = [[[NSBundle mainBundle] loadNibNamed:[MWMActionBarButton className] owner:nil options:nil] firstObject];
  button.delegate = delegate;
  button.type = type;
  [view addSubview:button];
  button.autoresizingMask = UIViewAutoresizingNone;
  [button configButton:isSelected];
}

- (IBAction)tap
{
  if (self.type == EButton::Bookmark)
    [self setBookmarkSelected:!self.button.isSelected];

  [self.delegate tapOnButtonWithType:self.type];
}

- (void)setBookmarkSelected:(BOOL)isSelected
{
  if (isSelected)
    [self.button.imageView startAnimating];

  self.button.selected = isSelected;
  self.label.text = L(isSelected ? @"delete" : @"save");
}

- (void)setupBookmarkButton:(BOOL)isSelected
{
  MWMButton * btn = self.button;
  [btn setImage:[UIImage imageNamed:@"ic_bookmarks_off"] forState:UIControlStateNormal];
  [btn setImage:[UIImage imageNamed:@"ic_bookmarks_on"] forState:UIControlStateSelected];
  [btn setImage:[UIImage imageNamed:@"ic_bookmarks_on"] forState:UIControlStateHighlighted];

  [self setBookmarkSelected:isSelected];

  NSUInteger const animationImagesCount = 11;
  NSMutableArray * animationImages = [NSMutableArray arrayWithCapacity:animationImagesCount];
  for (NSUInteger i = 0; i < animationImagesCount; ++i)
    animationImages[i] = [UIImage imageNamed:[NSString stringWithFormat:@"ic_bookmarks_%@", @(i+1)]];

  UIImageView * animationIV = btn.imageView;
  animationIV.animationImages = animationImages;
  animationIV.animationRepeatCount = 1;
}

- (void)layoutSubviews
{
  self.frame = self.superview.bounds;
  [super layoutSubviews];
}

@end