[iOS] restore all subsriptions from settings

https://jira.mail.ru/browse/MAPSME-11572
This commit is contained in:
Aleksey Belouosv 2019-08-22 14:00:24 +03:00 committed by Aleksey Belousov
parent 779d153c9f
commit 616ecb5ff8
2 changed files with 44 additions and 22 deletions

View file

@ -1,5 +1,5 @@
extension UIViewController {
func signup(anchor: UIView, onComplete: @escaping (Bool) -> Void) {
@objc func signup(anchor: UIView, onComplete: @escaping (Bool) -> Void) {
if MWMAuthorizationViewModel.isAuthenticated() {
onComplete(true)
} else {

View file

@ -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