[ios] Refactored place page.

This commit is contained in:
Илья Гречухин 2015-12-28 17:33:10 +03:00 committed by Sergey Yershov
parent b8e1e70264
commit 0714789cb9
12 changed files with 174 additions and 74 deletions

View file

@ -1,5 +1,3 @@
#import <UIKit/UIKit.h>
@class MWMPlacePageEntity, MWMDirectionView;
@interface MWMBasePlacePageView : UIView

View file

@ -5,6 +5,7 @@
#import "MWMPlacePageButtonCell.h"
#import "MWMPlacePageEntity.h"
#import "MWMPlacePageInfoCell.h"
#import "MWMPlacePageOpeningHoursCell.h"
#import "MWMPlacePageTypeDescription.h"
#import "MWMPlacePageViewManager.h"
#import "Statistics.h"
@ -13,6 +14,7 @@ static NSString * const kPlacePageLinkCellIdentifier = @"PlacePageLinkCell";
static NSString * const kPlacePageInfoCellIdentifier = @"PlacePageInfoCell";
static NSString * const kPlacePageBookmarkCellIdentifier = @"PlacePageBookmarkCell";
static NSString * const kPlacePageButtonCellIdentifier = @"MWMPlacePageButtonCell";
static NSString * const kPlacePageOpeningHoursCellIdentifier = @"MWMPlacePageOpeningHoursCell";
static CGFloat const kPlacePageTitleKoefficient = 0.63;
static CGFloat const kLeftOffset = 16.;
@ -21,11 +23,14 @@ static CGFloat const kOffsetFromTitleToDistance = 12.;
static CGFloat const kOffsetFromDistanceToArrow = 8.;
extern CGFloat const kBasePlacePageViewTitleBottomOffset = 2.;
@interface MWMBasePlacePageView ()
@interface MWMBasePlacePageView () <MWMPlacePageOpeningHoursCellProtocol>
@property (weak, nonatomic) MWMPlacePageEntity * entity;
@property (weak, nonatomic) IBOutlet MWMPlacePage * ownerPlacePage;
@property (nonatomic) MWMPlacePageBookmarkCell * bookmarkSizingCell;
@property (nonatomic) MWMPlacePageOpeningHoursCell * openingHoursSizingCell;
@property (nonatomic, readwrite) BOOL openingHoursCellExpanded;
@end
@ -49,6 +54,8 @@ extern CGFloat const kBasePlacePageViewTitleBottomOffset = 2.;
forCellReuseIdentifier:kPlacePageBookmarkCellIdentifier];
[self.featureTable registerNib:[UINib nibWithNibName:kPlacePageButtonCellIdentifier bundle:nil]
forCellReuseIdentifier:kPlacePageButtonCellIdentifier];
[self.featureTable registerNib:[UINib nibWithNibName:kPlacePageOpeningHoursCellIdentifier bundle:nil]
forCellReuseIdentifier:kPlacePageOpeningHoursCellIdentifier];
}
- (void)configureWithEntity:(MWMPlacePageEntity *)entity
@ -211,6 +218,32 @@ extern CGFloat const kBasePlacePageViewTitleBottomOffset = 2.;
[self setNeedsLayout];
}
#pragma mark - MWMPlacePageOpeningHoursCellProtocol
- (void)setOpeningHoursCellExpanded:(BOOL)openingHoursCellExpanded forCell:(UITableViewCell *)cell
{
_openingHoursCellExpanded = openingHoursCellExpanded;
UITableView * tv = self.featureTable;
NSIndexPath * indexPath = [tv indexPathForCell:cell];
[CATransaction begin];
[tv beginUpdates];
[CATransaction setCompletionBlock:^
{
[self setNeedsLayout];
dispatch_async(dispatch_get_main_queue(), ^{ [self.ownerPlacePage refresh]; });
}];
[tv reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[tv endUpdates];
[CATransaction commit];
}
- (void)editPlaceTime
{
[self.ownerPlacePage editPlaceTime];
}
#pragma mark - Properties
- (MWMPlacePageBookmarkCell *)bookmarkSizingCell
{
if (!_bookmarkSizingCell)
@ -220,6 +253,16 @@ extern CGFloat const kBasePlacePageViewTitleBottomOffset = 2.;
return _bookmarkSizingCell;
}
- (MWMPlacePageOpeningHoursCell *)openingHoursSizingCell
{
if (!_openingHoursSizingCell)
_openingHoursSizingCell =
[[[NSBundle mainBundle] loadNibNamed:kPlacePageOpeningHoursCellIdentifier
owner:nil
options:nil] firstObject];
return _openingHoursSizingCell;
}
@end
@implementation MWMBasePlacePageView (UITableView)
@ -232,8 +275,13 @@ extern CGFloat const kBasePlacePageViewTitleBottomOffset = 2.;
if (currentType == MWMPlacePageMetadataTypeBookmark)
{
[self.bookmarkSizingCell config:self.ownerPlacePage forHeight:YES];
CGFloat height = self.bookmarkSizingCell.cellHeight;
return height;
return self.bookmarkSizingCell.cellHeight;
}
else if (currentType == MWMPlacePageMetadataTypeOpenHours)
{
[self.openingHoursSizingCell configWithInfo:self.entity.metadataValues[indexPath.row]
delegate:self];
return self.openingHoursSizingCell.cellHeight;
}
else if (currentType == MWMPlacePageMetadataTypeEditButton)
{
@ -268,6 +316,14 @@ extern CGFloat const kBasePlacePageViewTitleBottomOffset = 2.;
[cell config:self.ownerPlacePage forHeight:NO];
return cell;
}
else if (currentType == MWMPlacePageMetadataTypeOpenHours)
{
MWMPlacePageOpeningHoursCell * cell = (MWMPlacePageOpeningHoursCell *)
[tableView dequeueReusableCellWithIdentifier:kPlacePageOpeningHoursCellIdentifier];
[cell configWithInfo:self.entity.metadataValues[indexPath.row]
delegate:self];
return cell;
}
else if (currentType == MWMPlacePageMetadataTypeEditButton)
{
MWMPlacePageButtonCell * cell = (MWMPlacePageButtonCell *)[tableView dequeueReusableCellWithIdentifier:kPlacePageButtonCellIdentifier];

View file

@ -27,7 +27,8 @@
- (void)changeBookmarkColor;
- (void)changeBookmarkCategory;
- (void)changeBookmarkDescription;
- (void)editPlace;
- (void)editPlaceTime;
- (void)login;
- (void)share;
- (void)route;
- (void)reloadBookmark;
@ -45,6 +46,8 @@
- (void)keyboardWillShow:(NSNotification *)aNotification;
- (void)keyboardWillHide;
- (void)refresh;
- (instancetype)init __attribute__((unavailable("call initWithManager: instead")));
@end

View file

@ -129,9 +129,9 @@ static NSString * const kPlacePageViewCenterKeyPath = @"center";
[self.manager removeBookmark];
}
- (void)editPlace
- (void)editPlaceTime
{
[self.manager editPlace];
[self.manager editPlaceTime];
}
- (void)share
@ -199,7 +199,7 @@ static NSString * const kPlacePageViewCenterKeyPath = @"center";
- (void)willStartEditingBookmarkTitle
{
[[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatRename)];
// This method should be ovverriden.
// This method should be overriden.
}
- (void)willFinishEditingBookmarkTitle:(NSString *)title
@ -210,12 +210,17 @@ static NSString * const kPlacePageViewCenterKeyPath = @"center";
- (IBAction)didTap:(UITapGestureRecognizer *)sender
{
// This method should be ovverriden if you want to process custom tap.
// This method should be overriden if you want to process custom tap.
}
- (IBAction)didPan:(UIPanGestureRecognizer *)sender
{
// This method should be ovverriden if you want to process custom pan.
// This method should be overriden if you want to process custom pan.
}
- (void)refresh
{
// This method should be overriden.
}
#pragma mark - Properties

View file

@ -1,6 +1,6 @@
#import "MWMPlacePage.h"
#import "MWMPlacePageButtonCell.h"
#import "Statistics.h"
#import "MWMPlacePage.h"
@interface MWMPlacePageButtonCell ()
@ -23,7 +23,6 @@
- (IBAction)editPlaceButtonTouchUpIndide
{
[[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatEdit)];
[self.placePage editPlace];
}
@end

View file

@ -3,9 +3,27 @@
#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 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)];
static NSArray * const kPatternTypesArray = @[
@(MWMPlacePageMetadataTypePostcode),
@(MWMPlacePageMetadataTypePhoneNumber),
@(MWMPlacePageMetadataTypeWebsite),
@(MWMPlacePageMetadataTypeURL),
@(MWMPlacePageMetadataTypeEmail),
@(MWMPlacePageMetadataTypeOpenHours),
@(MWMPlacePageMetadataTypeWiFi),
@(MWMPlacePageMetadataTypeCoordinate)
];
using feature::Metadata;
@ -184,9 +202,7 @@ using feature::Metadata;
case Metadata::FMD_INTERNET:
{
NSString * v;
if (type == Metadata::EType::FMD_OPEN_HOURS)
v = [self formattedOpenHoursFromString:metadata.Get(type)];
else if (type == Metadata::FMD_INTERNET)
if (type == Metadata::FMD_INTERNET)
v = L(@"WiFi_available");
else
v = @(metadata.Get(type).c_str());
@ -344,23 +360,4 @@ using feature::Metadata;
category->SaveToKMLFile();
}
#pragma mark - Open hours string formatter
- (NSString *)formattedOpenHoursFromString:(string const &)s
{
//TODO (Vlad): Not the best solution, but this function is temporary and will be replaced in future.
NSMutableString * r = [NSMutableString stringWithUTF8String:s.c_str()];
[r replaceOccurrencesOfString:@"," withString:@", " options:NSCaseInsensitiveSearch range:NSMakeRange(0, r.length)];
while (YES)
{
NSRange const range = [r rangeOfString:@" "];
if (range.location == NSNotFound)
break;
[r replaceCharactersInRange:range withString:@" "];
}
[r replaceOccurrencesOfString:@"; " withString:@"\n" options:NSCaseInsensitiveSearch range:NSMakeRange(0, r.length)];
[r replaceOccurrencesOfString:@";" withString:@"\n" options:NSCaseInsensitiveSearch range:NSMakeRange(0, r.length)];
return r.copy;
}
@end

View file

@ -22,9 +22,19 @@ extern NSString * const kUserDefaultsLatLonAsDMSKey;
@implementation MWMPlacePageInfoCell
- (void)awakeFromNib
{
[super awakeFromNib];
if ([self.textContainer isKindOfClass:[UITextView class]])
{
CGFloat const topInset = 12.0;
[self.textContainer setTextContainerInset:{topInset, 0, 0, 0}];
}
}
- (void)configureWithType:(MWMPlacePageMetadataType)type info:(NSString *)info;
{
NSString * typeName = nil;
NSString * typeName;
switch (type)
{
case MWMPlacePageMetadataTypeURL:
@ -43,25 +53,27 @@ extern NSString * const kUserDefaultsLatLonAsDMSKey;
case MWMPlacePageMetadataTypePostcode:
typeName = @"postcode";
break;
case MWMPlacePageMetadataTypeOpenHours:
typeName = @"open_hours";
break;
case MWMPlacePageMetadataTypeWiFi:
typeName = @"wifi";
break;
case MWMPlacePageMetadataTypeBookmark:
case MWMPlacePageMetadataTypeEditButton:
case MWMPlacePageMetadataTypeOpenHours:
NSAssert(false, @"Incorrect type!");
break;
}
UIImage * image = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@", @"ic_placepage_", typeName]];
UIImage * image =
[UIImage imageNamed:[NSString stringWithFormat:@"%@%@", @"ic_placepage_", typeName]];
self.type = type;
self.icon.image = image;
if ([self.textContainer isKindOfClass:[UITextView class]])
{
[self.textContainer setAttributedText:[[NSAttributedString alloc] initWithString:info attributes:@{NSFontAttributeName : [UIFont light16]}]];
[self.textContainer
setAttributedText:[[NSAttributedString alloc]
initWithString:info
attributes:@{NSFontAttributeName : [UIFont regular17]}]];
self.icon.mwm_coloring = MWMImageColoringBlue;
}
else
@ -70,7 +82,8 @@ extern NSString * const kUserDefaultsLatLonAsDMSKey;
self.icon.mwm_coloring = MWMImageColoringBlack;
}
UILongPressGestureRecognizer * longTap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTap:)];
UILongPressGestureRecognizer * longTap =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTap:)];
longTap.minimumPressDuration = 0.3;
[self.upperButton addGestureRecognizer:longTap];
}
@ -80,15 +93,6 @@ extern NSString * const kUserDefaultsLatLonAsDMSKey;
return YES;
}
- (void)layoutSubviews
{
CGFloat const leftOffset = 16.;
CGFloat const topOffset = 8.;
CGFloat const textOffset= 60.;
self.icon.origin = {leftOffset, topOffset};
[self.textContainer setMinX:textOffset];
}
- (IBAction)cellTap
{
switch (self.type)

View file

@ -16,6 +16,7 @@
- (instancetype)initWithViewController:(UIViewController *)viewController
delegate:(id<MWMPlacePageViewManagerProtocol>)delegate;
- (void)showPlacePageWithUserMark:(unique_ptr<UserMarkCopy>)userMark;
- (void)reloadPlacePage;
- (void)refreshPlacePage;
- (void)refresh;
- (BOOL)hasPlacePage;
@ -25,7 +26,7 @@
- (void)routeFrom;
- (void)routeTo;
- (void)share;
- (void)editPlace;
- (void)editPlaceTime;
- (void)addBookmark;
- (void)removeBookmark;
- (void)apiBack;

View file

@ -3,6 +3,7 @@
#import "MapsAppDelegate.h"
#import "MWMActivityViewController.h"
#import "MWMAPIBar.h"
#import "MWMAuthorizationCommon.h"
#import "MWMBasePlacePageView.h"
#import "MWMDirectionView.h"
#import "MWMiPadPlacePage.h"
@ -83,10 +84,16 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState)
NSAssert(userMark, @"userMark cannot be nil");
m_userMark = move(userMark);
[[MapsAppDelegate theApp].m_locationManager start:self];
// [self.entity enableEditing];
[self reloadPlacePage];
}
- (void)reloadPlacePage
{
if (!m_userMark)
return;
self.entity = [[MWMPlacePageEntity alloc] initWithUserMark:m_userMark->GetUserMark()];
[self.entity enableEditing];
self.state = MWMPlacePageManagerStateOpen;
if (IPAD)
[self setPlacePageForiPad];
@ -277,9 +284,23 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState)
m_userMark.reset(new UserMarkCopy(bookmark, false));
}
- (void)editPlace
- (void)editPlaceTime
{
[self.ownerViewController performSegueWithIdentifier:@"Map2PlacePageEditor" sender:self.entity];
NSUserDefaults * ud = [NSUserDefaults standardUserDefaults];
NSString * username = [ud stringForKey:kOSMUsernameKey];
NSString * password = [ud stringForKey:kOSMPasswordKey];
if (!username || !password)
{
[[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatEditTime)
withParameters:@{kStatValue : kStatAuthorization}];
[self.ownerViewController performSegueWithIdentifier:@"Map2Login" sender:nil];
}
else
{
[[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatEditTime)
withParameters:@{kStatValue : kStatEdit}];
[self.ownerViewController performSegueWithIdentifier:@"Map2OpeningHoursEditor" sender:self.entity];
}
}
- (void)addBookmark

