From 7ff4a12a43862c560fd9f48a008160f86e8b1647 Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Fri, 2 Oct 2015 18:09:20 +0300 Subject: [PATCH] [ios] Updated place page for bottom menu support. --- .../MWMMapViewControlsManager.mm | 2 +- iphone/Maps/Classes/MWMBasePlacePageView.mm | 7 ++-- .../Maps/Classes/MWMExtendedPlacePageView.h | 4 +- iphone/Maps/Classes/MWMPlacePage.h | 1 + iphone/Maps/Classes/MWMPlacePage.mm | 41 ++++++++++++++++--- iphone/Maps/Classes/MWMPlacePageActionBar.h | 2 + iphone/Maps/Classes/MWMPlacePageActionBar.mm | 1 - iphone/Maps/Classes/MWMPlacePageViewManager.h | 3 +- .../Maps/Classes/MWMPlacePageViewManager.mm | 23 +++++++---- .../Classes/MWMPlacePageViewManagerDelegate.h | 2 +- iphone/Maps/Classes/MWMiPadPlacePage.mm | 5 +++ .../Classes/MWMiPhoneLandscapePlacePage.mm | 35 ++++++++++++---- .../Classes/MWMiPhonePortraitPlacePage.mm | 31 ++++---------- 13 files changed, 102 insertions(+), 55 deletions(-) diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm index 817fbc3dd9..a56dee54d3 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm @@ -97,7 +97,7 @@ extern NSString * const kAlohalyticsTapEventKey; - (void)dismissPlacePage { - [self.placePageManager dismissPlacePage]; + [self.placePageManager hidePlacePage]; } - (void)showPlacePageWithUserMark:(unique_ptr)userMark diff --git a/iphone/Maps/Classes/MWMBasePlacePageView.mm b/iphone/Maps/Classes/MWMBasePlacePageView.mm index 1df0795d6e..1f020349a7 100644 --- a/iphone/Maps/Classes/MWMBasePlacePageView.mm +++ b/iphone/Maps/Classes/MWMBasePlacePageView.mm @@ -48,12 +48,12 @@ extern CGFloat const kBookmarkCellHeight = 135.; if (type == MWMPlacePageEntityTypeBookmark) { self.titleLabel.text = entity.bookmarkTitle.length > 0 ? entity.bookmarkTitle : entity.title; - self.typeLabel.text = entity.bookmarkCategory; + self.typeLabel.text = [entity.bookmarkCategory capitalizedString]; } else { self.titleLabel.text = entity.title; - self.typeLabel.text = entity.category; + self.typeLabel.text = [entity.category capitalizedString]; } BOOL const isMyPosition = type == MWMPlacePageEntityTypeMyPosition; @@ -149,9 +149,9 @@ static CGFloat const kTitleBottomOffset = 2.; - (void)addBookmark { + self.entity.type = MWMPlacePageEntityTypeBookmark; [self.typeDescriptionView removeFromSuperview]; self.typeDescriptionView = nil; - self.typeLabel.text = self.entity.bookmarkCategory; [self.typeLabel sizeToFit]; [self.entity insertBookmarkInTypes]; [self configure]; @@ -159,6 +159,7 @@ static CGFloat const kTitleBottomOffset = 2.; - (void)removeBookmark { + self.entity.type = MWMPlacePageEntityTypeRegular; [self.entity removeBookmarkFromTypes]; [self configure]; } diff --git a/iphone/Maps/Classes/MWMExtendedPlacePageView.h b/iphone/Maps/Classes/MWMExtendedPlacePageView.h index ff71cb408d..59143b9e2e 100644 --- a/iphone/Maps/Classes/MWMExtendedPlacePageView.h +++ b/iphone/Maps/Classes/MWMExtendedPlacePageView.h @@ -1,5 +1,3 @@ -#import - -@interface MWMExtendedPlacePageView : UIView +@interface MWMExtendedPlacePageView : SolidTouchView @end diff --git a/iphone/Maps/Classes/MWMPlacePage.h b/iphone/Maps/Classes/MWMPlacePage.h index 4c274aa090..1cecf32f0b 100644 --- a/iphone/Maps/Classes/MWMPlacePage.h +++ b/iphone/Maps/Classes/MWMPlacePage.h @@ -17,6 +17,7 @@ - (instancetype)initWithManager:(MWMPlacePageViewManager *)manager; - (void)show; +- (void)hide; - (void)dismiss; - (void)configure; diff --git a/iphone/Maps/Classes/MWMPlacePage.mm b/iphone/Maps/Classes/MWMPlacePage.mm index 9c879bf75d..6ce2696f95 100644 --- a/iphone/Maps/Classes/MWMPlacePage.mm +++ b/iphone/Maps/Classes/MWMPlacePage.mm @@ -1,17 +1,18 @@ -#import "MWMPlacePage.h" #import "MWMBasePlacePageView.h" +#import "MWMBookmarkColorViewController.h" +#import "MWMBookmarkDescriptionViewController.h" +#import "MWMDirectionView.h" +#import "MWMPlacePage.h" +#import "MWMPlacePageActionBar.h" #import "MWMPlacePageEntity.h" #import "MWMPlacePageViewManager.h" -#import "MWMPlacePageActionBar.h" -#import "MWMDirectionView.h" -#import "MWMBookmarkColorViewController.h" #import "SelectSetVC.h" -#import "MWMBookmarkDescriptionViewController.h" #import "../../3party/Alohalytics/src/alohalytics_objc.h" static NSString * const kPlacePageNibIdentifier = @"PlacePageView"; extern NSString * const kAlohalyticsTapEventKey; +static NSString * const kPlacePageViewCenterKeyPath = @"center"; @interface MWMPlacePage () @@ -28,10 +29,35 @@ extern NSString * const kAlohalyticsTapEventKey; { [[NSBundle mainBundle] loadNibNamed:kPlacePageNibIdentifier owner:self options:nil]; self.manager = manager; + if (!IPAD) + { + [self.extendedPlacePageView addObserver:self + forKeyPath:kPlacePageViewCenterKeyPath + options:NSKeyValueObservingOptionNew + context:nullptr]; + } } return self; } +- (void)dealloc +{ + if (!IPAD) + { + [self.extendedPlacePageView removeObserver:self forKeyPath:kPlacePageViewCenterKeyPath]; + } +} + +- (void)observeValueForKeyPath:(NSString *)keyPath + ofObject:(id)object + change:(NSDictionary *)change + context:(void *)context +{ + if ([self.extendedPlacePageView isEqual:object] && + [keyPath isEqualToString:kPlacePageViewCenterKeyPath]) + [self.manager dragPlacePage:self.extendedPlacePageView.frame]; +} + - (void)configure { MWMPlacePageEntity * entity = self.manager.entity; @@ -44,6 +70,11 @@ extern NSString * const kAlohalyticsTapEventKey; // Should override this method if you want to show place page with custom animation. } +- (void)hide +{ + // Should override this method if you want to hide place page with custom animation. +} + - (void)dismiss { [self.extendedPlacePageView removeFromSuperview]; diff --git a/iphone/Maps/Classes/MWMPlacePageActionBar.h b/iphone/Maps/Classes/MWMPlacePageActionBar.h index 3578523a8e..7bf22afed2 100644 --- a/iphone/Maps/Classes/MWMPlacePageActionBar.h +++ b/iphone/Maps/Classes/MWMPlacePageActionBar.h @@ -6,6 +6,8 @@ @property (nonatomic) BOOL isBookmark; +@property (weak, nonatomic) IBOutlet UIButton * shareButton; + + (MWMPlacePageActionBar *)actionBarForPlacePage:(MWMPlacePage *)placePage; - (void)configureWithPlacePage:(MWMPlacePage *)placePage; diff --git a/iphone/Maps/Classes/MWMPlacePageActionBar.mm b/iphone/Maps/Classes/MWMPlacePageActionBar.mm index 8f5add3055..c123d843ef 100644 --- a/iphone/Maps/Classes/MWMPlacePageActionBar.mm +++ b/iphone/Maps/Classes/MWMPlacePageActionBar.mm @@ -17,7 +17,6 @@ static NSString * const kPlacePageActionBarNibName = @"PlacePageActionBar"; @property (weak, nonatomic) MWMPlacePage * placePage; @property (weak, nonatomic) IBOutlet UIButton * apiBackButton; @property (weak, nonatomic) IBOutlet UIButton * bookmarkButton; -@property (weak, nonatomic) IBOutlet UIButton * shareButton; @property (weak, nonatomic) IBOutlet UIButton * routeButton; @property (weak, nonatomic) IBOutlet UILabel * apiBackLabel; @property (weak, nonatomic) IBOutlet UILabel * routeLabel; diff --git a/iphone/Maps/Classes/MWMPlacePageViewManager.h b/iphone/Maps/Classes/MWMPlacePageViewManager.h index e2867e5f3f..d9e10cfae7 100644 --- a/iphone/Maps/Classes/MWMPlacePageViewManager.h +++ b/iphone/Maps/Classes/MWMPlacePageViewManager.h @@ -19,6 +19,7 @@ - (void)showPlacePageWithUserMark:(unique_ptr)userMark; - (void)refreshPlacePage; - (void)dismissPlacePage; +- (void)hidePlacePage; - (void)buildRoute; - (void)share; - (void)addBookmark; @@ -28,7 +29,7 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator; - (void)reloadBookmark; -- (void)dragPlacePage:(CGPoint)point; +- (void)dragPlacePage:(CGRect)frame; - (void)showDirectionViewWithTitle:(NSString *)title type:(NSString *)type; - (void)hideDirectionView; - (void)addSubviews:(NSArray *)views withNavigationController:(UINavigationController *)controller; diff --git a/iphone/Maps/Classes/MWMPlacePageViewManager.mm b/iphone/Maps/Classes/MWMPlacePageViewManager.mm index 9219eb8d85..dcb56764fe 100644 --- a/iphone/Maps/Classes/MWMPlacePageViewManager.mm +++ b/iphone/Maps/Classes/MWMPlacePageViewManager.mm @@ -55,6 +55,11 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) return self; } +- (void)hidePlacePage +{ + [self.placePage hide]; +} + - (void)dismissPlacePage { [self.delegate placePageDidClose]; @@ -119,10 +124,10 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) BOOL hasSpeed; self.entity.category = [[MapsAppDelegate theApp].m_locationManager formattedSpeedAndAltitude:hasSpeed]; } - self.placePage.topBound = self.topBound; - self.placePage.leftBound = self.leftBound; self.placePage.parentViewHeight = self.ownerViewController.view.height; [self.placePage configure]; + self.placePage.topBound = self.topBound; + self.placePage.leftBound = self.leftBound; [self refreshPlacePage]; } @@ -191,10 +196,12 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) { MWMPlacePageEntity * entity = self.entity; CLLocationCoordinate2D const coord = CLLocationCoordinate2DMake(entity.point.x, entity.point.y); - MWMActivityViewController * shareVC = [MWMActivityViewController shareControllerForLocationTitle:entity.title - location:coord - myPosition:NO]; - [shareVC presentInParentViewController:self.ownerViewController anchorView:self.placePage.actionBar]; + MWMActivityViewController * shareVC = + [MWMActivityViewController shareControllerForLocationTitle:entity.title + location:coord + myPosition:NO]; + [shareVC presentInParentViewController:self.ownerViewController + anchorView:self.placePage.actionBar.shareButton]; } - (void)apiBack @@ -253,9 +260,9 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) [self.placePage reloadBookmark]; } -- (void)dragPlacePage:(CGPoint)point +- (void)dragPlacePage:(CGRect)frame { - [self.delegate dragPlacePage:point]; + [self.delegate dragPlacePage:frame]; } - (void)onLocationUpdate:(location::GpsInfo const &)info diff --git a/iphone/Maps/Classes/MWMPlacePageViewManagerDelegate.h b/iphone/Maps/Classes/MWMPlacePageViewManagerDelegate.h index 12ecb69427..e9faadb247 100644 --- a/iphone/Maps/Classes/MWMPlacePageViewManagerDelegate.h +++ b/iphone/Maps/Classes/MWMPlacePageViewManagerDelegate.h @@ -1,6 +1,6 @@ @protocol MWMPlacePageViewManagerProtocol -- (void)dragPlacePage:(CGPoint)point; +- (void)dragPlacePage:(CGRect)frame; - (void)addPlacePageViews:(NSArray *)views; - (void)updateStatusBarStyle; - (void)buildRoute:(m2::PointD)destination; diff --git a/iphone/Maps/Classes/MWMiPadPlacePage.mm b/iphone/Maps/Classes/MWMiPadPlacePage.mm index 7accbfca37..db8d148c0a 100644 --- a/iphone/Maps/Classes/MWMiPadPlacePage.mm +++ b/iphone/Maps/Classes/MWMiPadPlacePage.mm @@ -119,6 +119,11 @@ static CGFloat const kBottomOffset = 12.; }]; } +- (void)hide +{ + [self.manager dismissPlacePage]; +} + - (void)dismiss { UIView * view = self.navigationController.view; diff --git a/iphone/Maps/Classes/MWMiPhoneLandscapePlacePage.mm b/iphone/Maps/Classes/MWMiPhoneLandscapePlacePage.mm index 4bfa21ebba..924a5fee57 100644 --- a/iphone/Maps/Classes/MWMiPhoneLandscapePlacePage.mm +++ b/iphone/Maps/Classes/MWMiPhoneLandscapePlacePage.mm @@ -40,9 +40,24 @@ typedef NS_ENUM(NSUInteger, MWMiPhoneLandscapePlacePageState) - (void)show { + if (self.state == MWMiPhoneLandscapePlacePageStateOpen) + return; + CGSize const size = self.extendedPlacePageView.superview.size; + CGFloat const height = MIN(size.width, size.height); + CGFloat const offset = MIN(height, kMaximumPlacePageWidth); + self.extendedPlacePageView.minX = -offset; + self.actionBar.width = offset; + self.actionBar.minX = 0.0; self.state = MWMiPhoneLandscapePlacePageStateOpen; } +- (void)hide +{ + if (self.state == MWMiPhoneLandscapePlacePageStateClosed) + return; + self.state = MWMiPhoneLandscapePlacePageStateClosed; +} + - (void)configureContentInset { CGFloat const height = self.extendedPlacePageView.height - self.anchorImageView.height; @@ -84,7 +99,6 @@ typedef NS_ENUM(NSUInteger, MWMiPhoneLandscapePlacePageState) switch (self.state) { case MWMiPhoneLandscapePlacePageStateClosed: - [self.actionBar removeFromSuperview]; self.targetPoint = CGPointMake(-offset / 2., (height + self.topBound) / 2.); break; case MWMiPhoneLandscapePlacePageStateOpen: @@ -110,7 +124,7 @@ typedef NS_ENUM(NSUInteger, MWMiPhoneLandscapePlacePageState) if (self.panVelocity > 0) [self show]; else - [self.manager dismissPlacePage]; + [self hide]; } } @@ -144,6 +158,8 @@ typedef NS_ENUM(NSUInteger, MWMiPhoneLandscapePlacePageState) - (void)setState:(MWMiPhoneLandscapePlacePageState)state { + if (_state == state) + return; _state = state; [self updateTargetPoint]; } @@ -151,14 +167,13 @@ typedef NS_ENUM(NSUInteger, MWMiPhoneLandscapePlacePageState) - (void)setTopBound:(CGFloat)topBound { super.topBound = topBound; - CGSize const size = UIScreen.mainScreen.bounds.size; + CGSize const size = self.extendedPlacePageView.superview.size; CGFloat const height = MIN(size.width, size.height); - CGFloat const offset = MIN(height, kMaximumPlacePageWidth); - self.extendedPlacePageView.frame = CGRectMake(0., topBound, offset, height - topBound); - self.actionBar.width = offset; - self.actionBar.minX = 0.0; + CGRect const frame = self.extendedPlacePageView.frame; + self.extendedPlacePageView.frame = {{frame.origin.x, topBound}, {frame.size.width, height - topBound}}; self.actionBar.maxY = height - topBound; - [self updateTargetPoint]; + if (self.state == MWMiPhoneLandscapePlacePageStateOpen) + [self updateTargetPoint]; [self configureContentInset]; } @@ -166,11 +181,13 @@ typedef NS_ENUM(NSUInteger, MWMiPhoneLandscapePlacePageState) { _targetPoint = targetPoint; __weak MWMiPhoneLandscapePlacePage * weakSelf = self; + if (self.state == MWMiPhoneLandscapePlacePageStateClosed) + GetFramework().GetBalloonManager().RemovePin(); [self startAnimatingPlacePage:self initialVelocity:CGPointMake(self.panVelocity, 0.0) completion:^ { __strong MWMiPhoneLandscapePlacePage * self = weakSelf; if (self.state == MWMiPhoneLandscapePlacePageStateClosed) - [super dismiss]; + [self.manager dismissPlacePage]; else self.panRecognizer.enabled = YES; }]; diff --git a/iphone/Maps/Classes/MWMiPhonePortraitPlacePage.mm b/iphone/Maps/Classes/MWMiPhonePortraitPlacePage.mm index 76dcbf6601..d8c7ebaa40 100644 --- a/iphone/Maps/Classes/MWMiPhonePortraitPlacePage.mm +++ b/iphone/Maps/Classes/MWMiPhonePortraitPlacePage.mm @@ -12,7 +12,6 @@ #include "Framework.h" -static NSString * const kPlacePageViewDragKeyPath = @"center"; static CGFloat const kPlacePageBottomOffset = 31.; typedef NS_ENUM(NSUInteger, MWMiPhonePortraitPlacePageState) @@ -33,27 +32,6 @@ typedef NS_ENUM(NSUInteger, MWMiPhonePortraitPlacePageState) @implementation MWMiPhonePortraitPlacePage -- (instancetype)initWithManager:(MWMPlacePageViewManager *)manager -{ - self = [super initWithManager:manager]; - if (self) - { - [self.extendedPlacePageView addObserver:self forKeyPath:kPlacePageViewDragKeyPath options:NSKeyValueObservingOptionNew context:nullptr]; - } - return self; -} - -- (void)dealloc -{ - [self.extendedPlacePageView removeObserver:self forKeyPath:kPlacePageViewDragKeyPath]; -} - -- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context -{ - if ([self.extendedPlacePageView isEqual:object] && [keyPath isEqualToString:kPlacePageViewDragKeyPath]) - [self.manager dragPlacePage:self.extendedPlacePageView.origin]; -} - - (void)configure { [super configure]; @@ -79,6 +57,11 @@ typedef NS_ENUM(NSUInteger, MWMiPhonePortraitPlacePageState) self.state = MWMiPhonePortraitPlacePageStatePreview; } +- (void)hide +{ + self.state = MWMiPhonePortraitPlacePageStateClosed; +} + - (void)dismiss { [MWMPlacePageNavigationBar remove]; @@ -275,13 +258,15 @@ typedef NS_ENUM(NSUInteger, MWMiPhonePortraitPlacePageState) return; _targetPoint = targetPoint; __weak MWMiPhonePortraitPlacePage * weakSelf = self; + if (self.state == MWMiPhonePortraitPlacePageStateClosed) + GetFramework().GetBalloonManager().RemovePin(); [self startAnimatingPlacePage:self initialVelocity:CGPointMake(0.0, self.panVelocity) completion:^ { __strong MWMiPhonePortraitPlacePage * self = weakSelf; if (self.state == MWMiPhonePortraitPlacePageStateClosed) { self.keyboardHeight = 0.; - [super dismiss]; + [self.manager dismissPlacePage]; } else {