diff options
author | v.mikhaylenko <v.mikhaylenko@corp.mail.ru> | 2015-06-16 20:21:32 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:52:40 +0300 |
commit | 4e8f1cc18f1a594e5cd35a7ee85937939ac3a4f2 (patch) | |
tree | 878b831909555983c98433dd0435e02b10b1787c /iphone/Maps/Classes/MWMPlacePageInfoCell.mm | |
parent | 00c153b50ff6c92c312fb9fdc7662df4eef54388 (diff) |
[ios] Added safety interface for work with metadata dictionary.
Diffstat (limited to 'iphone/Maps/Classes/MWMPlacePageInfoCell.mm')
-rw-r--r-- | iphone/Maps/Classes/MWMPlacePageInfoCell.mm | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/iphone/Maps/Classes/MWMPlacePageInfoCell.mm b/iphone/Maps/Classes/MWMPlacePageInfoCell.mm index aaa5177457..5019baf07f 100644 --- a/iphone/Maps/Classes/MWMPlacePageInfoCell.mm +++ b/iphone/Maps/Classes/MWMPlacePageInfoCell.mm @@ -21,16 +21,44 @@ extern NSString * const kUserDefaultsLatLonAsDMSKey; @property (weak, nonatomic, readwrite) IBOutlet id textContainer; @property (weak, nonatomic) IBOutlet UIButton * upperButton; -@property (copy, nonatomic) NSString * type; +@property (nonatomic) MWMPlacePageMetadataType type; @end @implementation MWMPlacePageInfoCell -- (void)configureWithIconTitle:(NSString *)title info:(NSString *)info +- (void)configureWithType:(MWMPlacePageMetadataType)type info:(NSString *)info; { - self.type = title; - [self.imageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"ic_%@", title]]]; + NSMutableString * imageName = [@"ic_" mutableCopy]; + switch (type) + { + case MWMPlacePageMetadataTypeURL: + case MWMPlacePageMetadataTypeWebsite: + [imageName appendString:@"Website"]; + break; + case MWMPlacePageMetadataTypeEmail: + [imageName appendString:@"Email"]; + break; + case MWMPlacePageMetadataTypePhoneNumber: + [imageName appendString:@"PhoneNumber"]; + break; + case MWMPlacePageMetadataTypeCoordinate: + [imageName appendString:@"Coordinate"]; + break; + case MWMPlacePageMetadataTypePostcode: + [imageName appendString:@"Postcode"]; + break; + case MWMPlacePageMetadataTypeOpenHours: + [imageName appendString:@"OpenHours"]; + break; + case MWMPlacePageMetadataTypeBookmark: + NSAssert(false, @"Incorrect type!"); + break; + } + + UIImage * image = [UIImage imageNamed:imageName]; + self.type = type; + [self.imageView setImage:image]; if ([self.textContainer isKindOfClass:[UITextView class]]) [self.textContainer setAttributedText:[[NSAttributedString alloc] initWithString:info attributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Light" size:16.]}]]; @@ -38,7 +66,7 @@ extern NSString * const kUserDefaultsLatLonAsDMSKey; [self.textContainer setText:info]; UILongPressGestureRecognizer * longTap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTap:)]; - longTap.minimumPressDuration = 0.3f; + longTap.minimumPressDuration = 0.3; [self.upperButton addGestureRecognizer:longTap]; } @@ -47,19 +75,17 @@ extern NSString * const kUserDefaultsLatLonAsDMSKey; return YES; } -- (IBAction)cellTap:(id)sender +- (IBAction)cellTap { - if ([self.type isEqualToString:@"Coordinate"]) - { - NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; - BOOL const isLatLonAsDMA = [defaults boolForKey:kUserDefaultsLatLonAsDMSKey]; - m2::PointD const point = self.currentEntity.point; - - isLatLonAsDMA ? [self.textContainer setText:[NSString stringWithUTF8String:MeasurementUtils::FormatLatLon(point.x, point.y).c_str()]] : [self.textContainer setText:[NSString stringWithUTF8String:MeasurementUtils::FormatLatLonAsDMS(point.x, point.y, 2).c_str()]]; + if (self.type != MWMPlacePageMetadataTypeCoordinate) + return; - [defaults setBool:!isLatLonAsDMA forKey:kUserDefaultsLatLonAsDMSKey]; - [defaults synchronize]; - } + NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; + BOOL const showLatLonAsDMS = [defaults boolForKey:kUserDefaultsLatLonAsDMSKey]; + m2::PointD const point = self.currentEntity.point; + [self.textContainer setText:[NSString stringWithUTF8String:(showLatLonAsDMS ? MeasurementUtils::FormatLatLon(point.x, point.y).c_str() : MeasurementUtils::FormatLatLonAsDMS(point.x, point.y, 2).c_str())]]; + [defaults setBool:!showLatLonAsDMS forKey:kUserDefaultsLatLonAsDMSKey]; + [defaults synchronize]; } - (void)longTap:(UILongPressGestureRecognizer *)sender @@ -67,8 +93,7 @@ extern NSString * const kUserDefaultsLatLonAsDMSKey; UIMenuController * menuController = [UIMenuController sharedMenuController]; if (menuController.isMenuVisible) return; - - CGPoint tapPoint = [sender locationInView:sender.view.superview]; + 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]; |