View file

@ -210,18 +210,23 @@ static CGFloat const kKeyboardOffset = 12.;
- (void)addBookmark
{
[super addBookmark];
[self updatePlacePageLayoutAnimated:YES];
[self refresh];
}
- (void)removeBookmark
{
[super removeBookmark];
[self updatePlacePageLayoutAnimated:YES];
[self refresh];
}
- (void)reloadBookmark
{
[super reloadBookmark];
[self refresh];
}
- (void)refresh
{
[self updatePlacePageLayoutAnimated:YES];
}
@ -316,13 +321,13 @@ static CGFloat const kKeyboardOffset = 12.;
- (void)keyboardWillShow:(NSNotification *)aNotification
{
[super keyboardWillShow:aNotification];
[self updatePlacePageLayoutAnimated:YES];
[self refresh];
}
- (void)keyboardWillHide
{
[super keyboardWillHide];
[self updatePlacePageLayoutAnimated:YES];
[self refresh];
}
- (CGFloat)getAvailableHeight

View file

@ -33,7 +33,7 @@ typedef NS_ENUM(NSUInteger, MWMiPhoneLandscapePlacePageState)
[super configure];
self.anchorImageView.backgroundColor = [UIColor white];
self.anchorImageView.image = nil;
[self configureContentInset];
[self refresh];
[self addPlacePageShadowToView:self.extendedPlacePageView offset:CGSizeMake(2.0, 4.0)];
[self.extendedPlacePageView addSubview:self.actionBar];
[self.manager addSubviews:@[self.extendedPlacePageView] withNavigationController:nil];
@ -84,18 +84,23 @@ typedef NS_ENUM(NSUInteger, MWMiPhoneLandscapePlacePageState)
- (void)addBookmark
{
[super addBookmark];
[self configureContentInset];
[self refresh];
}
- (void)removeBookmark
{
[super removeBookmark];
[self configureContentInset];
[self refresh];
}
- (void)reloadBookmark
{
[super reloadBookmark];
[self refresh];
}
- (void)refresh
{
[self configureContentInset];
}
@ -136,9 +141,9 @@ typedef NS_ENUM(NSUInteger, MWMiPhoneLandscapePlacePageState)
{
[super willStartEditingBookmarkTitle];
CGFloat const statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
MWMBasePlacePageView const * basePlacePageView = self.basePlacePageView;
UITableView const * tableView = basePlacePageView.featureTable;
CGFloat const baseViewHeight = basePlacePageView.height;
MWMBasePlacePageView * basePPV = self.basePlacePageView;
UITableView const * tableView = basePPV.featureTable;
CGFloat const baseViewHeight = basePPV.height;
CGFloat const tableHeight = tableView.contentSize.height;
CGFloat const headerViewHeight = baseViewHeight - tableHeight;
CGFloat const titleOriginY = tableHeight - kBookmarkCellHeight - tableView.contentOffset.y;
@ -180,7 +185,7 @@ typedef NS_ENUM(NSUInteger, MWMiPhoneLandscapePlacePageState)
self.actionBar.frame = {{0, height - actionBarHeight}, {width, actionBarHeight}};
if (self.state == MWMiPhoneLandscapePlacePageStateOpen)
[self updateTargetPoint];
[self configureContentInset];
[self refresh];
}
- (void)setTargetPoint:(CGPoint)targetPoint

