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

MWMPlacePageInfoCell.mm « Classes « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1edbd5aa79527fb03055c5f28900dea0cf1188ba (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
#import "MWMPlacePageInfoCell.h"
#import "Common.h"
#import "MapViewController.h"
#import "MapsAppDelegate.h"
#import "Statistics.h"
#import "UIColor+MapsMeColor.h"
#import "UIFont+MapsMeFonts.h"
#import "UIImageView+Coloring.h"

#include "platform/measurement_utils.hpp"
#include "platform/settings.hpp"

@interface MWMPlacePageInfoCell ()<UITextViewDelegate>

@property(weak, nonatomic, readwrite) IBOutlet UIImageView * icon;
@property(weak, nonatomic, readwrite) IBOutlet id textContainer;
@property(weak, nonatomic) IBOutlet NSLayoutConstraint * textContainerHeight;

@property(weak, nonatomic) IBOutlet UIButton * upperButton;
@property(weak, nonatomic) IBOutlet UIImageView * toggleImage;

@property(nonatomic) MWMPlacePageCellType type;

@end

@implementation MWMPlacePageInfoCell

- (void)awakeFromNib
{
  [super awakeFromNib];
  if ([self.textContainer isKindOfClass:[UITextView class]])
  {
    UITextView * textView = (UITextView *)self.textContainer;
    [textView setTextContainerInset:{.top = 12}];
    textView.keyboardAppearance =
        [UIColor isNightMode] ? UIKeyboardAppearanceDark : UIKeyboardAppearanceDefault;
  }
}

- (void)configureWithType:(MWMPlacePageCellType)type info:(NSString *)info;
{
  NSString * typeName;
  switch (type)
  {
  case MWMPlacePageCellTypeURL:
  case MWMPlacePageCellTypeWebsite:
    self.toggleImage.hidden = YES;
    typeName = @"website";
    break;
  case MWMPlacePageCellTypeEmail:
    self.toggleImage.hidden = YES;
    typeName = @"email";
    break;
  case MWMPlacePageCellTypePhoneNumber:
    self.toggleImage.hidden = YES;
    typeName = @"phone_number";
    break;
  case MWMPlacePageCellTypeCoordinate:
    self.toggleImage.hidden = NO;
    typeName = @"coordinate";
    break;
  case MWMPlacePageCellTypePostcode:
    self.toggleImage.hidden = YES;
    typeName = @"postcode";
    break;
  case MWMPlacePageCellTypeWiFi:
    self.toggleImage.hidden = YES;
    typeName = @"wifi";
    break;
  default: NSAssert(false, @"Incorrect type!"); break;
  }

  UIImage * image =
      [UIImage imageNamed:[NSString stringWithFormat:@"%@%@", @"ic_placepage_", typeName]];
  self.type = type;
  self.icon.image = image;
  self.icon.mwm_coloring = [self.textContainer isKindOfClass:[UITextView class]]
                               ? MWMImageColoringBlue
                               : MWMImageColoringBlack;
  [self changeText:info];
  UILongPressGestureRecognizer * longTap =
      [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTap:)];
  longTap.minimumPressDuration = 0.3;
  [self.upperButton addGestureRecognizer:longTap];
}

- (void)changeText:(NSString *)text
{
  if ([self.textContainer isKindOfClass:[UITextView class]])
  {
    UITextView * tv = (UITextView *)self.textContainer;
    [tv setAttributedText:[[NSAttributedString alloc]
                              initWithString:text
                                  attributes:@{NSFontAttributeName : [UIFont regular16]}]];
    [tv sizeToIntegralFit];
    CGFloat const minTextContainerHeight = 42.0;
    CGFloat const bottomOffset = 8.0;
    self.textContainerHeight.constant =
        MAX(ceil(tv.contentSize.height) + bottomOffset, minTextContainerHeight);
  }
  else
  {
    UILabel * lb = (UILabel *)self.textContainer;
    [lb setText:text];
    [lb sizeToIntegralFit];
    CGFloat const trailingOffset = self.width - lb.maxX;
    lb.font = trailingOffset < 32 ? [UIFont regular15] : [UIFont regular16];
  }
}

- (BOOL)textView:(UITextView *)textView
    shouldInteractWithURL:(NSURL *)URL
                  inRange:(NSRange)characterRange
{
  NSString * scheme = URL.scheme;
  if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"])
  {
    [[MapViewController controller] openUrl:URL];
    return NO;
  }
  return YES;
}

- (IBAction)cellTap
{
  switch (self.type)
  {
  case MWMPlacePageCellTypeURL:
  case MWMPlacePageCellTypeWebsite:
    [Statistics logEvent:kStatEventName(kStatPlacePage, kStatOpenSite)];
    break;
  case MWMPlacePageCellTypeEmail:
    [Statistics logEvent:kStatEventName(kStatPlacePage, kStatSendEmail)];
    break;
  case MWMPlacePageCellTypePhoneNumber:
    [Statistics logEvent:kStatEventName(kStatPlacePage, kStatCallPhoneNumber)];
    break;
  case MWMPlacePageCellTypeCoordinate:
    [Statistics logEvent:kStatEventName(kStatPlacePage, kStatToggleCoordinates)];
    [self.currentEntity toggleCoordinateSystem];
    [self changeText:[self.currentEntity getCellValue:MWMPlacePageCellTypeCoordinate]];
    break;
  default: break;
  }
}

- (void)longTap:(UILongPressGestureRecognizer *)sender
{
  UIMenuController * menuController = [UIMenuController sharedMenuController];
  if (menuController.isMenuVisible)
    return;
  CGPoint const tapPoint = [sender locationInView:sender.view.superview];
  UIView * targetView =
      [self.textContainer isKindOfClass:[UITextView class]] ? sender.view : self.textContainer;
  [menuController setTargetRect:CGRectMake(tapPoint.x, targetView.minY, 0., 0.)
                         inView:sender.view.superview];
  [menuController setMenuVisible:YES animated:YES];
  [targetView becomeFirstResponder];
  [menuController update];
}

@end