diff --git a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h index fdedc6caaa..667955edd9 100644 --- a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h +++ b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h @@ -12,10 +12,12 @@ - (void)presentAlert:(routing::IRouter::ResultCode)type; - (void)presentDownloaderAlertWithCountries:(vector const &)countries routes:(vector const &)routes - code:(routing::IRouter::ResultCode)code; + code:(routing::IRouter::ResultCode)code + block:(nonnull TMWMVoidBlock)block; - (void)presentRateAlert; - (void)presentFacebookAlert; - (void)presentPoint2PointAlertWithOkBlock:(nonnull TMWMVoidBlock)block needToRebuild:(BOOL)needToRebuild; +- (void)presentNeedMigrationAlertWithOkBlock:(nonnull TMWMVoidBlock)block; - (void)presentRoutingDisclaimerAlert; - (void)presentDisabledLocationAlert; - (void)presentLocationAlert; diff --git a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm index 81f2ce1ac7..812701f731 100644 --- a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm +++ b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm @@ -66,6 +66,11 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController [self displayAlert:[MWMAlert point2PointAlertWithOkBlock:block needToRebuild:needToRebuild]]; } +- (void)presentNeedMigrationAlertWithOkBlock:(nonnull CloseAlertCompletion)block +{ + [self displayAlert:[MWMAlert needMigrationAlertWithOkBlock:block]]; +} + - (void)presentFacebookAlert { [self displayAlert:MWMAlert.facebookAlert]; @@ -94,8 +99,9 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController - (void)presentDownloaderAlertWithCountries:(vector const &)countries routes:(vector const &)routes code:(routing::IRouter::ResultCode)code + block:(TMWMVoidBlock)block { - [self displayAlert:[MWMAlert downloaderAlertWithAbsentCountries:countries routes:routes code:code]]; + [self displayAlert:[MWMAlert downloaderAlertWithAbsentCountries:countries routes:routes code:code block:block]]; } - (void)presentRoutingDisclaimerAlert diff --git a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h index 0f5f38bd9b..933a832a8e 100644 --- a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h +++ b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h @@ -9,7 +9,8 @@ + (MWMAlert *)alert:(routing::IRouter::ResultCode)type; + (MWMAlert *)downloaderAlertWithAbsentCountries:(vector const &)countries routes:(vector const &)routes - code:(routing::IRouter::ResultCode)code; + code:(routing::IRouter::ResultCode)code + block:(TMWMVoidBlock)block; + (MWMAlert *)rateAlert; + (MWMAlert *)facebookAlert; + (MWMAlert *)locationAlert; @@ -20,6 +21,7 @@ + (MWMAlert *)locationServiceNotSupportedAlert; + (MWMAlert *)pedestrianToastShareAlert:(BOOL)isFirstLaunch; + (MWMAlert *)point2PointAlertWithOkBlock:(TMWMVoidBlock)block needToRebuild:(BOOL)needToRebuild; ++ (MWMAlert *)needMigrationAlertWithOkBlock:(TMWMVoidBlock)block; - (void)close; - (void)setNeedsCloseAlertAfterEnterBackground; diff --git a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm index 4895689bc5..bcfbecaef2 100644 --- a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm @@ -31,6 +31,11 @@ return [MWMDefaultAlert point2PointAlertWithOkBlock:block needToRebuild:needToRebuild]; } ++ (MWMAlert *)needMigrationAlertWithOkBlock:(TMWMVoidBlock)block +{ + return [MWMDefaultAlert needMigrationAlertWithOkBlock:block]; +} + + (MWMAlert *)routingDisclaimerAlertWithInitialOrientation:(UIInterfaceOrientation)orientation { return [MWMRoutingDisclaimerAlert alertWithInitialOrientation:orientation]; @@ -59,8 +64,9 @@ + (MWMAlert *)downloaderAlertWithAbsentCountries:(vector const &)countries routes:(vector const &)routes code:(routing::IRouter::ResultCode)code + block:(TMWMVoidBlock)block { - return [MWMDownloadTransitMapAlert downloaderAlertWithMaps:countries routes:routes code:code]; + return [MWMDownloadTransitMapAlert downloaderAlertWithMaps:countries routes:routes code:code block:block]; } + (MWMAlert *)alert:(routing::IRouter::ResultCode)type diff --git a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.h b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.h index 7008165e8a..f2d380d43a 100644 --- a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.h +++ b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.h @@ -14,5 +14,6 @@ + (instancetype)noConnectionAlert; + (instancetype)locationServiceNotSupportedAlert; + (instancetype)point2PointAlertWithOkBlock:(TMWMVoidBlock)block needToRebuild:(BOOL)needToRebuild; ++ (instancetype)needMigrationAlertWithOkBlock:(TMWMVoidBlock)block; @end diff --git a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.mm b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.mm index b7f4bb5aef..e5c01857d1 100644 --- a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.mm @@ -124,6 +124,15 @@ static NSString * const kDefaultAlertNibName = @"MWMDefaultAlert"; } } ++ (instancetype)needMigrationAlertWithOkBlock:(TMWMVoidBlock)block +{ + return [self defaultAlertWithTitle:@"need_migrate_title" + message:@"need_migrate_message" + rightButtonTitle:@"migrate" + leftButtonTitle:@"not_now" + rightButtonAction:block]; +} + + (instancetype)defaultAlertWithTitle:(nonnull NSString *)title message:(nullable NSString *)message rightButtonTitle:(nonnull NSString *)rightButtonTitle leftButtonTitle:(nullable NSString *)leftButtonTitle rightButtonAction:(nullable TMWMVoidBlock)action { [[Statistics instance] logEvent:kStatisticsEvent withParameters:@{kStatAction : kStatOpen}]; diff --git a/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.h b/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.h index 9690df211f..a12b4c68c0 100644 --- a/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.h +++ b/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.h @@ -7,7 +7,8 @@ + (instancetype)downloaderAlertWithMaps:(vector const &)maps routes:(vector const &)routes - code:(routing::IRouter::ResultCode)code; + code:(routing::IRouter::ResultCode)code + block:(TMWMVoidBlock)block; - (void)showDownloadDetail:(UIButton *)sender; @end diff --git a/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.mm b/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.mm index 39b79154b0..c11114d57c 100644 --- a/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.mm @@ -86,6 +86,7 @@ static NSString * const kStatisticsEvent = @"Map download Alert"; + (instancetype)downloaderAlertWithMaps:(vector const &)maps routes:(vector const &)routes code:(routing::IRouter::ResultCode)code + block:(TMWMVoidBlock)block { [[Statistics instance] logEvent:kStatisticsEvent withParameters:@{kStatAction : kStatOpen}]; MWMDownloadTransitMapAlert * alert = [self alertWithMaps:maps routes:routes]; @@ -109,6 +110,7 @@ static NSString * const kStatisticsEvent = @"Map download Alert"; NSAssert(false, @"Incorrect code!"); break; } + alert.downloaderBlock = block; return alert; } @@ -129,16 +131,6 @@ static NSString * const kStatisticsEvent = @"Map download Alert"; alert.missedFiles = missedFiles; alert->maps = maps; alert->routes = routes; - __weak MWMDownloadTransitMapAlert * wAlert = alert; - alert.downloaderBlock = ^() - { - __strong MWMDownloadTransitMapAlert * alert = wAlert; - auto & a = GetFramework().GetCountryTree().GetActiveMapLayout(); - for (auto const & index : alert->maps) - a.DownloadMap(index, MapOptions::MapWithCarRouting); - for (auto const & index : alert->routes) - a.DownloadMap(index, MapOptions::CarRouting); - }; [alert configure]; return alert; } diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm index b2bf6db13b..79d9fb1bcd 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm @@ -207,9 +207,7 @@ extern NSString * const kAlohalyticsTapEventKey; - (void)actionDownloadMaps { - [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"downloader"]; - CountryTreeVC * vc = [[CountryTreeVC alloc] initWithNodePosition:-1]; - [self.ownerController.navigationController pushViewController:vc animated:YES]; + [self.ownerController downloadMaps]; } #pragma mark - MWMBottomMenuControllerProtocol diff --git a/iphone/Maps/Classes/MapViewController.h b/iphone/Maps/Classes/MapViewController.h index a2c39feb39..653c4faf24 100644 --- a/iphone/Maps/Classes/MapViewController.h +++ b/iphone/Maps/Classes/MapViewController.h @@ -35,6 +35,7 @@ namespace search { struct AddressInfo; } - (void)performAction:(NSString *)action; - (void)openBookmarks; +- (void)downloadMaps; - (void)refreshAd; diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index acdb1d8d90..f6bcd6ea76 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -1,6 +1,7 @@ #import "BookmarksRootVC.h" #import "BookmarksVC.h" #import "Common.h" +#import "CountryTreeVC.h" #import "EAGLView.h" #import "MapsAppDelegate.h" #import "MapViewController.h" @@ -32,6 +33,7 @@ #include "drape_frontend/user_event_stream.hpp" #include "platform/file_logging.hpp" +#include "platform/local_country_file_utils.hpp" #include "platform/platform.hpp" #include "platform/settings.hpp" @@ -554,32 +556,35 @@ NSString * const kAuthorizationSegue = @"Map2AuthorizationSegue"; } else { - LocalAndRemoteSizeT sizes = layout.GetRemoteCountrySizes(idx); - uint64_t sizeToDownload = sizes.first; - MapOptions options = static_cast(opt); - if(HasOptions(options, MapOptions::CarRouting)) - sizeToDownload += sizes.second; - - NSString * name = @(layout.GetCountryName(idx).c_str()); - Platform::EConnectionType const connection = Platform::ConnectionStatus(); - if (connection != Platform::EConnectionType::CONNECTION_NONE) + [self checkMigrationAndCallBlock:^ { - if (connection == Platform::EConnectionType::CONNECTION_WWAN && sizeToDownload > 50 * MB) + LocalAndRemoteSizeT sizes = layout.GetRemoteCountrySizes(idx); + uint64_t sizeToDownload = sizes.first; + MapOptions options = static_cast(opt); + if(HasOptions(options, MapOptions::CarRouting)) + sizeToDownload += sizes.second; + + NSString * name = @(layout.GetCountryName(idx).c_str()); + Platform::EConnectionType const connection = Platform::ConnectionStatus(); + if (connection != Platform::EConnectionType::CONNECTION_NONE) { - [self.alertController presentnoWiFiAlertWithName:name downloadBlock:^ + if (connection == Platform::EConnectionType::CONNECTION_WWAN && sizeToDownload > 50 * MB) { - layout.DownloadMap(idx, static_cast(opt)); - }]; + [self.alertController presentnoWiFiAlertWithName:name downloadBlock:^ + { + layout.DownloadMap(idx, static_cast(opt)); + }]; + return; + } + } + else + { + [self.alertController presentNoConnectionAlert]; return; } - } - else - { - [self.alertController presentNoConnectionAlert]; - return; - } - layout.DownloadMap(idx, static_cast(opt)); + layout.DownloadMap(idx, static_cast(opt)); + }]; } }); @@ -600,6 +605,31 @@ NSString * const kAuthorizationSegue = @"Map2AuthorizationSegue"; }); } +- (void)checkMigrationAndCallBlock:(TMWMVoidBlock)block +{ + if (platform::migrate::NeedMigrate()) + { + [self.alertController presentNeedMigrationAlertWithOkBlock:^ + { + GetFramework().Migrate(); + }]; + } + else + { + block(); + } +} + +- (void)downloadMaps +{ + [self checkMigrationAndCallBlock:^ + { + [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"downloader"]; + CountryTreeVC * vc = [[CountryTreeVC alloc] initWithNodePosition:-1]; + [self.navigationController pushViewController:vc animated:YES]; + }]; +} + - (void)processRoutingBuildingEvent:(routing::IRouter::ResultCode)code countries:(vector const &)absentCountries routes:(vector const &)absentRoutes @@ -633,10 +663,22 @@ NSString * const kAuthorizationSegue = @"Map2AuthorizationSegue"; case routing::IRouter::NeedMoreMaps: case routing::IRouter::FileTooOld: case routing::IRouter::RouteNotFound: + { [self.controlsManager handleRoutingError]; - [self presentDownloaderAlert:code countries:absentCountries routes:absentRoutes]; + [self presentDownloaderAlert:code countries:absentCountries routes:absentRoutes block:^ + { + [self checkMigrationAndCallBlock:^ + { + auto & a = GetFramework().GetCountryTree().GetActiveMapLayout(); + for (auto const & index : absentCountries) + a.DownloadMap(index, MapOptions::MapWithCarRouting); + for (auto const & index : absentRoutes) + a.DownloadMap(index, MapOptions::CarRouting); + }]; + }]; self.forceRoutingStateChange = ForceRoutingStateChangeNone; break; + } case routing::IRouter::Cancelled: self.forceRoutingStateChange = ForceRoutingStateChangeNone; break; @@ -748,9 +790,10 @@ NSString * const kAuthorizationSegue = @"Map2AuthorizationSegue"; - (void)presentDownloaderAlert:(routing::IRouter::ResultCode)code countries:(vector const &)countries routes:(vector const &)routes + block:(TMWMVoidBlock)block { if (countries.size() || routes.size()) - [self.alertController presentDownloaderAlertWithCountries:countries routes:routes code:code]; + [self.alertController presentDownloaderAlertWithCountries:countries routes:routes code:code block:block]; else [self presentDefaultAlert:code]; }