View file

@ -95,19 +95,24 @@ typedef NS_ENUM(NSUInteger, MWMiPhonePortraitPlacePageState)
- (void)reloadBookmark
{
[super reloadBookmark];
[self updateTargetPoint];
[self refresh];
}
- (void)updateMyPositionStatus:(NSString *)status
{
[super updateMyPositionStatus:status];
[self refresh];
}
- (void)refresh
{
[self updateTargetPoint];
}
- (void)setState:(MWMiPhonePortraitPlacePageState)state
{
_state = state;
[self updateTargetPoint];
[self refresh];
switch (state)
{
case MWMiPhonePortraitPlacePageStateClosed:
@ -116,6 +121,7 @@ typedef NS_ENUM(NSUInteger, MWMiPhonePortraitPlacePageState)
[self.manager.ownerViewController.view endEditing:YES];
break;
case MWMiPhonePortraitPlacePageStatePreview:
self.isHover = NO;
[MWMPlacePageNavigationBar remove];
[self.manager.ownerViewController.view endEditing:YES];
break;
@ -299,7 +305,7 @@ typedef NS_ENUM(NSUInteger, MWMiPhonePortraitPlacePageState)
- (void)willFinishEditingBookmarkTitle:(NSString *)title
{
[super willFinishEditingBookmarkTitle:title];
[self updateTargetPoint];
[self refresh];
}
- (void)setAnchorImage