From 70c61b34ecd4a4c32f53f38418a3def470252e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=93=D1=80=D0=B5=D1=87=D1=83?= =?UTF-8?q?=D1=85=D0=B8=D0=BD?= Date: Tue, 29 Dec 2015 10:11:04 +0300 Subject: [PATCH] [ios] Review fixes. --- .../MWMPedestrianShareAlert.mm | 4 +- .../Login/MWMAuthorizationCommon.h | 2 +- .../Login/MWMAuthorizationCommon.mm | 2 +- .../MWMAuthorizationLoginViewController.mm | 14 +- .../MWMAuthorizationOSMLoginViewController.mm | 4 +- .../MWMPlacePageOpeningHoursCell.mm | 14 +- .../MWMOpeningHoursEditorViewController.mm | 21 +- .../OpeningHours/MWMOpeningHoursModel.mm | 7 +- .../InputValidators/MWMInputEmailValidator.mm | 2 +- .../MWMInputValidatorFactory.mm | 1 + iphone/Maps/Classes/MWMBasePlacePageView.mm | 21 +- iphone/Maps/Classes/MWMBookmarkColorCell.mm | 2 - .../Classes/MWMBookmarkColorViewController.mm | 11 +- iphone/Maps/Classes/MWMPlacePage.h | 1 - iphone/Maps/Classes/MWMPlacePage.mm | 27 ++- iphone/Maps/Classes/MWMPlacePageEntity.h | 12 +- iphone/Maps/Classes/MWMPlacePageEntity.mm | 211 ++++++++---------- iphone/Maps/Classes/MWMPlacePageInfoCell.mm | 26 +-- .../Maps/Classes/MWMPlacePageViewManager.mm | 6 +- iphone/Maps/Classes/MapViewController.mm | 4 +- iphone/Maps/Classes/PlacePageInfoCell.xib | 1 + 21 files changed, 197 insertions(+), 196 deletions(-) diff --git a/iphone/Maps/Classes/CustomAlert/PedestrianShareAlert/MWMPedestrianShareAlert.mm b/iphone/Maps/Classes/CustomAlert/PedestrianShareAlert/MWMPedestrianShareAlert.mm index 39be731da7..c8538a7cf3 100644 --- a/iphone/Maps/Classes/CustomAlert/PedestrianShareAlert/MWMPedestrianShareAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/PedestrianShareAlert/MWMPedestrianShareAlert.mm @@ -77,12 +77,12 @@ static NSString * const kStatisticsEvent = @"Pedestrian Share Alert"; - (void)rotate:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { - // Overriden implemantation left empty since this view is added to the view controller handling device rotation + // Overridden implemantation left empty since this view is added to the view controller handling device rotation } - (void)addControllerViewToWindow { - // Overriden implemantation left empty to let sharing view appear above + // Overridden implemantation left empty to let sharing view appear above } @end diff --git a/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationCommon.h b/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationCommon.h index b76b4e3b7e..40288c3257 100644 --- a/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationCommon.h +++ b/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationCommon.h @@ -10,4 +10,4 @@ typedef NS_OPTIONS(NSUInteger, MWMAuthorizationButtonType) }; UIColor * MWMAuthorizationButtonBackgroundColor(MWMAuthorizationButtonType type); -void MWMAuthorizationConfigButton(UIButton * btn, MWMAuthorizationButtonType type); \ No newline at end of file +void MWMAuthorizationConfigButton(UIButton * btn, MWMAuthorizationButtonType type); diff --git a/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationCommon.mm b/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationCommon.mm index 003b32b96c..7d60a213d9 100644 --- a/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationCommon.mm +++ b/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationCommon.mm @@ -23,7 +23,7 @@ UIColor * MWMAuthorizationButtonBackgroundColor(MWMAuthorizationButtonType type) case MWMAuthorizationButtonTypeFacebook: return [UIColor colorWithRed:72. / 255. green:97. / 255. blue:163. / 255. alpha:1.]; case MWMAuthorizationButtonTypeOSM: - return [UIColor colorWithRed:3. / 255. green:122. / 255. blue:1. alpha:1.]; + return [UIColor colorWithRed:30. / 255. green:150. / 255. blue:240. / 255. alpha:1.]; } return [UIColor clearColor]; } diff --git a/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationLoginViewController.mm b/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationLoginViewController.mm index 68a7704e7d..91a298fbae 100644 --- a/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationLoginViewController.mm +++ b/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationLoginViewController.mm @@ -20,10 +20,6 @@ { [super viewDidLoad]; self.backgroundImage.image = [UIImage imageWithColor:[UIColor primary]]; - - MWMAuthorizationConfigButton(self.loginGoogleButton, MWMAuthorizationButtonTypeGoogle); - MWMAuthorizationConfigButton(self.loginFacebookButton, MWMAuthorizationButtonTypeFacebook); - MWMAuthorizationConfigButton(self.loginOSMButton, MWMAuthorizationButtonTypeOSM); [self checkConnection]; } @@ -57,6 +53,16 @@ self.loginGoogleButton.enabled = isConnected; self.loginFacebookButton.enabled = isConnected; self.signupButton.enabled = isConnected; + + MWMAuthorizationConfigButton(self.loginGoogleButton, MWMAuthorizationButtonTypeGoogle); + MWMAuthorizationConfigButton(self.loginFacebookButton, MWMAuthorizationButtonTypeFacebook); + MWMAuthorizationConfigButton(self.loginOSMButton, MWMAuthorizationButtonTypeOSM); + + if (!isConnected) + { + self.loginGoogleButton.layer.borderColor = [UIColor clearColor].CGColor; + self.loginFacebookButton.layer.borderColor = [UIColor clearColor].CGColor; + } } #pragma mark - Actions diff --git a/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationOSMLoginViewController.mm b/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationOSMLoginViewController.mm index e3f9dda39e..0d86dc3fcb 100644 --- a/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationOSMLoginViewController.mm +++ b/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationOSMLoginViewController.mm @@ -111,8 +111,8 @@ typedef NS_OPTIONS(NSUInteger, MWMFieldCorrect) // TODO: Add async loader spinner dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^ { - string username = self.loginTextField.text.UTF8String; - string password = self.passwordTextField.text.UTF8String; + string const username = self.loginTextField.text.UTF8String; + string const password = self.passwordTextField.text.UTF8String; BOOL const credentialsOK = osm::ServerApi06(username, password).CheckUserAndPassword(); dispatch_async(dispatch_get_main_queue(), ^ { diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/PlacePage/Cells/OpeningHours/MWMPlacePageOpeningHoursCell.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/PlacePage/Cells/OpeningHours/MWMPlacePageOpeningHoursCell.mm index de1342f5c0..840c609b7c 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/PlacePage/Cells/OpeningHours/MWMPlacePageOpeningHoursCell.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/PlacePage/Cells/OpeningHours/MWMPlacePageOpeningHoursCell.mm @@ -72,7 +72,7 @@ WeekDayView getWeekDayView() BOOL const isExpanded = delegate.openingHoursCellExpanded; self.middleSeparator.hidden = !isExpanded; self.weekDaysView.hidden = !isExpanded; - self.editButton.hidden = NO; + self.editButton.hidden = !isExpanded; self.expandImage.image = [UIImage imageNamed:isExpanded ? @"ic_arrow_gray_up" : @"ic_arrow_gray_down"]; } else @@ -93,11 +93,11 @@ WeekDayView getWeekDayView() Weekday currentDay = static_cast([cal component:NSCalendarUnitWeekday fromDate:[NSDate date]]); BOOL haveCurrentDay = NO; size_t timeTablesCount = timeTableSet.Size(); - BOOL const canExpand = (timeTablesCount > 1); + BOOL const haveExpandSchedule = (timeTablesCount > 1); BOOL const isExpanded = self.delegate.openingHoursCellExpanded; self.weekDaysViewEstimatedHeight = 0.0; [self.weekDaysView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; - [self.currentDay setCanExpand:canExpand]; + [self.currentDay setCanExpand:YES]; for (size_t idx = 0; idx < timeTablesCount; ++idx) { ui::TTimeTableProxy tt = timeTableSet.Get(idx); @@ -107,12 +107,12 @@ WeekDayView getWeekDayView() haveCurrentDay = YES; [self addCurrentDay:tt]; } - if (canExpand && isExpanded) + if (haveExpandSchedule && isExpanded) [self addWeekDays:tt]; } if (!haveCurrentDay) [self addEmptyCurrentDay]; - if (canExpand && isExpanded) + if (haveExpandSchedule && isExpanded) [self addClosedDays]; self.weekDaysViewHeight.constant = ceil(self.weekDaysViewEstimatedHeight); } @@ -186,9 +186,7 @@ WeekDayView getWeekDayView() { CGFloat height = self.currentDay.viewHeight; if (!self.currentDay.isCompatibility && self.delegate.openingHoursCellExpanded) - height += self.weekDaysViewHeight.constant; - if (!self.editButton.hidden) - height += self.editButton.height; + height += self.weekDaysViewHeight.constant + self.editButton.height; return ceil(height); } diff --git a/iphone/Maps/Classes/Editor/OpeningHours/MWMOpeningHoursEditorViewController.mm b/iphone/Maps/Classes/Editor/OpeningHours/MWMOpeningHoursEditorViewController.mm index 1737b1ec7e..defd881912 100644 --- a/iphone/Maps/Classes/Editor/OpeningHours/MWMOpeningHoursEditorViewController.mm +++ b/iphone/Maps/Classes/Editor/OpeningHours/MWMOpeningHoursEditorViewController.mm @@ -31,6 +31,7 @@ extern NSDictionary * const kMWMOpeningHoursEditorTableCells = @{ @property (weak, nonatomic, readwrite) IBOutlet UIButton * toggleModeButton; @property (nonatomic) BOOL exampleExpanded; +@property (nonatomic) BOOL isSimpleMode; @property (nonatomic) MWMOpeningHoursModel * model; @@ -71,13 +72,13 @@ extern NSDictionary * const kMWMOpeningHoursEditorTableCells = @{ - (void)configAdvancedEditor { - [self.editorView setTextContainerInset:{12, 10, 12, 10}]; - [self setExampleExpanded:NO]; + [self.editorView setTextContainerInset:{.top = 12, .left = 10, .bottom = 12, .right = 10}]; } - (void)configData { self.model = [[MWMOpeningHoursModel alloc] initWithDelegate:self]; + self.isSimpleMode = self.model.isSimpleModeCapable; } #pragma mark - Actions @@ -183,7 +184,7 @@ extern NSDictionary * const kMWMOpeningHoursEditorTableCells = @{ - (IBAction)toggleMode { - self.model.isSimpleMode = !self.model.isSimpleMode; + self.isSimpleMode = !self.isSimpleMode; } #pragma mark - UITextViewDelegate @@ -195,4 +196,18 @@ extern NSDictionary * const kMWMOpeningHoursEditorTableCells = @{ self.toggleModeButton.enabled = self.model.isSimpleModeCapable; } +#pragma mark - Properties + +- (void)setIsSimpleMode:(BOOL)isSimpleMode +{ + self.model.isSimpleMode = isSimpleMode; + if (!isSimpleMode) + self.exampleExpanded = NO; +} + +- (BOOL)isSimpleMode +{ + return self.model.isSimpleMode; +} + @end diff --git a/iphone/Maps/Classes/Editor/OpeningHours/MWMOpeningHoursModel.mm b/iphone/Maps/Classes/Editor/OpeningHours/MWMOpeningHoursModel.mm index 31a43c79b6..bc30837933 100644 --- a/iphone/Maps/Classes/Editor/OpeningHours/MWMOpeningHoursModel.mm +++ b/iphone/Maps/Classes/Editor/OpeningHours/MWMOpeningHoursModel.mm @@ -27,10 +27,7 @@ using namespace osmoh; { self = [super init]; if (self) - { - self.delegate = delegate; - self.isSimpleMode = self.isSimpleModeCapable; - } + _delegate = delegate; return self; } @@ -168,7 +165,6 @@ using namespace osmoh; id delegate = self.delegate; if (isSimpleMode && MakeTimeTableSet(osmoh::OpeningHours(delegate.openingHours.UTF8String), timeTableSet)) { - _isSimpleMode = YES; delegate.tableView.hidden = NO; delegate.advancedEditor.hidden = YES; [delegate.toggleModeButton setTitle:L(@"advanced_mode") forState:UIControlStateNormal]; @@ -179,7 +175,6 @@ using namespace osmoh; } else { - _isSimpleMode = NO; [self updateOpeningHours]; delegate.tableView.hidden = YES; delegate.advancedEditor.hidden = NO; diff --git a/iphone/Maps/Classes/InputValidators/MWMInputEmailValidator.mm b/iphone/Maps/Classes/InputValidators/MWMInputEmailValidator.mm index b81c158ca6..7dce50fce5 100644 --- a/iphone/Maps/Classes/InputValidators/MWMInputEmailValidator.mm +++ b/iphone/Maps/Classes/InputValidators/MWMInputEmailValidator.mm @@ -15,7 +15,7 @@ static NSString * const kEmailRegexPattern = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\ error:&err]; NSAssert(!err, @"Invalid regular expression"); NSMutableArray * matches = [@[] mutableCopy]; - NSRange const range = {0, string.length}; + NSRange const range{0, string.length}; [regex enumerateMatchesInString:string options:NSMatchingReportProgress range:range diff --git a/iphone/Maps/Classes/InputValidators/MWMInputValidatorFactory.mm b/iphone/Maps/Classes/InputValidators/MWMInputValidatorFactory.mm index 95119f046d..74e46a36d3 100644 --- a/iphone/Maps/Classes/InputValidators/MWMInputValidatorFactory.mm +++ b/iphone/Maps/Classes/InputValidators/MWMInputValidatorFactory.mm @@ -14,6 +14,7 @@ return [[MWMInputPasswordValidator alloc] init]; if ([validator isEqualToString:[MWMInputEmailValidator className]]) return [[MWMInputEmailValidator alloc] init]; + NSAssert(false, @"Invalid validator requested."); return [[MWMInputValidator alloc] init]; } diff --git a/iphone/Maps/Classes/MWMBasePlacePageView.mm b/iphone/Maps/Classes/MWMBasePlacePageView.mm index 2c8deda5f7..3d356d6635 100644 --- a/iphone/Maps/Classes/MWMBasePlacePageView.mm +++ b/iphone/Maps/Classes/MWMBasePlacePageView.mm @@ -269,9 +269,8 @@ extern CGFloat const kBasePlacePageViewTitleBottomOffset = 2.; - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - - MWMPlacePageMetadataType currentType = (MWMPlacePageMetadataType)[self.entity.metadataTypes[indexPath.row] integerValue]; - + MWMPlacePageEntity * entity = self.entity; + MWMPlacePageMetadataType const currentType = [entity getType:indexPath.row]; if (currentType == MWMPlacePageMetadataTypeBookmark) { [self.bookmarkSizingCell config:self.ownerPlacePage forHeight:YES]; @@ -279,8 +278,7 @@ extern CGFloat const kBasePlacePageViewTitleBottomOffset = 2.; } else if (currentType == MWMPlacePageMetadataTypeOpenHours) { - [self.openingHoursSizingCell configWithInfo:self.entity.metadataValues[indexPath.row] - delegate:self]; + [self.openingHoursSizingCell configWithInfo:[entity getValue:currentType] delegate:self]; return self.openingHoursSizingCell.cellHeight; } else if (currentType == MWMPlacePageMetadataTypeEditButton) @@ -294,7 +292,7 @@ extern CGFloat const kBasePlacePageViewTitleBottomOffset = 2.; CGFloat const rightOffset = 22.; UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0., 0., defaultWidth - leftOffset - rightOffset, 10.)]; label.numberOfLines = 0; - label.text = self.entity.metadataValues[indexPath.row]; + label.text = [entity getValue:currentType]; [label sizeToFit]; CGFloat const defaultCellOffset = 24.; return MAX(label.height + defaultCellOffset, defaultCellHeight); @@ -302,13 +300,13 @@ extern CGFloat const kBasePlacePageViewTitleBottomOffset = 2.; - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return self.entity.metadataTypes.count; + return [self.entity getTypesCount]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - MWMPlacePageMetadataType currentType = (MWMPlacePageMetadataType)[self.entity.metadataTypes[indexPath.row] integerValue]; - + MWMPlacePageEntity * entity = self.entity; + MWMPlacePageMetadataType const currentType = [entity getType:indexPath.row]; if (currentType == MWMPlacePageMetadataTypeBookmark) { MWMPlacePageBookmarkCell * cell = (MWMPlacePageBookmarkCell *)[tableView dequeueReusableCellWithIdentifier:kPlacePageBookmarkCellIdentifier]; @@ -320,8 +318,7 @@ extern CGFloat const kBasePlacePageViewTitleBottomOffset = 2.; { MWMPlacePageOpeningHoursCell * cell = (MWMPlacePageOpeningHoursCell *) [tableView dequeueReusableCellWithIdentifier:kPlacePageOpeningHoursCellIdentifier]; - [cell configWithInfo:self.entity.metadataValues[indexPath.row] - delegate:self]; + [cell configWithInfo:[entity getValue:currentType] delegate:self]; return cell; } else if (currentType == MWMPlacePageMetadataTypeEditButton) @@ -337,7 +334,7 @@ extern CGFloat const kBasePlacePageViewTitleBottomOffset = 2.; MWMPlacePageInfoCell * cell = (MWMPlacePageInfoCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; cell.currentEntity = self.entity; - [cell configureWithType:currentType info:self.entity.metadataValues[indexPath.row]]; + [cell configureWithType:currentType info:[entity getValue:currentType]]; return cell; } diff --git a/iphone/Maps/Classes/MWMBookmarkColorCell.mm b/iphone/Maps/Classes/MWMBookmarkColorCell.mm index 0d48f0316c..b62e4fd8d9 100644 --- a/iphone/Maps/Classes/MWMBookmarkColorCell.mm +++ b/iphone/Maps/Classes/MWMBookmarkColorCell.mm @@ -1,8 +1,6 @@ #import "MWMBookmarkColorCell.h" #import "UIColor+MapsMeColor.h" -extern NSArray * const kBookmarkColorsVariant; - @interface MWMBookmarkColorCell () @property (copy, nonatomic) NSString * currentImageName; diff --git a/iphone/Maps/Classes/MWMBookmarkColorViewController.mm b/iphone/Maps/Classes/MWMBookmarkColorViewController.mm index 681846adce..f83c1c3b76 100644 --- a/iphone/Maps/Classes/MWMBookmarkColorViewController.mm +++ b/iphone/Maps/Classes/MWMBookmarkColorViewController.mm @@ -6,7 +6,16 @@ #import "UIColor+MapsMeColor.h" #import "UIViewController+navigation.h" -extern NSArray * const kBookmarkColorsVariant; +static NSArray * const kBookmarkColorsVariant = @[ + @"placemark-red", + @"placemark-yellow", + @"placemark-blue", + @"placemark-green", + @"placemark-purple", + @"placemark-orange", + @"placemark-brown", + @"placemark-pink" +]; static NSString * const kBookmarkColorCellIdentifier = @"MWMBookmarkColorCell"; diff --git a/iphone/Maps/Classes/MWMPlacePage.h b/iphone/Maps/Classes/MWMPlacePage.h index c4c7763f76..d50b0a7b82 100644 --- a/iphone/Maps/Classes/MWMPlacePage.h +++ b/iphone/Maps/Classes/MWMPlacePage.h @@ -28,7 +28,6 @@ - (void)changeBookmarkCategory; - (void)changeBookmarkDescription; - (void)editPlaceTime; -- (void)login; - (void)share; - (void)route; - (void)reloadBookmark; diff --git a/iphone/Maps/Classes/MWMPlacePage.mm b/iphone/Maps/Classes/MWMPlacePage.mm index d1c11354a8..dcc0166fb9 100644 --- a/iphone/Maps/Classes/MWMPlacePage.mm +++ b/iphone/Maps/Classes/MWMPlacePage.mm @@ -35,15 +35,18 @@ static NSString * const kPlacePageViewCenterKeyPath = @"center"; options:NSKeyValueObservingOptionNew context:nullptr]; } - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(keyboardWillShow:) - name:UIKeyboardWillShowNotification - object:nil]; + dispatch_async(dispatch_get_main_queue(), ^ + { + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillShow:) + name:UIKeyboardWillShowNotification + object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(keyboardWillHide) - name:UIKeyboardWillHideNotification - object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillHide) + name:UIKeyboardWillHideNotification + object:nil]; + }); } return self; } @@ -199,7 +202,7 @@ static NSString * const kPlacePageViewCenterKeyPath = @"center"; - (void)willStartEditingBookmarkTitle { [[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatRename)]; -// This method should be overriden. +// This method should be оverridden. } - (void)willFinishEditingBookmarkTitle:(NSString *)title @@ -210,17 +213,17 @@ static NSString * const kPlacePageViewCenterKeyPath = @"center"; - (IBAction)didTap:(UITapGestureRecognizer *)sender { -// This method should be overriden if you want to process custom tap. +// This method should be оverridden if you want to process custom tap. } - (IBAction)didPan:(UIPanGestureRecognizer *)sender { - // This method should be overriden if you want to process custom pan. + // This method should be оverridden if you want to process custom pan. } - (void)refresh { - // This method should be overriden. + // This method should be оverridden. } #pragma mark - Properties diff --git a/iphone/Maps/Classes/MWMPlacePageEntity.h b/iphone/Maps/Classes/MWMPlacePageEntity.h index 4ad68d812e..678dc7c171 100644 --- a/iphone/Maps/Classes/MWMPlacePageEntity.h +++ b/iphone/Maps/Classes/MWMPlacePageEntity.h @@ -45,14 +45,10 @@ typedef NS_ENUM (NSUInteger, MWMPlacePageEntityType) @property (nonatomic) int typeDescriptionValue; @property (nonatomic) BookmarkAndCategory bac; -@property (nonatomic) ms::LatLon ll; @property (weak, nonatomic) MWMPlacePageViewManager * manager; -// Automatically checks if DMS format should be used. -- (NSString *)coordinates; +@property (nonatomic, readonly) ms::LatLon latlon; -- (NSArray *)metadataTypes; -- (NSArray *)metadataValues; - (void)enableEditing; - (void)insertBookmarkInTypes; - (void)removeBookmarkFromTypes; @@ -60,4 +56,10 @@ typedef NS_ENUM (NSUInteger, MWMPlacePageEntityType) - (instancetype)initWithUserMark:(UserMark const *)mark; - (void)synchronize; +- (void)toggleCoordinateSystem; + +- (NSUInteger)getTypesCount; +- (MWMPlacePageMetadataType)getType:(NSUInteger)index; +- (NSString *)getValue:(MWMPlacePageMetadataType)type; + @end diff --git a/iphone/Maps/Classes/MWMPlacePageEntity.mm b/iphone/Maps/Classes/MWMPlacePageEntity.mm index 203ab29e0d..b6340347a1 100644 --- a/iphone/Maps/Classes/MWMPlacePageEntity.mm +++ b/iphone/Maps/Classes/MWMPlacePageEntity.mm @@ -3,74 +3,54 @@ #import "MapViewController.h" #include "platform/measurement_utils.hpp" -extern NSArray * const kBookmarkColorsVariant = @[ - @"placemark-red", - @"placemark-yellow", - @"placemark-blue", - @"placemark-green", - @"placemark-purple", - @"placemark-orange", - @"placemark-brown", - @"placemark-pink" -]; -extern NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; -static NSArray * const kPatternTypesArray = @[ - @(MWMPlacePageMetadataTypePostcode), - @(MWMPlacePageMetadataTypePhoneNumber), - @(MWMPlacePageMetadataTypeWebsite), - @(MWMPlacePageMetadataTypeURL), - @(MWMPlacePageMetadataTypeEmail), - @(MWMPlacePageMetadataTypeOpenHours), - @(MWMPlacePageMetadataTypeWiFi), - @(MWMPlacePageMetadataTypeCoordinate) -]; - using feature::Metadata; -@interface MWMPlacePageEntity () +extern NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; -@property (nonatomic) NSMutableArray * metaTypes; -@property (nonatomic) NSMutableArray * metaValues; +static array const kPatternTypesArray{ + {MWMPlacePageMetadataTypePostcode, MWMPlacePageMetadataTypePhoneNumber, + MWMPlacePageMetadataTypeWebsite, MWMPlacePageMetadataTypeURL, MWMPlacePageMetadataTypeEmail, + MWMPlacePageMetadataTypeOpenHours, MWMPlacePageMetadataTypeWiFi, + MWMPlacePageMetadataTypeCoordinate}}; -@end +static map const kMetaTypesMap{ + {Metadata::FMD_URL, MWMPlacePageMetadataTypeURL}, + {Metadata::FMD_WEBSITE, MWMPlacePageMetadataTypeWebsite}, + {Metadata::FMD_PHONE_NUMBER, MWMPlacePageMetadataTypePhoneNumber}, + {Metadata::FMD_OPEN_HOURS, MWMPlacePageMetadataTypeOpenHours}, + {Metadata::FMD_EMAIL, MWMPlacePageMetadataTypeEmail}, + {Metadata::FMD_POSTCODE, MWMPlacePageMetadataTypePostcode}, + {Metadata::FMD_INTERNET, MWMPlacePageMetadataTypeWiFi}}; @implementation MWMPlacePageEntity - -- (instancetype)initWithUserMark:(UserMark const *)mark { + vector m_types; + map m_values; +} + +- (instancetype)initWithUserMark:(UserMark const *)userMark +{ + NSAssert(userMark, @"userMark can not be nil."); self = [super init]; if (self) - { - self.metaTypes = [NSMutableArray array]; - self.metaValues = [NSMutableArray array]; - [self configureWithUserMark:mark]; - } - + [self configureWithUserMark:userMark]; return self; } - (void)configureWithUserMark:(UserMark const *)mark { - UserMark::Type const type = mark->GetMarkType(); - self.ll = mark->GetLatLon(); - - typedef UserMark::Type Type; - switch (type) + _latlon = mark->GetLatLon(); + using Type = UserMark::Type; + switch (mark->GetMarkType()) { case Type::API: - { - ApiMarkPoint const * apiMark = static_cast(mark); - [self configureForApi:apiMark]; + [self configureForApi:static_cast(mark)]; break; - } case Type::DEBUG_MARK: break; case Type::MY_POSITION: - { - MyPositionMarkPoint const * myPositionMark = static_cast(mark); - [self configureForMyPosition:myPositionMark]; + [self configureForMyPosition:static_cast(mark)]; break; - } case Type::SEARCH: [self configureForSearch:static_cast(mark)]; break; @@ -83,6 +63,25 @@ using feature::Metadata; } } +- (void)addMetaType:(MWMPlacePageMetadataType)type +{ + if (find(m_types.begin(), m_types.end(), type) == m_types.end()) + m_types.emplace_back(type); +} + +- (void)removeMetaType:(MWMPlacePageMetadataType)type +{ + auto it = find(m_types.begin(), m_types.end(), type); + if (it != m_types.end()) + m_types.erase(it); +} + +- (void)addMetaType:(MWMPlacePageMetadataType)type value:(string const &)value +{ + [self addMetaType:type]; + m_values.emplace(type, value); +} + - (void)configureForBookmark:(UserMark const *)bookmark { Framework & f = GetFramework(); @@ -125,8 +124,7 @@ using feature::Metadata; { self.title = L(@"my_position"); self.type = MWMPlacePageEntityTypeMyPosition; - [self.metaTypes addObject:kPatternTypesArray.lastObject]; - [self.metaValues addObject:[self coordinates]]; + [self addMetaType:MWMPlacePageMetadataTypeCoordinate]; } - (void)configureForApi:(ApiMarkPoint const *)apiMark @@ -134,8 +132,7 @@ using feature::Metadata; self.type = MWMPlacePageEntityTypeAPI; self.title = @(apiMark->GetName().c_str()); self.category = @(GetFramework().GetApiDataHolder().GetAppTitle().c_str()); - [self.metaTypes addObject:kPatternTypesArray.lastObject]; - [self.metaValues addObject:[self coordinates]]; + [self addMetaType:MWMPlacePageMetadataTypeCoordinate]; } - (void)configureEntityWithMetadata:(Metadata const &)metadata addressInfo:(search::AddressInfo const &)info @@ -201,95 +198,83 @@ using feature::Metadata; case Metadata::FMD_POSTCODE: case Metadata::FMD_INTERNET: { - NSString * v; - if (type == Metadata::FMD_INTERNET) - v = L(@"WiFi_available"); + auto metaType = kMetaTypesMap.find(type); + if (metaType != kMetaTypesMap.end()) + { + BOOL const internet = (type == Metadata::FMD_INTERNET); + [self addMetaType:metaType->second value:internet ? L(@"WiFi_available").UTF8String : metadata.Get(type)]; + } else - v = @(metadata.Get(type).c_str()); - - NSNumber const * t = [self typeFromMetadata:type]; - [self.metaTypes addObject:t]; - [self.metaValues addObject:v]; - break; + { + NSAssert(false, @"Unhandled meta type, see kMetaTypesMap."); + } } - default: break; } } - NSUInteger swappedIndex = 0; - for (NSNumber * pattern in kPatternTypesArray) + auto begin = kPatternTypesArray.begin(); + auto end = kPatternTypesArray.end(); + sort(m_types.begin(), m_types.end(), [&](MWMPlacePageMetadataType a, MWMPlacePageMetadataType b) { - NSUInteger const index = [self.metaTypes indexOfObject:pattern]; - if (index == NSNotFound) - continue; - [self.metaTypes exchangeObjectAtIndex:index withObjectAtIndex:swappedIndex]; - [self.metaValues exchangeObjectAtIndex:index withObjectAtIndex:swappedIndex]; - swappedIndex++; - } + return find(begin, end, a) < find(begin, end, b); + }); - [self.metaTypes addObject:kPatternTypesArray.lastObject]; - [self.metaValues addObject:[self coordinates]]; -} - -- (NSArray *)metadataTypes -{ - return (NSArray *)self.metaTypes; -} - -- (NSArray *)metadataValues -{ - return (NSArray *)self.metaValues; + [self addMetaType:MWMPlacePageMetadataTypeCoordinate]; } - (void)enableEditing { - NSNumber * editType = @(MWMPlacePageMetadataTypeEditButton); - if (![self.metaTypes containsObject:editType]) - [self.metaTypes addObject:editType]; + [self addMetaType:MWMPlacePageMetadataTypeEditButton]; } - (void)insertBookmarkInTypes { - NSNumber * bookmarkType = @(MWMPlacePageMetadataTypeBookmark); - if (![self.metaTypes containsObject:bookmarkType]) - [self.metaTypes addObject:bookmarkType]; + [self addMetaType:MWMPlacePageMetadataTypeBookmark]; } - (void)removeBookmarkFromTypes { - [self.metaTypes removeObject:@(MWMPlacePageMetadataTypeBookmark)]; + [self removeMetaType:MWMPlacePageMetadataTypeBookmark]; } -- (NSNumber *)typeFromMetadata:(uint8_t)type +- (void)toggleCoordinateSystem { - switch (type) - { - case Metadata::FMD_URL: - return @(MWMPlacePageMetadataTypeURL); - case Metadata::FMD_WEBSITE: - return @(MWMPlacePageMetadataTypeWebsite); - case Metadata::FMD_PHONE_NUMBER: - return @(MWMPlacePageMetadataTypePhoneNumber); - case Metadata::FMD_OPEN_HOURS: - return @(MWMPlacePageMetadataTypeOpenHours); - case Metadata::FMD_EMAIL: - return @(MWMPlacePageMetadataTypeEmail); - case Metadata::FMD_POSTCODE: - return @(MWMPlacePageMetadataTypePostcode); - case Metadata::FMD_INTERNET: - return @(MWMPlacePageMetadataTypeWiFi); - default: - return nil; - } + NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; + [ud setBool:![ud boolForKey:kUserDefaultsLatLonAsDMSKey] forKey:kUserDefaultsLatLonAsDMSKey]; + [ud synchronize]; } -- (NSString *)coordinates +#pragma mark - Getters + +- (NSUInteger)getTypesCount { - BOOL const useDMSFormat = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsLatLonAsDMSKey]; - return @((useDMSFormat ? MeasurementUtils::FormatLatLon(self.ll.lat, self.ll.lon).c_str() - : MeasurementUtils::FormatLatLonAsDMS(self.ll.lat, self.ll.lon, 2).c_str())); + return m_types.size(); +} + +- (MWMPlacePageMetadataType)getType:(NSUInteger)index +{ + NSAssert(index < [self getTypesCount], @"Invalid meta index"); + return m_types[index]; +} + +- (NSString *)getValue:(MWMPlacePageMetadataType)type +{ + if (type == MWMPlacePageMetadataTypeCoordinate) + return [self coordinate]; + auto it = m_values.find(type); + return it != m_values.end() ? @(it->second.c_str()) : @""; +} + +- (NSString *)coordinate +{ + BOOL const useDMSFormat = + [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsLatLonAsDMSKey]; + ms::LatLon const latlon = self.latlon; + return @((useDMSFormat ? MeasurementUtils::FormatLatLon(latlon.lat, latlon.lon) + : MeasurementUtils::FormatLatLonAsDMS(latlon.lat, latlon.lon, 2)) + .c_str()); } #pragma mark - Bookmark editing diff --git a/iphone/Maps/Classes/MWMPlacePageInfoCell.mm b/iphone/Maps/Classes/MWMPlacePageInfoCell.mm index 08a48463a2..71c6e1f3b5 100644 --- a/iphone/Maps/Classes/MWMPlacePageInfoCell.mm +++ b/iphone/Maps/Classes/MWMPlacePageInfoCell.mm @@ -8,14 +8,14 @@ #include "platform/settings.hpp" #include "platform/measurement_utils.hpp" -extern NSString * const kUserDefaultsLatLonAsDMSKey; - @interface MWMPlacePageInfoCell () @property (weak, nonatomic, readwrite) IBOutlet UIImageView * icon; @property (weak, nonatomic, readwrite) IBOutlet id textContainer; @property (weak, nonatomic) IBOutlet UIButton * upperButton; +@property (weak, nonatomic) IBOutlet UIImageView * toggleImage; + @property (nonatomic) MWMPlacePageMetadataType type; @end @@ -26,10 +26,7 @@ extern NSString * const kUserDefaultsLatLonAsDMSKey; { [super awakeFromNib]; if ([self.textContainer isKindOfClass:[UITextView class]]) - { - CGFloat const topInset = 12.0; - [self.textContainer setTextContainerInset:{topInset, 0, 0, 0}]; - } + [self.textContainer setTextContainerInset:{.top = 12, 0, 0, 0}]; } - (void)configureWithType:(MWMPlacePageMetadataType)type info:(NSString *)info; @@ -39,21 +36,27 @@ extern NSString * const kUserDefaultsLatLonAsDMSKey; { case MWMPlacePageMetadataTypeURL: case MWMPlacePageMetadataTypeWebsite: + self.toggleImage.hidden = YES; typeName = @"website"; break; case MWMPlacePageMetadataTypeEmail: + self.toggleImage.hidden = YES; typeName = @"email"; break; case MWMPlacePageMetadataTypePhoneNumber: + self.toggleImage.hidden = YES; typeName = @"phone_number"; break; case MWMPlacePageMetadataTypeCoordinate: + self.toggleImage.hidden = NO; typeName = @"coordinate"; break; case MWMPlacePageMetadataTypePostcode: + self.toggleImage.hidden = YES; typeName = @"postcode"; break; case MWMPlacePageMetadataTypeWiFi: + self.toggleImage.hidden = YES; typeName = @"wifi"; break; case MWMPlacePageMetadataTypeBookmark: @@ -109,19 +112,12 @@ extern NSString * const kUserDefaultsLatLonAsDMSKey; break; case MWMPlacePageMetadataTypeCoordinate: [[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatToggleCoordinates)]; + [self.currentEntity toggleCoordinateSystem]; + [self.textContainer setText:[self.currentEntity getValue:MWMPlacePageMetadataTypeCoordinate]]; break; default: break; } - if (self.type != MWMPlacePageMetadataTypeCoordinate) - return; - NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; - BOOL const showLatLonAsDMS = [defaults boolForKey:kUserDefaultsLatLonAsDMSKey]; - [defaults setBool:!showLatLonAsDMS forKey:kUserDefaultsLatLonAsDMSKey]; - [defaults synchronize]; - - // @NOTE: coordinates method depends on kUserDefaultsLatLonAsDMSKey value above. - [self.textContainer setText:[self.currentEntity coordinates]]; } - (void)longTap:(UILongPressGestureRecognizer *)sender diff --git a/iphone/Maps/Classes/MWMPlacePageViewManager.mm b/iphone/Maps/Classes/MWMPlacePageViewManager.mm index cd217b722b..a4fa96ae27 100644 --- a/iphone/Maps/Classes/MWMPlacePageViewManager.mm +++ b/iphone/Maps/Classes/MWMPlacePageViewManager.mm @@ -81,11 +81,9 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) - (void)showPlacePageWithUserMark:(unique_ptr)userMark { - NSAssert(userMark, @"userMark cannot be nil"); + NSAssert(userMark, @"userMark can not be nil."); m_userMark = move(userMark); [[MapsAppDelegate theApp].m_locationManager start:self]; -// [self.entity enableEditing]; - [self reloadPlacePage]; } @@ -258,7 +256,7 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"ppShare"]; MWMPlacePageEntity * entity = self.entity; NSString * title = entity.bookmarkTitle ? entity.bookmarkTitle : entity.title; - CLLocationCoordinate2D const coord = CLLocationCoordinate2DMake(entity.ll.lat, entity.ll.lon); + CLLocationCoordinate2D const coord = CLLocationCoordinate2DMake(entity.latlon.lat, entity.latlon.lon); MWMActivityViewController * shareVC = [MWMActivityViewController shareControllerForLocationTitle:title location:coord diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 8bd9dabe21..1efc397114 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -801,10 +801,8 @@ typedef NS_ENUM(NSUInteger, UserTouchesAction) { self.skipDismissOnViewDisappear = YES; MWMPlacePageEntity * entity = sender; - NSUInteger const timeIndex = [entity.metadataTypes indexOfObject:@(MWMPlacePageMetadataTypeOpenHours)]; - BOOL const haveTime = (timeIndex != NSNotFound); MWMOpeningHoursEditorViewController * dvc = segue.destinationViewController; - dvc.openingHours = haveTime ? entity.metadataValues[timeIndex] : @""; + dvc.openingHours = [entity getValue:MWMPlacePageMetadataTypeOpenHours]; } } diff --git a/iphone/Maps/Classes/PlacePageInfoCell.xib b/iphone/Maps/Classes/PlacePageInfoCell.xib index 71981bda83..805f5b6e63 100644 --- a/iphone/Maps/Classes/PlacePageInfoCell.xib +++ b/iphone/Maps/Classes/PlacePageInfoCell.xib @@ -82,6 +82,7 @@ +