From 19dab4908a15da7b3558a59370058d8725bd8cae Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Tue, 22 Aug 2017 14:37:23 +0300 Subject: [PATCH] [MAPSME-5412] [ios] Fixed bottom menu badge visibility. --- iphone/Maps/Classes/MapsAppDelegate.h | 2 + iphone/Maps/Classes/MapsAppDelegate.mm | 12 +++++- .../Maps/UI/BottomMenu/MWMBottomMenuView.mm | 38 +++++-------------- .../BottomMenu/MWMBottomMenuViewController.h | 1 + .../BottomMenu/MWMBottomMenuViewController.mm | 10 ++--- .../MWMBottomMenuViewController.xib | 3 +- 6 files changed, 29 insertions(+), 37 deletions(-) diff --git a/iphone/Maps/Classes/MapsAppDelegate.h b/iphone/Maps/Classes/MapsAppDelegate.h index 15c96ead08..6ef66afd12 100644 --- a/iphone/Maps/Classes/MapsAppDelegate.h +++ b/iphone/Maps/Classes/MapsAppDelegate.h @@ -36,4 +36,6 @@ - (void)showMap; - (void)showAlertIfRequired; +- (NSUInteger)badgeNumber; + @end diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm index d755611504..c7f421a368 100644 --- a/iphone/Maps/Classes/MapsAppDelegate.mm +++ b/iphone/Maps/Classes/MapsAppDelegate.mm @@ -22,7 +22,9 @@ #include "Framework.h" #include "map/gps_tracker.hpp" + #include "platform/http_thread_apple.h" +#include "platform/local_country_file_utils.hpp" // If you have a "missing header error" here, then please run configure.sh script in the root repo // folder. @@ -855,12 +857,18 @@ using namespace osm_auth_ios; } - (void)updateApplicationIconBadgeNumber +{ + auto const number = [self badgeNumber]; + [UIApplication sharedApplication].applicationIconBadgeNumber = number; + [[MWMBottomMenuViewController controller] updateBadgeVisible:number != 0]; +} + +- (NSUInteger)badgeNumber { auto & s = GetFramework().GetStorage(); storage::Storage::UpdateInfo updateInfo{}; s.GetUpdateInfo(s.GetRootId(), updateInfo); - [UIApplication sharedApplication].applicationIconBadgeNumber = - updateInfo.m_numberOfMwmFilesToUpdate; + return updateInfo.m_numberOfMwmFilesToUpdate + (platform::migrate::NeedMigrate() ? 1 : 0); } #pragma mark - MWMFrameworkStorageObserver diff --git a/iphone/Maps/UI/BottomMenu/MWMBottomMenuView.mm b/iphone/Maps/UI/BottomMenu/MWMBottomMenuView.mm index b87b164294..c247062be3 100644 --- a/iphone/Maps/UI/BottomMenu/MWMBottomMenuView.mm +++ b/iphone/Maps/UI/BottomMenu/MWMBottomMenuView.mm @@ -3,10 +3,6 @@ #import "MWMButton.h" #import "MWMCommon.h" -#include "Framework.h" - -#include "platform/local_country_file_utils.hpp" - namespace { CGFloat constexpr kAdditionalHeight = 64; @@ -16,22 +12,17 @@ CGFloat constexpr kDefaultMenuButtonWidth = 60; @interface MWMBottomMenuView () -@property(weak, nonatomic) IBOutlet UICollectionView * additionalButtons; - -@property(weak, nonatomic) IBOutlet NSLayoutConstraint * mainButtonsHeight; -@property(weak, nonatomic) IBOutlet NSLayoutConstraint * additionalButtonsHeight; -@property(weak, nonatomic) IBOutlet NSLayoutConstraint * separatorHeight; - -@property(weak, nonatomic) IBOutlet UIView * downloadBadge; - -@property(weak, nonatomic) IBOutlet MWMButton * searchButton; -@property(weak, nonatomic) IBOutlet MWMButton * menuButton; -@property(weak, nonatomic) IBOutlet NSLayoutConstraint * menuButtonWidth; - -@property(nonatomic) IBOutletCollection(NSLayoutConstraint) NSArray * mainButtonConstraintsLeftToRight; - @property(nonatomic) CGFloat layoutDuration; @property(nonatomic) CGRect availableArea; +@property(nonatomic) IBOutletCollection(NSLayoutConstraint) NSArray * mainButtonConstraintsLeftToRight; +@property(weak, nonatomic) IBOutlet MWMButton * menuButton; +@property(weak, nonatomic) IBOutlet MWMButton * searchButton; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint * additionalButtonsHeight; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint * mainButtonsHeight; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint * menuButtonWidth; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint * separatorHeight; +@property(weak, nonatomic) IBOutlet UICollectionView * additionalButtons; +@property(weak, nonatomic) IBOutlet UIView * downloadBadge; @end @@ -41,7 +32,6 @@ CGFloat constexpr kDefaultMenuButtonWidth = 60; { [super awakeFromNib]; self.additionalButtons.hidden = YES; - self.downloadBadge.hidden = YES; if (isInterfaceRightToLeft()) { @@ -191,15 +181,6 @@ CGFloat constexpr kDefaultMenuButtonWidth = 60; [self setNeedsLayout]; } -- (void)updateBadge -{ - auto & s = GetFramework().GetStorage(); - storage::Storage::UpdateInfo updateInfo{}; - s.GetUpdateInfo(s.GetRootId(), updateInfo); - self.downloadBadge.hidden = - (updateInfo.m_numberOfMwmFilesToUpdate == 0) && !platform::migrate::NeedMigrate(); -} - #pragma mark - Properties - (void)setState:(MWMBottomMenuState)state @@ -212,7 +193,6 @@ CGFloat constexpr kDefaultMenuButtonWidth = 60; [self morphMenuButtonTemplate:@"ic_menu_" direct:isActive]; _state = state; [self refreshLayout]; - [self updateBadge]; } - (void)updateAvailableArea:(CGRect)frame diff --git a/iphone/Maps/UI/BottomMenu/MWMBottomMenuViewController.h b/iphone/Maps/UI/BottomMenu/MWMBottomMenuViewController.h index e3c13ff4f2..73acf4213c 100644 --- a/iphone/Maps/UI/BottomMenu/MWMBottomMenuViewController.h +++ b/iphone/Maps/UI/BottomMenu/MWMBottomMenuViewController.h @@ -13,6 +13,7 @@ delegate:(id)delegate; - (void)mwm_refreshUI; +- (void)updateBadgeVisible:(BOOL)visible; + (void)updateAvailableArea:(CGRect)frame; diff --git a/iphone/Maps/UI/BottomMenu/MWMBottomMenuViewController.mm b/iphone/Maps/UI/BottomMenu/MWMBottomMenuViewController.mm index a9cb039a58..887d4a8146 100644 --- a/iphone/Maps/UI/BottomMenu/MWMBottomMenuViewController.mm +++ b/iphone/Maps/UI/BottomMenu/MWMBottomMenuViewController.mm @@ -7,6 +7,7 @@ #import "MWMCommon.h" #import "MWMMapViewControlsManager.h" #import "MapViewController.h" +#import "MapsAppDelegate.h" #import "SwiftBridge.h" #include "Framework.h" @@ -42,6 +43,7 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) { @property(weak, nonatomic) IBOutlet MWMButton * searchButton; @property(weak, nonatomic) IBOutlet NSLayoutConstraint * mainButtonsHeight; @property(weak, nonatomic) IBOutlet UICollectionView * additionalButtons; +@property(weak, nonatomic) IBOutlet UIView * downloadBadge; @property(weak, nonatomic) MapViewController * controller; @property(weak, nonatomic) id delegate; @@ -97,7 +99,7 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) { } - (void)mwm_refreshUI { [self.view mwm_refreshUI]; } - +- (void)updateBadgeVisible:(BOOL)visible { self.downloadBadge.hidden = !visible; } #pragma mark - Refresh Collection View layout - (void)refreshLayout @@ -170,12 +172,9 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) { } case MWMBottomMenuViewCellDownload: { - auto & s = GetFramework().GetStorage(); - storage::Storage::UpdateInfo updateInfo{}; - s.GetUpdateInfo(s.GetRootId(), updateInfo); [cell configureWithImageName:@"ic_menu_download" label:L(@"download_maps") - badgeCount:updateInfo.m_numberOfMwmFilesToUpdate + badgeCount:[[MapsAppDelegate theApp] badgeNumber] isEnabled:YES]; } break; @@ -355,6 +354,7 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) { }); }]; view.state = state; + [self updateBadgeVisible:[[MapsAppDelegate theApp] badgeNumber] != 0]; } - (MWMBottomMenuState)state { return self.menuView.state; } diff --git a/iphone/Maps/UI/BottomMenu/MWMBottomMenuViewController.xib b/iphone/Maps/UI/BottomMenu/MWMBottomMenuViewController.xib index f63be97e08..b2c62fa6ea 100644 --- a/iphone/Maps/UI/BottomMenu/MWMBottomMenuViewController.xib +++ b/iphone/Maps/UI/BottomMenu/MWMBottomMenuViewController.xib @@ -13,6 +13,7 @@ + @@ -164,7 +165,7 @@ - +