From 0241eebabf2897010495c1d5515138e629fafecf Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Fri, 29 Apr 2016 13:16:29 +0300 Subject: [PATCH] [ios] Fixed duplicate alerts bug. --- .../AlertController/MWMAlertViewController.mm | 78 ++++++++++++------- iphone/Maps/Classes/MapViewController.mm | 38 ++++----- 2 files changed, 64 insertions(+), 52 deletions(-) diff --git a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm index 902f31b68a..85b3b8b60c 100644 --- a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm +++ b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm @@ -23,8 +23,8 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { - MWMAlert * alert = self.view.subviews.firstObject; - [alert rotate:toInterfaceOrientation duration:duration]; + for (MWMAlert * alert in self.view.subviews) + [alert rotate:toInterfaceOrientation duration:duration]; } #pragma mark - Actions @@ -137,28 +137,6 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController [self displayAlert:[MWMAlert alert:type]]; } -- (void)displayAlert:(MWMAlert *)alert -{ - [self removeFromParentViewController]; - alert.alertController = self; - [self.ownerViewController addChildViewController:self]; - self.view.alpha = 0.; - alert.alpha = 0.; - if (!isIOS7) - { - CGFloat const scale = 1.1; - alert.transform = CGAffineTransformMakeScale(scale, scale); - } - [UIView animateWithDuration:kDefaultAnimationDuration animations:^ - { - self.view.alpha = 1.; - alert.alpha = 1.; - if (!isIOS7) - alert.transform = CGAffineTransformIdentity; - }]; - [MapsAppDelegate.theApp.window endEditing:YES]; -} - - (void)presentDisableAutoDownloadAlertWithOkBlock:(nonnull TMWMVoidBlock)okBlock { [self displayAlert:[MWMAlert disableAutoDownloadAlertWithOkBlock:okBlock]]; @@ -209,21 +187,61 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController [self displayAlert:[MWMAlert osmAuthAlert]]; } +- (void)displayAlert:(MWMAlert *)alert +{ + [UIView animateWithDuration:kDefaultAnimationDuration animations:^ + { + for (MWMAlert * view in self.view.subviews) + view.alpha = 0.0; + } + completion:^(BOOL finished) + { + for (MWMAlert * view in self.view.subviews) + { + if (view != alert) + view.hidden = YES; + } + }]; + + [self removeFromParentViewController]; + alert.alertController = self; + [self.ownerViewController addChildViewController:self]; + self.view.alpha = 0.; + alert.alpha = 0.; + if (!isIOS7) + { + CGFloat const scale = 1.1; + alert.transform = CGAffineTransformMakeScale(scale, scale); + } + [UIView animateWithDuration:kDefaultAnimationDuration animations:^ + { + self.view.alpha = 1.; + alert.alpha = 1.; + if (!isIOS7) + alert.transform = CGAffineTransformIdentity; + }]; + [MapsAppDelegate.theApp.window endEditing:YES]; +} + - (void)closeAlert { NSArray * subviews = self.view.subviews; - MWMAlert * alert = subviews.firstObject; - BOOL const isLastAlert = (subviews.count == 1); + MWMAlert * closeAlert = subviews.lastObject; + MWMAlert * showAlert = (subviews.count >= 2 ? subviews[subviews.count - 2] : nil); + if (showAlert) + showAlert.hidden = NO; [UIView animateWithDuration:kDefaultAnimationDuration animations:^ { - alert.alpha = 0.; - if (isLastAlert) + closeAlert.alpha = 0.; + if (showAlert) + showAlert.alpha = 1.; + else self.view.alpha = 0.; } completion:^(BOOL finished) { - [alert removeFromSuperview]; - if (isLastAlert) + [closeAlert removeFromSuperview]; + if (!showAlert) { [self.view removeFromSuperview]; [self removeFromParentViewController]; diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 36905da508..a0be9e2ff2 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -628,21 +628,8 @@ NSString * const kUDViralAlertWasShown = @"ViralAlertWasShown"; case routing::IRouter::NeedMoreMaps: case routing::IRouter::FileTooOld: case routing::IRouter::RouteNotFound: - { - if (platform::migrate::NeedMigrate()) - { - [self presentRoutingMigrationAlertWithOkBlock:^ - { - [Statistics logEvent:kStatDownloaderMigrationDialogue withParameters:@{kStatFrom : kStatRouting}]; - [self openMigration]; - }]; - } - else - { - [self presentDownloaderAlert:code countries:absentCountries]; - } + [self presentDownloaderAlert:code countries:absentCountries]; break; - } case routing::IRouter::Cancelled: break; default: @@ -776,25 +763,32 @@ NSString * const kUDViralAlertWasShown = @"ViralAlertWasShown"; #pragma mark - ShowDialog callback -- (void)presentRoutingMigrationAlertWithOkBlock:(TMWMVoidBlock)okBlock -{ - [self.alertController presentRoutingMigrationAlertWithOkBlock:okBlock]; -} - - (void)presentDownloaderAlert:(routing::IRouter::ResultCode)code countries:(storage::TCountriesVec const &)countries { - if (countries.size()) + if (platform::migrate::NeedMigrate()) + { + [self.alertController presentRoutingMigrationAlertWithOkBlock:^ + { + [Statistics logEvent:kStatDownloaderMigrationDialogue + withParameters:@{kStatFrom : kStatRouting}]; + [self openMigration]; + }]; + } + else if (!countries.empty()) { [self.alertController presentDownloaderAlertWithCountries:countries code:code cancelBlock:^ { - [self.controlsManager routingHidden]; + if (code != routing::IRouter::NeedMoreMaps) + [self.controlsManager routingHidden]; } downloadBlock:^(storage::TCountriesVec const & downloadCountries, TMWMVoidBlock onSuccess) { - [MWMStorage downloadNodes:downloadCountries alertController:self.alertController onSuccess:onSuccess]; + [MWMStorage downloadNodes:downloadCountries + alertController:self.alertController + onSuccess:onSuccess]; } downloadCompleteBlock:^ {