diff --git a/iphone/Maps/Classes/MWMBasePlacePageView.mm b/iphone/Maps/Classes/MWMBasePlacePageView.mm index 32e2684101..e37c564e85 100644 --- a/iphone/Maps/Classes/MWMBasePlacePageView.mm +++ b/iphone/Maps/Classes/MWMBasePlacePageView.mm @@ -2,6 +2,7 @@ #import "MWMPlacePage.h" #import "MWMPlacePageActionBar.h" #import "MWMPlacePageBookmarkCell.h" +#import "MWMPlacePageButtonCell.h" #import "MWMPlacePageEntity.h" #import "MWMPlacePageInfoCell.h" #import "MWMPlacePageTypeDescription.h" @@ -11,6 +12,7 @@ static NSString * const kPlacePageLinkCellIdentifier = @"PlacePageLinkCell"; static NSString * const kPlacePageInfoCellIdentifier = @"PlacePageInfoCell"; static NSString * const kPlacePageBookmarkCellIdentifier = @"PlacePageBookmarkCell"; +static NSString * const kPlacePageButtonCellIdentifier = @"MWMPlacePageButtonCell"; static CGFloat const kPlacePageTitleKoefficient = 0.63; static CGFloat const kLeftOffset = 16.; @@ -45,6 +47,8 @@ extern CGFloat const kBasePlacePageViewTitleBottomOffset = 2.; forCellReuseIdentifier:kPlacePageLinkCellIdentifier]; [self.featureTable registerNib:[UINib nibWithNibName:kPlacePageBookmarkCellIdentifier bundle:nil] forCellReuseIdentifier:kPlacePageBookmarkCellIdentifier]; + [self.featureTable registerNib:[UINib nibWithNibName:kPlacePageButtonCellIdentifier bundle:nil] + forCellReuseIdentifier:kPlacePageButtonCellIdentifier]; } - (void)configureWithEntity:(MWMPlacePageEntity *)entity @@ -210,7 +214,9 @@ extern CGFloat const kBasePlacePageViewTitleBottomOffset = 2.; - (MWMPlacePageBookmarkCell *)bookmarkSizingCell { if (!_bookmarkSizingCell) - _bookmarkSizingCell = [self.featureTable dequeueReusableCellWithIdentifier:kPlacePageBookmarkCellIdentifier]; + _bookmarkSizingCell = [[[NSBundle mainBundle] loadNibNamed:kPlacePageBookmarkCellIdentifier + owner:nil + options:nil] firstObject]; return _bookmarkSizingCell; } @@ -220,13 +226,19 @@ extern CGFloat const kBasePlacePageViewTitleBottomOffset = 2.; - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - NSNumber * const currentType = self.entity.metadataTypes[indexPath.row]; - if (currentType.integerValue == MWMPlacePageMetadataTypeBookmark) + + MWMPlacePageMetadataType currentType = (MWMPlacePageMetadataType)[self.entity.metadataTypes[indexPath.row] integerValue]; + + if (currentType == MWMPlacePageMetadataTypeBookmark) { [self.bookmarkSizingCell config:self.ownerPlacePage forHeight:YES]; CGFloat height = self.bookmarkSizingCell.cellHeight; return height; } + else if (currentType == MWMPlacePageMetadataTypeEditButton) + { + return [MWMPlacePageButtonCell height]; + } CGFloat const defaultCellHeight = 44.; CGFloat const defaultWidth = tableView.width; @@ -256,6 +268,12 @@ extern CGFloat const kBasePlacePageViewTitleBottomOffset = 2.; [cell config:self.ownerPlacePage forHeight:NO]; return cell; } + else if (currentType == MWMPlacePageMetadataTypeEditButton) + { + MWMPlacePageButtonCell * cell = (MWMPlacePageButtonCell *)[tableView dequeueReusableCellWithIdentifier:kPlacePageButtonCellIdentifier]; + [cell config:self.ownerPlacePage]; + return cell; + } BOOL const isLinkTypeCell = (currentType == MWMPlacePageMetadataTypePhoneNumber || currentType == MWMPlacePageMetadataTypeEmail || currentType == MWMPlacePageMetadataTypeWebsite || currentType == MWMPlacePageMetadataTypeURL); NSString * const cellIdentifier = isLinkTypeCell ? kPlacePageLinkCellIdentifier : kPlacePageInfoCellIdentifier; diff --git a/iphone/Maps/Classes/MWMPlacePage.h b/iphone/Maps/Classes/MWMPlacePage.h index 76e33ae758..ddc0a8f9b7 100644 --- a/iphone/Maps/Classes/MWMPlacePage.h +++ b/iphone/Maps/Classes/MWMPlacePage.h @@ -27,6 +27,7 @@ - (void)changeBookmarkColor; - (void)changeBookmarkCategory; - (void)changeBookmarkDescription; +- (void)editPlace; - (void)share; - (void)route; - (void)reloadBookmark; diff --git a/iphone/Maps/Classes/MWMPlacePage.mm b/iphone/Maps/Classes/MWMPlacePage.mm index 9adaab921c..b16fd545e7 100644 --- a/iphone/Maps/Classes/MWMPlacePage.mm +++ b/iphone/Maps/Classes/MWMPlacePage.mm @@ -129,6 +129,11 @@ static NSString * const kPlacePageViewCenterKeyPath = @"center"; [self.manager removeBookmark]; } +- (void)editPlace +{ + [self.manager editPlace]; +} + - (void)share { [self.manager share]; diff --git a/iphone/Maps/Classes/MWMPlacePageBookmarkCell.mm b/iphone/Maps/Classes/MWMPlacePageBookmarkCell.mm index f8b4fb77ab..762bed3a4b 100644 --- a/iphone/Maps/Classes/MWMPlacePageBookmarkCell.mm +++ b/iphone/Maps/Classes/MWMPlacePageBookmarkCell.mm @@ -134,21 +134,21 @@ static NSUInteger sWebViewHeight = 0; - (IBAction)colorPickerButtonTap { [self.placePage changeBookmarkColor]; - [self.title resignFirstResponder]; + [self endEditing:YES]; } - (IBAction)categoryButtonTap { [[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatChangeBookmarkGroup)]; [self.placePage changeBookmarkCategory]; - [self.title resignFirstResponder]; + [self endEditing:YES]; } - (IBAction)editTap { [[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatChangeBookmarkDescription)]; [self.placePage changeBookmarkDescription]; - [self.title resignFirstResponder]; + [self endEditing:YES]; } - (MWMPlacePageEntity *)entity diff --git a/iphone/Maps/Classes/MWMPlacePageButtonCell.h b/iphone/Maps/Classes/MWMPlacePageButtonCell.h new file mode 100644 index 0000000000..260c710133 --- /dev/null +++ b/iphone/Maps/Classes/MWMPlacePageButtonCell.h @@ -0,0 +1,9 @@ +@class MWMPlacePage; + +@interface MWMPlacePageButtonCell : UITableViewCell + ++ (CGFloat)height; + +- (void)config:(MWMPlacePage *)placePage; + +@end diff --git a/iphone/Maps/Classes/MWMPlacePageButtonCell.mm b/iphone/Maps/Classes/MWMPlacePageButtonCell.mm new file mode 100644 index 0000000000..d6373b7727 --- /dev/null +++ b/iphone/Maps/Classes/MWMPlacePageButtonCell.mm @@ -0,0 +1,29 @@ +#import "MWMPlacePageButtonCell.h" +#import "Statistics.h" +#import "MWMPlacePage.h" + +@interface MWMPlacePageButtonCell () + +@property (weak, nonatomic) MWMPlacePage * placePage; + +@end + +@implementation MWMPlacePageButtonCell + ++ (CGFloat)height +{ + return 44.0; +} + +- (void)config:(MWMPlacePage *)placePage +{ + self.placePage = placePage; +} + +- (IBAction)editPlaceButtonTouchUpIndide +{ + [[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatEdit)]; + [self.placePage editPlace]; +} + +@end diff --git a/iphone/Maps/Classes/MWMPlacePageEntity.h b/iphone/Maps/Classes/MWMPlacePageEntity.h index 82e6e73625..a22f27bf0a 100644 --- a/iphone/Maps/Classes/MWMPlacePageEntity.h +++ b/iphone/Maps/Classes/MWMPlacePageEntity.h @@ -14,7 +14,8 @@ typedef NS_ENUM (NSUInteger, MWMPlacePageMetadataType) MWMPlacePageMetadataTypeOpenHours, MWMPlacePageMetadataTypeCoordinate, MWMPlacePageMetadataTypeWiFi, - MWMPlacePageMetadataTypeBookmark + MWMPlacePageMetadataTypeBookmark, + MWMPlacePageMetadataTypeEditButton }; typedef NS_ENUM (NSUInteger, MWMPlacePageEntityType) @@ -49,6 +50,7 @@ typedef NS_ENUM (NSUInteger, MWMPlacePageEntityType) - (NSArray *)metadataTypes; - (NSArray *)metadataValues; +- (void)enableEditing; - (void)insertBookmarkInTypes; - (void)removeBookmarkFromTypes; diff --git a/iphone/Maps/Classes/MWMPlacePageEntity.mm b/iphone/Maps/Classes/MWMPlacePageEntity.mm index 8a8779b86b..fd5bd99ddc 100644 --- a/iphone/Maps/Classes/MWMPlacePageEntity.mm +++ b/iphone/Maps/Classes/MWMPlacePageEntity.mm @@ -7,14 +7,12 @@ extern NSArray * const kBookmarkColorsVariant = @[@"placemark-red", @"placemark- extern NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; static NSArray * const kPatternTypesArray = @[@(MWMPlacePageMetadataTypePostcode), @(MWMPlacePageMetadataTypePhoneNumber), @(MWMPlacePageMetadataTypeWebsite), @(MWMPlacePageMetadataTypeURL), @(MWMPlacePageMetadataTypeEmail), @(MWMPlacePageMetadataTypeOpenHours), @(MWMPlacePageMetadataTypeWiFi), @(MWMPlacePageMetadataTypeCoordinate)]; -static NSString * const kTypesKey = @"types"; -static NSString * const kValuesKey = @"values"; - using feature::Metadata; @interface MWMPlacePageEntity () -@property (nonatomic) NSDictionary * metadata; +@property (nonatomic) NSMutableArray * metaTypes; +@property (nonatomic) NSMutableArray * metaValues; @end @@ -24,7 +22,11 @@ using feature::Metadata; { self = [super init]; if (self) + { + self.metaTypes = [NSMutableArray array]; + self.metaValues = [NSMutableArray array]; [self configureWithUserMark:mark]; + } return self; } @@ -107,14 +109,10 @@ using feature::Metadata; { self.title = L(@"my_position"); self.type = MWMPlacePageEntityTypeMyPosition; - NSMutableArray * types = [NSMutableArray array]; - NSMutableArray * values = [NSMutableArray array]; - [types addObject:kPatternTypesArray.lastObject]; + [self.metaTypes addObject:kPatternTypesArray.lastObject]; BOOL const isLatLonAsDMS = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsLatLonAsDMSKey]; NSString * latLonStr = isLatLonAsDMS ? @(MeasurementUtils::FormatLatLonAsDMS(self.point.x, self.point.y, 2).c_str()): @( MeasurementUtils::FormatLatLon(self.point.x, self.point.y).c_str()); - [values addObject:latLonStr]; - - self.metadata = @{kTypesKey : types, kValuesKey : values}; + [self.metaValues addObject:latLonStr]; } - (void)configureForApi:(ApiMarkPoint const *)apiMark @@ -122,14 +120,11 @@ using feature::Metadata; self.type = MWMPlacePageEntityTypeAPI; self.title = @(apiMark->GetName().c_str()); self.category = @(GetFramework().GetApiDataHolder().GetAppTitle().c_str()); - NSMutableArray const * types = [NSMutableArray array]; - NSMutableArray const * values = [NSMutableArray array]; - [types addObject:kPatternTypesArray.lastObject]; + [self.metaTypes addObject:kPatternTypesArray.lastObject]; BOOL const isLatLonAsDMS = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsLatLonAsDMSKey]; NSString * latLonStr = isLatLonAsDMS ? @(MeasurementUtils::FormatLatLonAsDMS(self.point.x, self.point.y, 2).c_str()) : @(MeasurementUtils::FormatLatLon(self.point.x, self.point.y).c_str()); latLonStr = isLatLonAsDMS ? @(MeasurementUtils::FormatLatLonAsDMS(self.point.x, self.point.y, 2).c_str()) : @(MeasurementUtils::FormatLatLon(self.point.x, self.point.y).c_str()); - [values addObject:latLonStr]; - self.metadata = @{kTypesKey : types, kValuesKey : values}; + [self.metaValues addObject:latLonStr]; } - (void)configureEntityWithMetadata:(Metadata const &)metadata addressInfo:(search::AddressInfo const &)info @@ -140,9 +135,6 @@ using feature::Metadata; auto const presentTypes = metadata.GetPresentTypes(); - NSMutableArray const * types = [NSMutableArray array]; - NSMutableArray const * values = [NSMutableArray array]; - for (auto const & type : presentTypes) { switch (type) @@ -207,8 +199,8 @@ using feature::Metadata; v = @(metadata.Get(type).c_str()); NSNumber const * t = [self typeFromMetadata:type]; - [types addObject:t]; - [values addObject:v]; + [self.metaTypes addObject:t]; + [self.metaValues addObject:v]; break; } @@ -220,43 +212,48 @@ using feature::Metadata; NSUInteger swappedIndex = 0; for (NSNumber * pattern in kPatternTypesArray) { - NSUInteger const index = [types indexOfObject:pattern]; + NSUInteger const index = [self.metaTypes indexOfObject:pattern]; if (index == NSNotFound) continue; - [types exchangeObjectAtIndex:index withObjectAtIndex:swappedIndex]; - [values exchangeObjectAtIndex:index withObjectAtIndex:swappedIndex]; + [self.metaTypes exchangeObjectAtIndex:index withObjectAtIndex:swappedIndex]; + [self.metaValues exchangeObjectAtIndex:index withObjectAtIndex:swappedIndex]; swappedIndex++; } - [types addObject:kPatternTypesArray.lastObject]; + [self.metaTypes addObject:kPatternTypesArray.lastObject]; BOOL const isLatLonAsDMS = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsLatLonAsDMSKey]; NSString * latLonStr = isLatLonAsDMS ? @(MeasurementUtils::FormatLatLonAsDMS(self.point.x, self.point.y, 2).c_str()) : @( MeasurementUtils::FormatLatLon(self.point.x, self.point.y).c_str()); latLonStr = isLatLonAsDMS ? @(MeasurementUtils::FormatLatLonAsDMS(self.point.x, self.point.y, 2).c_str()) : @( MeasurementUtils::FormatLatLon(self.point.x, self.point.y).c_str()); - [values addObject:latLonStr]; - - self.metadata = @{kTypesKey : types, kValuesKey : values}; + [self.metaValues addObject:latLonStr]; } - (NSArray *)metadataTypes { - return (NSArray *)self.metadata[kTypesKey]; + return (NSArray *)self.metaTypes; } - (NSArray *)metadataValues { - return (NSArray *)self.metadata[kValuesKey]; + return (NSArray *)self.metaValues; +} + +- (void)enableEditing +{ + NSNumber * editType = @(MWMPlacePageMetadataTypeEditButton); + if (![self.metaTypes containsObject:editType]) + [self.metaTypes addObject:editType]; } - (void)insertBookmarkInTypes { - if ([self.metadataTypes containsObject:@(MWMPlacePageMetadataTypeBookmark)]) - return; - [self.metadata[kTypesKey] insertObject:@(MWMPlacePageMetadataTypeBookmark) atIndex:self.metadataTypes.count]; + NSNumber * bookmarkType = @(MWMPlacePageMetadataTypeBookmark); + if (![self.metaTypes containsObject:bookmarkType]) + [self.metaTypes addObject:bookmarkType]; } - (void)removeBookmarkFromTypes { - [self.metadata[kTypesKey] removeObject:@(MWMPlacePageMetadataTypeBookmark)]; + [self.metaTypes removeObject:@(MWMPlacePageMetadataTypeBookmark)]; } - (NSNumber *)typeFromMetadata:(uint8_t)type diff --git a/iphone/Maps/Classes/MWMPlacePageInfoCell.mm b/iphone/Maps/Classes/MWMPlacePageInfoCell.mm index 2d2e42eb28..50619edc54 100644 --- a/iphone/Maps/Classes/MWMPlacePageInfoCell.mm +++ b/iphone/Maps/Classes/MWMPlacePageInfoCell.mm @@ -50,6 +50,7 @@ extern NSString * const kUserDefaultsLatLonAsDMSKey; typeName = @"wifi"; break; case MWMPlacePageMetadataTypeBookmark: + case MWMPlacePageMetadataTypeEditButton: NSAssert(false, @"Incorrect type!"); break; } diff --git a/iphone/Maps/Classes/MWMPlacePageViewManager.h b/iphone/Maps/Classes/MWMPlacePageViewManager.h index 901d66844d..56040ba449 100644 --- a/iphone/Maps/Classes/MWMPlacePageViewManager.h +++ b/iphone/Maps/Classes/MWMPlacePageViewManager.h @@ -25,6 +25,7 @@ - (void)routeFrom; - (void)routeTo; - (void)share; +- (void)editPlace; - (void)addBookmark; - (void)removeBookmark; - (void)apiBack; diff --git a/iphone/Maps/Classes/MWMPlacePageViewManager.mm b/iphone/Maps/Classes/MWMPlacePageViewManager.mm index c89af38d97..74a3cc678d 100644 --- a/iphone/Maps/Classes/MWMPlacePageViewManager.mm +++ b/iphone/Maps/Classes/MWMPlacePageViewManager.mm @@ -84,6 +84,9 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) m_userMark = move(userMark); [[MapsAppDelegate theApp].m_locationManager start:self]; self.entity = [[MWMPlacePageEntity alloc] initWithUserMark:m_userMark->GetUserMark()]; + + [self.entity enableEditing]; + self.state = MWMPlacePageManagerStateOpen; if (IPAD) [self setPlacePageForiPad]; @@ -274,6 +277,11 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) m_userMark.reset(new UserMarkCopy(bookmark, false)); } +- (void)editPlace +{ + [self.ownerViewController performSegueWithIdentifier:@"Map2PlacePageEditor" sender:self.entity]; +} + - (void)addBookmark { [[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatBookmarks)