forked from organicmaps/organicmaps
[ios] Added "edit" button to place page.
This commit is contained in:
parent
b367434083
commit
cd38dda713
11 changed files with 111 additions and 40 deletions
|
@ -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;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
- (void)changeBookmarkColor;
|
||||
- (void)changeBookmarkCategory;
|
||||
- (void)changeBookmarkDescription;
|
||||
- (void)editPlace;
|
||||
- (void)share;
|
||||
- (void)route;
|
||||
- (void)reloadBookmark;
|
||||
|
|
|
@ -129,6 +129,11 @@ static NSString * const kPlacePageViewCenterKeyPath = @"center";
|
|||
[self.manager removeBookmark];
|
||||
}
|
||||
|
||||
- (void)editPlace
|
||||
{
|
||||
[self.manager editPlace];
|
||||
}
|
||||
|
||||
- (void)share
|
||||
{
|
||||
[self.manager share];
|
||||
|
|
|
@ -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
|
||||
|
|
9
iphone/Maps/Classes/MWMPlacePageButtonCell.h
Normal file
9
iphone/Maps/Classes/MWMPlacePageButtonCell.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
@class MWMPlacePage;
|
||||
|
||||
@interface MWMPlacePageButtonCell : UITableViewCell
|
||||
|
||||
+ (CGFloat)height;
|
||||
|
||||
- (void)config:(MWMPlacePage *)placePage;
|
||||
|
||||
@end
|
29
iphone/Maps/Classes/MWMPlacePageButtonCell.mm
Normal file
29
iphone/Maps/Classes/MWMPlacePageButtonCell.mm
Normal file
|
@ -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
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -50,6 +50,7 @@ extern NSString * const kUserDefaultsLatLonAsDMSKey;
|
|||
typeName = @"wifi";
|
||||
break;
|
||||
case MWMPlacePageMetadataTypeBookmark:
|
||||
case MWMPlacePageMetadataTypeEditButton:
|
||||
NSAssert(false, @"Incorrect type!");
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
- (void)routeFrom;
|
||||
- (void)routeTo;
|
||||
- (void)share;
|
||||
- (void)editPlace;
|
||||
- (void)addBookmark;
|
||||
- (void)removeBookmark;
|
||||
- (void)apiBack;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue