diff options
Diffstat (limited to 'iphone/Maps/UI/Settings')
-rw-r--r-- | iphone/Maps/UI/Settings/MWMSettingsViewController.mm | 64 |
1 files changed, 43 insertions, 21 deletions
diff --git a/iphone/Maps/UI/Settings/MWMSettingsViewController.mm b/iphone/Maps/UI/Settings/MWMSettingsViewController.mm index fe086a8b52..7b48af0d2f 100644 --- a/iphone/Maps/UI/Settings/MWMSettingsViewController.mm +++ b/iphone/Maps/UI/Settings/MWMSettingsViewController.mm @@ -369,29 +369,11 @@ using namespace power_management; else if (cell == self.restoreSubscriptionCell) { [tableView deselectRowAtIndexPath:indexPath animated:YES]; - [self.restoreSubscriptionCell.progress startAnimating]; - self.restoringSubscription = YES; __weak auto s = self; - [[InAppPurchase adsRemovalSubscriptionManager] restore:^(MWMValidationResult result) { - __strong auto self = s; - self.restoringSubscription = NO; - [self.restoreSubscriptionCell.progress stopAnimating]; - NSString *alertText; - switch (result) - { - case MWMValidationResultValid: - alertText = L(@"restore_success_alert"); - break; - case MWMValidationResultNotValid: - alertText = L(@"restore_no_subscription_alert"); - break; - case MWMValidationResultServerError: - case MWMValidationResultAuthError: - alertText = L(@"restore_error_alert"); - break; + [self signupWithAnchor:self.restoreSubscriptionCell.progress onComplete:^(BOOL success) { + if (success) { + [s restoreSubscription]; } - [MWMAlertViewController.activeAlertController presentInfoAlert:L(@"restore_subscription") - text:alertText]; }]; } else if (cell == self.manageSubscriptionsCell) @@ -451,4 +433,44 @@ using namespace power_management; }]; } +#pragma mark - RestoreSubscription + +- (void)restoreSubscription { + dispatch_group_t dispatchGroup = dispatch_group_create(); + + [self.restoreSubscriptionCell.progress startAnimating]; + self.restoringSubscription = YES; + __block MWMValidationResult adsResult; + __block MWMValidationResult bookmarksResult; + + dispatch_group_enter(dispatchGroup); + [[InAppPurchase adsRemovalSubscriptionManager] restore:^(MWMValidationResult result) { + adsResult = result; + dispatch_group_leave(dispatchGroup); + }]; + + dispatch_group_enter(dispatchGroup); + [[InAppPurchase bookmarksSubscriptionManager] restore:^(MWMValidationResult result) { + bookmarksResult = result; + dispatch_group_leave(dispatchGroup); + }]; + + __weak auto s = self; + dispatch_group_notify(dispatchGroup, dispatch_get_main_queue(), ^{ + __strong auto self = s; + self.restoringSubscription = NO; + [self.restoreSubscriptionCell.progress stopAnimating]; + NSString *alertText; + if (adsResult == MWMValidationResultNotValid && bookmarksResult == MWMValidationResultNotValid) { + alertText = L(@"restore_no_subscription_alert"); + } else if (adsResult == MWMValidationResultValid || bookmarksResult == MWMValidationResultValid) { + alertText = L(@"restore_success_alert"); + } else { + alertText = L(@"restore_error_alert"); + } + [MWMAlertViewController.activeAlertController presentInfoAlert:L(@"restore_subscription") + text:alertText]; + }); +} + @end |