diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButton.h b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButton.h index 89f33cfd09..c04048855f 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButton.h +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButton.h @@ -8,11 +8,13 @@ #import "MWMSideMenuButtonDelegate.h" #import "MWMSideMenuDelegate.h" +#import "MWMSideMenuDownloadBadge.h" #import -@interface MWMSideMenuButton : UIButton +@interface MWMSideMenuButton : UIView @property (weak, nonatomic) id delegate; +@property (weak, nonatomic) MWMSideMenuDownloadBadge * downloadBadge; - (instancetype)initWithFrame:(CGRect)frame __attribute__((unavailable("initWithFrame is not available"))); - (instancetype)init __attribute__((unavailable("init is not available"))); diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButton.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButton.mm index ebcb42f7cd..549d6fcfcf 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButton.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButton.mm @@ -12,6 +12,7 @@ @interface MWMSideMenuButton() +@property (weak, nonatomic) IBOutlet UIImageView * buttonImage; @property (nonatomic) CGRect defaultBounds; @end @@ -37,9 +38,9 @@ { self.alpha = 1.0; }]; - UIImageView const * const animationIV = self.imageView; + UIImageView const * const animationIV = self.buttonImage; NSString const * const imageName = @"btn_green_menu_"; - [self setImage:[UIImage imageNamed:[imageName stringByAppendingString:@"1"]] forState:UIControlStateNormal]; + self.buttonImage.image = [UIImage imageNamed:[imageName stringByAppendingString:@"1"]]; static NSUInteger const animationImagesCount = 4; NSMutableArray * const animationImages = [NSMutableArray arrayWithCapacity:animationImagesCount]; for (NSUInteger i = 0; i < animationImagesCount; ++i) @@ -54,7 +55,7 @@ - (void)layoutSubviews { [super layoutSubviews]; - self.bounds = self.defaultBounds; + self.buttonImage.frame = self.bounds = self.defaultBounds; self.maxY = self.superview.height - 2.0 * kViewControlsOffsetToBounds; [self layoutXPosition:self.hidden]; } @@ -87,6 +88,7 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { + self.buttonImage.highlighted = YES; UITouch * touch = [touches anyObject]; if (touch.tapCount > 1) [NSObject cancelPreviousPerformRequestsWithTarget:self]; @@ -94,10 +96,11 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { + self.buttonImage.highlighted = NO; UITouch * touch = [touches anyObject]; if (touch.tapCount == 1) [self performSelector:@selector(handleSingleTap) withObject:nil afterDelay:0.1]; - else + else if (touch.tapCount > 1) [self handleDoubleTap]; } @@ -129,4 +132,13 @@ } } +#pragma mark - Properties + +- (void)setDownloadBadge:(MWMSideMenuDownloadBadge *)downloadBadge +{ + _downloadBadge = downloadBadge; + if (![downloadBadge.superview isEqual:self]) + [self addSubview:downloadBadge]; +} + @end diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuDownloadBadge.h b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuDownloadBadge.h new file mode 100644 index 0000000000..042640b81e --- /dev/null +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuDownloadBadge.h @@ -0,0 +1,24 @@ +// +// MWMSideMenuDownloadBadge.h +// Maps +// +// Created by Ilya Grechuhin on 14.07.15. +// Copyright (c) 2015 MapsWithMe. All rights reserved. +// + +#import + +@class MWMSideMenuDownloadBadge; +@protocol MWMSideMenuDownloadBadgeOwner + +@property (weak, nonatomic) MWMSideMenuDownloadBadge * downloadBadge; + +@end + +@interface MWMSideMenuDownloadBadge : UIView + +@property (nonatomic) NSUInteger outOfDateCount; + +- (void)showAnimatedAfterDelay:(NSTimeInterval)delay; + +@end diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuDownloadBadge.m b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuDownloadBadge.m new file mode 100644 index 0000000000..097fe30aa6 --- /dev/null +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuDownloadBadge.m @@ -0,0 +1,57 @@ +// +// MWMSideMenuDownloadBadge.m +// Maps +// +// Created by Ilya Grechuhin on 14.07.15. +// Copyright (c) 2015 MapsWithMe. All rights reserved. +// + +#import "MWMMapViewControlsCommon.h" +#import "MWMSideMenuDownloadBadge.h" +#import "UIKitCategories.h" + +@interface MWMSideMenuDownloadBadge () + +@property (weak, nonatomic) IBOutlet UIImageView * badgeBackground; +@property (weak, nonatomic) IBOutlet UILabel * downloadCount; + +@end + +@implementation MWMSideMenuDownloadBadge + +- (void)layoutSubviews +{ + self.maxX = self.superview.width; + self.badgeBackground.frame = self.bounds; + self.downloadCount.frame = self.bounds; + [super layoutSubviews]; +} + +- (void)showAnimatedAfterDelay:(NSTimeInterval)delay +{ + self.hidden = YES; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^ + { + [self expand]; + }); +} + +- (void)expand +{ + if (self.outOfDateCount == 0) + return; + self.hidden = NO; + CATransform3D const zeroScale = CATransform3DScale(CATransform3DIdentity, 0.0, 0.0, 1.0); + self.badgeBackground.layer.transform = self.downloadCount.layer.transform = zeroScale; + self.badgeBackground.alpha = self.downloadCount.alpha = 0.0; + self.badgeBackground.hidden = NO; + self.downloadCount.hidden = NO; + self.downloadCount.text = @(self.outOfDateCount).stringValue; + [UIView animateWithDuration:framesDuration(4) animations:^ + { + self.badgeBackground.layer.transform = self.downloadCount.layer.transform = CATransform3DIdentity; + self.badgeBackground.alpha = self.downloadCount.alpha = 1.0; + }]; +} + +@end diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuManager.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuManager.mm index ff5e2d2f25..491cdf2abb 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuManager.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuManager.mm @@ -16,6 +16,7 @@ #import "MWMSideMenuButton.h" #import "MWMSideMenuButtonDelegate.h" #import "MWMSideMenuDelegate.h" +#import "MWMSideMenuDownloadBadge.h" #import "MWMSideMenuManager.h" #import "MWMSideMenuView.h" #import "SettingsAndMoreVC.h" @@ -34,6 +35,7 @@ extern NSString * const kAlohalyticsTapEventKey; @property (weak, nonatomic) MapViewController * controller; @property (nonatomic) IBOutlet MWMSideMenuButton * menuButton; @property (nonatomic) IBOutlet MWMSideMenuView * sideMenu; +@property (nonatomic) IBOutlet MWMSideMenuDownloadBadge * downloadBadge; @end @@ -177,6 +179,17 @@ extern NSString * const kAlohalyticsTapEventKey; }]; } +- (void)addDownloadBadgeToView:(UIView *)view +{ + int const count = GetFramework().GetCountryTree().GetActiveMapLayout().GetOutOfDateCount(); + if (count > 0) + { + self.downloadBadge.outOfDateCount = count; + view.downloadBadge = self.downloadBadge; + [self.downloadBadge showAnimatedAfterDelay:framesDuration(10)]; + } +} + #pragma mark - Properties - (void)setState:(MWMSideMenuState)state @@ -187,11 +200,12 @@ extern NSString * const kAlohalyticsTapEventKey; { case MWMSideMenuStateActive: [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"menu"]; - self.sideMenu.outOfDateCount = GetFramework().GetCountryTree().GetActiveMapLayout().GetOutOfDateCount(); + [self addDownloadBadgeToView:self.sideMenu]; [self showMenu]; [self.sideMenu setup]; break; case MWMSideMenuStateInactive: + [self addDownloadBadgeToView:self.menuButton]; if (_state == MWMSideMenuStateActive) { [self.menuButton setHidden:NO animated:NO]; diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuView.h b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuView.h index cbbcfe0650..f87401c83b 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuView.h +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuView.h @@ -6,14 +6,16 @@ // Copyright (c) 2015 MapsWithMe. All rights reserved. // -#import #import "MWMSideMenuDelegate.h" +#import "MWMSideMenuDownloadBadge.h" +#import "UIKitCategories.h" +#import -@interface MWMSideMenuView : UIView +@interface MWMSideMenuView : SolidTouchView @property (weak, nonatomic, readonly) IBOutlet UIView * dimBackground; @property (weak, nonatomic) id delegate; -@property (nonatomic) NSUInteger outOfDateCount; +@property (weak, nonatomic) MWMSideMenuDownloadBadge * downloadBadge; - (instancetype)initWithFrame:(CGRect)frame __attribute__((unavailable("initWithFrame is not available"))); - (instancetype)init __attribute__((unavailable("init is not available"))); diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuView.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuView.mm index e256ba3879..f58642311c 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuView.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuView.mm @@ -7,6 +7,7 @@ // #import "MWMMapViewControlsCommon.h" +#import "MWMSideMenuDownloadBadge.h" #import "MWMSideMenuView.h" #import "UIKitCategories.h" @@ -26,9 +27,6 @@ @property (weak, nonatomic) IBOutlet UIButton * shareLocationLabel; @property (weak, nonatomic) IBOutlet UIButton * searchLabel; -@property (weak, nonatomic) IBOutlet UIImageView * downloadBadge; -@property (weak, nonatomic) IBOutlet UILabel * downloadCount; - @property (nonatomic) NSArray * buttons; @property (nonatomic) NSArray * labels; @@ -52,12 +50,6 @@ self.labels = @[self.shareLocationLabel, self.settingsLabel, self.downloadMapsLabel, self.bookmarksLabel, self.searchLabel]; } -- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event -{ - // Prevent super call to stop event propagation - // [super touchesBegan:touches withEvent:event]; -} - - (void)setup { self.contentScaleFactor = self.superview.contentScaleFactor; @@ -73,10 +65,8 @@ animationIV.animationDuration = framesDuration(animationIV.animationImages.count); animationIV.animationRepeatCount = 1; [animationIV startAnimating]; - self.downloadBadge.hidden = YES; - self.downloadCount.hidden = YES; [self updateMenuBackground]; - [self updateMenuUI]; + [self showAnimation]; [self setNeedsLayout]; } @@ -149,11 +139,6 @@ self.bookmarksLabel.maxX = rightBound; self.searchLabel.maxX = rightBound; - self.downloadBadge.maxX = self.downloadMapsButton.maxX; - self.downloadCount.maxX = self.downloadMapsButton.maxX; - self.downloadBadge.minY = self.downloadMapsButton.minY; - self.downloadCount.minY = self.downloadMapsButton.minY; - m2::PointD const pivot(self.searchButton.minX * self.contentScaleFactor - 2.0 * kViewControlsOffsetToBounds, self.searchButton.maxY * self.contentScaleFactor - kViewControlsOffsetToBounds); [self.delegate setRulerPivot:pivot]; [self.delegate setCopyrightLabelPivot:pivot]; @@ -171,41 +156,14 @@ }]; } -- (void)updateMenuUI -{ - [self showAnimation]; - [self performSelector:@selector(updateMenuOutOfDateBadge) withObject:nil afterDelay:framesDuration(10)]; -} - -- (void)updateMenuOutOfDateBadge -{ - if (self.outOfDateCount == 0) - return; - CATransform3D const zeroScale = CATransform3DScale(CATransform3DIdentity, 0.0, 0.0, 1.0); - self.downloadBadge.layer.transform = zeroScale; - self.downloadCount.layer.transform = zeroScale; - self.downloadBadge.alpha = 0.0; - self.downloadCount.alpha = 0.0; - self.downloadBadge.hidden = NO; - self.downloadCount.hidden = NO; - self.downloadCount.text = @(self.outOfDateCount).stringValue; - [UIView animateWithDuration:framesDuration(4) animations:^ - { - self.downloadBadge.layer.transform = CATransform3DIdentity; - self.downloadCount.layer.transform = CATransform3DIdentity; - self.downloadBadge.alpha = 1.0; - self.downloadCount.alpha = 1.0; - }]; -} - - (void)showAnimation { - [self.labels enumerateObjectsUsingBlock:^(UIButton * label, NSUInteger idx, BOOL *stop) + [self.labels enumerateObjectsUsingBlock:^(UIButton * label, NSUInteger idx, BOOL * stop) { label.alpha = 0.0; }]; - [self.buttons enumerateObjectsUsingBlock:^(UIButton * button, NSUInteger idx, BOOL *stop) + [self.buttons enumerateObjectsUsingBlock:^(UIButton * button, NSUInteger idx, BOOL * stop) { button.alpha = 0.0; }]; @@ -249,4 +207,13 @@ [CATransaction commit]; } +#pragma mark - Properties + +- (void)setDownloadBadge:(MWMSideMenuDownloadBadge *)downloadBadge +{ + _downloadBadge = downloadBadge; + if (![downloadBadge.superview isEqual:self.downloadMapsButton]) + [self.downloadMapsButton addSubview:downloadBadge]; +} + @end diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuViews.xib b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuViews.xib index 7b645a647e..75dccbf775 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuViews.xib +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuViews.xib @@ -1,5 +1,5 @@ - + @@ -7,7 +7,8 @@ - + + @@ -111,17 +112,6 @@ - - + + + + + + + diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index a3e6a43980..a1a0633c15 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 28AD73880D9D96C1002E5188 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD73870D9D96C1002E5188 /* MainWindow.xib */; }; 340F24631B14910500F874CD /* RouteState.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340F24621B14910500F874CD /* RouteState.mm */; }; 34287FDC1B3D7C4800F9959C /* libFlurry_6.4.0.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 34287FDB1B3D7C4800F9959C /* libFlurry_6.4.0.a */; }; + 3428BC131B55477E00C85B30 /* MWMSideMenuDownloadBadge.m in Sources */ = {isa = PBXBuildFile; fileRef = 3428BC121B55477E00C85B30 /* MWMSideMenuDownloadBadge.m */; }; 342AD76F1B53D30C00E0B997 /* UIButton+RuntimeAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = 342AD76E1B53D30C00E0B997 /* UIButton+RuntimeAttributes.m */; }; 342AD7721B53D32F00E0B997 /* UIView+RuntimeAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = 342AD7711B53D32F00E0B997 /* UIView+RuntimeAttributes.m */; }; 343F262E1AEFC4A300388A6D /* MWMFrameworkUtils.mm in Sources */ = {isa = PBXBuildFile; fileRef = 343F262D1AEFC4A300388A6D /* MWMFrameworkUtils.mm */; }; @@ -356,6 +357,8 @@ 340F24621B14910500F874CD /* RouteState.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RouteState.mm; sourceTree = ""; }; 340F24641B15F01D00F874CD /* MWMSideMenuDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMSideMenuDelegate.h; sourceTree = ""; }; 34287FDB1B3D7C4800F9959C /* libFlurry_6.4.0.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libFlurry_6.4.0.a; path = Statistics/libFlurry_6.4.0.a; sourceTree = ""; }; + 3428BC111B55477E00C85B30 /* MWMSideMenuDownloadBadge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMSideMenuDownloadBadge.h; sourceTree = ""; }; + 3428BC121B55477E00C85B30 /* MWMSideMenuDownloadBadge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MWMSideMenuDownloadBadge.m; sourceTree = ""; }; 342AD76D1B53D30C00E0B997 /* UIButton+RuntimeAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIButton+RuntimeAttributes.h"; sourceTree = ""; }; 342AD76E1B53D30C00E0B997 /* UIButton+RuntimeAttributes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIButton+RuntimeAttributes.m"; sourceTree = ""; }; 342AD7701B53D32F00E0B997 /* UIView+RuntimeAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+RuntimeAttributes.h"; sourceTree = ""; }; @@ -1160,6 +1163,8 @@ 34BC72191B0DECAE0012A34B /* MWMSideMenuView.mm */, 34BC721A1B0DECAE0012A34B /* MWMSideMenuViews.xib */, 340F24641B15F01D00F874CD /* MWMSideMenuDelegate.h */, + 3428BC111B55477E00C85B30 /* MWMSideMenuDownloadBadge.h */, + 3428BC121B55477E00C85B30 /* MWMSideMenuDownloadBadge.m */, ); path = SideMenu; sourceTree = ""; @@ -2239,6 +2244,7 @@ F6588E371B15D87A00EE1E58 /* MWMBookmarkColorCell.mm in Sources */, F6D409FA1B319BD70041730F /* ContextViews.mm in Sources */, 349A357A1B53D4C9009677EE /* MWMCircularProgress.m in Sources */, + 3428BC131B55477E00C85B30 /* MWMSideMenuDownloadBadge.m in Sources */, 97A8000C18B21363000C07A2 /* SearchView.mm in Sources */, FAA5C2A2144F135F005337F6 /* LocationManager.mm in Sources */, F66A8FAC1B09F137001B9C97 /* MWMiPadPlacePage.mm in Sources */,