diff --git a/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift b/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift index 0e20ab1cb5..bd865c4ded 100644 --- a/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift @@ -207,7 +207,8 @@ final class CatalogWebViewController: WebViewController { private func showSubscribe(type: SubscriptionGroupType) { let subscribeViewController = SubscriptionViewBuilder.build(type: type, parentViewController: self, - source: kStatWebView) { [weak self] (success) in + source: kStatWebView, + openCatalog: false) { [weak self] (success) in if (success) { self?.webView.reloadFromOrigin() } diff --git a/iphone/Maps/Bookmarks/Catalog/Dialogs/SubscriptionGoToCatalogViewController.swift b/iphone/Maps/Bookmarks/Catalog/Dialogs/SubscriptionGoToCatalogViewController.swift index 2a940d4125..af7783ff43 100644 --- a/iphone/Maps/Bookmarks/Catalog/Dialogs/SubscriptionGoToCatalogViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/Dialogs/SubscriptionGoToCatalogViewController.swift @@ -23,10 +23,10 @@ override func awakeFromNib() { super.awakeFromNib() switch screenType { - case .allPass: + case .sightseeing: titleLabel.text = L("subscription_success_dialog_title_sightseeing_pass") textLabel.text = L("subscription_success_dialog_message_sightseeing_pass") - case .sightseeing: + case .allPass: titleLabel.text = L("subscription_success_dialog_title") textLabel.text = L("subscription_success_dialog_message") } diff --git a/iphone/Maps/Bookmarks/Catalog/Dialogs/SubscriptionSuccessViewController.swift b/iphone/Maps/Bookmarks/Catalog/Dialogs/SubscriptionSuccessViewController.swift index 5c82c9870f..1b17a96903 100644 --- a/iphone/Maps/Bookmarks/Catalog/Dialogs/SubscriptionSuccessViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/Dialogs/SubscriptionSuccessViewController.swift @@ -21,10 +21,10 @@ class SubscriptionSuccessViewController: UIViewController { override func awakeFromNib() { super.awakeFromNib() switch screenType { - case .allPass: + case .sightseeing: titleLabel.text = L("subscription_success_dialog_title_sightseeing_pass") textLabel.text = L("subscription_success_dialog_message_sightseeing_pass") - case .sightseeing: + case .allPass: titleLabel.text = L("subscription_success_dialog_title") textLabel.text = L("subscription_success_dialog_message") } diff --git a/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift b/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift index f27841b49c..b6025b6738 100644 --- a/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift @@ -268,7 +268,7 @@ extension PaidRouteViewController : SubscriptionManagerListener { } func didSubscribe(_ subscription: ISubscription) { - MWMPurchaseManager.setBookmarksSubscriptionActive(true) + subscriptionManager.setSubscriptionActive(true) MWMBookmarksManager.shared().resetInvalidCategories() } diff --git a/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift b/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift index 97fbc89cdb..f2061d161a 100644 --- a/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift @@ -165,7 +165,7 @@ extension BaseSubscriptionViewController: SubscriptionManagerListener { } func didSubscribe(_ subscription: ISubscription) { - MWMPurchaseManager.setBookmarksSubscriptionActive(true) + subscriptionManager?.setSubscriptionActive(true) bookmarksManager.resetInvalidCategories() } diff --git a/iphone/Maps/Bookmarks/Catalog/Subscription/SubscriptionViewBuilder.swift b/iphone/Maps/Bookmarks/Catalog/Subscription/SubscriptionViewBuilder.swift index cd41967a80..7ad98ca90d 100644 --- a/iphone/Maps/Bookmarks/Catalog/Subscription/SubscriptionViewBuilder.swift +++ b/iphone/Maps/Bookmarks/Catalog/Subscription/SubscriptionViewBuilder.swift @@ -2,6 +2,7 @@ class SubscriptionViewBuilder { static func build(type: SubscriptionGroupType, parentViewController: UIViewController, source: String, + openCatalog: Bool, completion: ((Bool) -> Void)?) -> UIViewController { let subscribeViewController: BaseSubscriptionViewController switch type { @@ -14,10 +15,21 @@ class SubscriptionViewBuilder { subscribeViewController.onSubscribe = { completion?(true); parentViewController.dismiss(animated: true) - let successDialog = SubscriptionSuccessViewController(type) { - parentViewController.dismiss(animated: true) + if openCatalog { + let successDialog = SubscriptionGoToCatalogViewController(type, onOk: { + parentViewController.dismiss(animated: true) + let webViewController = CatalogWebViewController.catalogFromAbsoluteUrl(nil, utm: .none) + parentViewController.navigationController?.pushViewController(webViewController, animated: true) + }) { + parentViewController.dismiss(animated: true) + } + parentViewController.present(successDialog, animated: true) + } else { + let successDialog = SubscriptionSuccessViewController(type) { + parentViewController.dismiss(animated: true) + } + parentViewController.present(successDialog, animated: true) } - parentViewController.present(successDialog, animated: true) } subscribeViewController.onCancel = { completion?(false) diff --git a/iphone/Maps/Bookmarks/Catalog/UIViewController+Subscription.swift b/iphone/Maps/Bookmarks/Catalog/UIViewController+Subscription.swift index dccb1f8ecc..f4cdd8854c 100644 --- a/iphone/Maps/Bookmarks/Catalog/UIViewController+Subscription.swift +++ b/iphone/Maps/Bookmarks/Catalog/UIViewController+Subscription.swift @@ -7,7 +7,7 @@ extension UIViewController { let onSubscribe = { self?.dismiss(animated: true) - let subscriptionDialog = BookmarksSubscriptionViewController() + let subscriptionDialog = AllPassSubscriptionViewController() subscriptionDialog.onSubscribe = { [weak self] in self?.dismiss(animated: true) } diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/PromoButton/PromoButton.swift b/iphone/Maps/Classes/CustomViews/MapViewControls/PromoButton/PromoButton.swift index 9509b4c94d..69055c13db 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/PromoButton/PromoButton.swift +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/PromoButton/PromoButton.swift @@ -3,7 +3,6 @@ import UIKit @objc class PromoButton: UIButton { private let coordinator: PromoCoordinator - private var timer: Timer? private let buttonSize: CGSize = CGSize(width: 48, height: 48) @objc init(coordinator: PromoCoordinator) { @@ -18,8 +17,7 @@ import UIKit private func configure() { removeTarget(self, action: nil, for: .touchUpInside) - timer?.invalidate() - timer = nil + self.subviews.forEach({ $0.removeFromSuperview() }) configureDiscovery() } @@ -52,14 +50,13 @@ import UIKit animationGroup.duration = 3 animationGroup.repeatCount = Float(Int.max) animationGroup.animations = [animation] + animationGroup.isRemovedOnCompletion = false imageView?.layer.add(animationGroup, forKey: "transform.rotation.z") } @objc private func onButtonPress(sender: UIButton) { coordinator.onPromoButtonPress(completion: { [weak self] in self?.isHidden = true; - self?.timer?.invalidate() - self?.timer = nil }) } diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm index d0821aa76b..ee401d41c8 100644 --- a/iphone/Maps/Classes/MapsAppDelegate.mm +++ b/iphone/Maps/Classes/MapsAppDelegate.mm @@ -252,6 +252,11 @@ using namespace osm_auth_ios; [MWMPurchaseManager setBookmarksSubscriptionActive:NO]; } }]; + [[InAppPurchase allPassSubscriptionManager] validateWithCompletion:^(MWMValidationResult result) { + if (result == MWMValidationResultNotValid) { + [MWMPurchaseManager setAllPassSubscriptionActive:NO]; + } + }]; [[InAppPurchase adsRemovalSubscriptionManager] validateWithCompletion:^(MWMValidationResult result) { [MWMPurchaseManager setAdsDisabled:result != MWMValidationResultNotValid]; }]; diff --git a/iphone/Maps/Core/DeepLink/DeepLinkHandler.swift b/iphone/Maps/Core/DeepLink/DeepLinkHandler.swift index ddf4dac1bb..048318fd9d 100644 --- a/iphone/Maps/Core/DeepLink/DeepLinkHandler.swift +++ b/iphone/Maps/Core/DeepLink/DeepLinkHandler.swift @@ -116,7 +116,7 @@ class DeepLinkURL { assertionFailure() return } - LOG(.info, "Handle deeplink: \(url)") + LOG(.info, "Handle deeplink: \(url.url)") let deeplinkHandlerStrategy = DeepLinkStrategyFactory.create(url: url) deeplinkHandlerStrategy.execute() } diff --git a/iphone/Maps/Core/DeepLink/Strategies/DeepLinkSubscriptionStrategy.swift b/iphone/Maps/Core/DeepLink/Strategies/DeepLinkSubscriptionStrategy.swift index ac4e2f8005..08324c2f97 100644 --- a/iphone/Maps/Core/DeepLink/Strategies/DeepLinkSubscriptionStrategy.swift +++ b/iphone/Maps/Core/DeepLink/Strategies/DeepLinkSubscriptionStrategy.swift @@ -26,6 +26,7 @@ class DeepLinkSubscriptionStrategy: IDeepLinkHandlerStrategy { let subscriptionViewController = SubscriptionViewBuilder.build(type: type, parentViewController: mapViewController, source: kStatDeeplink, + openCatalog: true, completion: nil) mapViewController.present(subscriptionViewController, animated: true, completion: nil) sendStatisticsOnSuccess(type: kStatSubscription) diff --git a/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.h b/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.h index 457ac5eb5f..0dc0386c4f 100644 --- a/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.h +++ b/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.h @@ -29,6 +29,7 @@ typedef void (^StartTransactionCallback)(BOOL success, NSString * serverId); + (NSArray *)bookmarkInappIds; + (void)setAdsDisabled:(BOOL)disabled; + (void)setBookmarksSubscriptionActive:(BOOL)active; ++ (void)setAllPassSubscriptionActive:(BOOL)active; - (instancetype)initWithVendorId:(NSString *)vendorId; - (void)validateReceipt:(NSString *)serverId diff --git a/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.mm b/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.mm index 881e59ad64..0387e9a576 100644 --- a/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.mm +++ b/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.mm @@ -196,6 +196,10 @@ GetFramework().GetPurchase()->SetSubscriptionEnabled(SubscriptionType::BookmarkCatalog, active); } ++ (void)setAllPassSubscriptionActive:(BOOL)active { + GetFramework().GetPurchase()->SetSubscriptionEnabled(SubscriptionType::AllPass, active); +} + #pragma mark - SKRequestDelegate - (void)requestDidFinish:(SKRequest *)request diff --git a/iphone/Maps/Core/Subscriptions/Subscription.swift b/iphone/Maps/Core/Subscriptions/Subscription.swift index 6ee6973640..7462b4a068 100644 --- a/iphone/Maps/Core/Subscriptions/Subscription.swift +++ b/iphone/Maps/Core/Subscriptions/Subscription.swift @@ -13,13 +13,15 @@ } class Subscription: ISubscription { - public static let productIds = MWMPurchaseManager.productIds() + MWMPurchaseManager.bookmakrsProductIds() + public static let productIds = MWMPurchaseManager.productIds() + MWMPurchaseManager.bookmakrsProductIds() + MWMPurchaseManager.allPassProductIds() public static let legacyProductIds = MWMPurchaseManager.legacyProductIds() private static let periodMap: [String: SubscriptionPeriod] = [productIds[0]: .year, productIds[1]: .month, productIds[2]: .week, productIds[3]: .year, - productIds[4]: .month] + productIds[4]: .month, + productIds[5]: .year, + productIds[6]: .month] var productId: String var period: SubscriptionPeriod var price: NSDecimalNumber diff --git a/iphone/Maps/Core/Subscriptions/SubscriptionManager.swift b/iphone/Maps/Core/Subscriptions/SubscriptionManager.swift index 3b861dd71c..bd092f1ba6 100644 --- a/iphone/Maps/Core/Subscriptions/SubscriptionManager.swift +++ b/iphone/Maps/Core/Subscriptions/SubscriptionManager.swift @@ -13,6 +13,7 @@ @objc func removeListener(_ listener: SubscriptionManagerListener) @objc func validate(completion: ValidationCompletion?) @objc func restore(_ callback: @escaping ValidationCompletion) + @objc func setSubscriptionActive(_ value: Bool) } @objc protocol SubscriptionManagerListener: AnyObject { @@ -85,6 +86,19 @@ class SubscriptionManager: NSObject, ISubscriptionManager { } } + func setSubscriptionActive(_ value: Bool) { + switch serverId { + case MWMPurchaseManager.allPassSubscriptionServerId(): + MWMPurchaseManager.setAllPassSubscriptionActive(value) + case MWMPurchaseManager.bookmarksSubscriptionServerId(): + MWMPurchaseManager.setBookmarksSubscriptionActive(value) + case MWMPurchaseManager.adsRemovalServerId(): + MWMPurchaseManager.setAdsDisabled(value) + default: + fatalError() + } + } + private func validate(_ refreshReceipt: Bool, completion: ValidationCompletion? = nil) { purchaseManager?.validateReceipt(serverId, refreshReceipt: refreshReceipt) { [weak self] (_, validationResult) in self?.logEvents(validationResult) diff --git a/iphone/Maps/UI/Settings/MWMSettingsViewController.mm b/iphone/Maps/UI/Settings/MWMSettingsViewController.mm index e0e1d7fdd7..ddbfdfa772 100644 --- a/iphone/Maps/UI/Settings/MWMSettingsViewController.mm +++ b/iphone/Maps/UI/Settings/MWMSettingsViewController.mm @@ -437,6 +437,7 @@ using namespace power_management; self.restoringSubscription = YES; __block MWMValidationResult adsResult; __block MWMValidationResult bookmarksResult; + __block MWMValidationResult allPassResult; dispatch_group_enter(dispatchGroup); [[InAppPurchase adsRemovalSubscriptionManager] restore:^(MWMValidationResult result) { @@ -450,15 +451,25 @@ using namespace power_management; dispatch_group_leave(dispatchGroup); }]; + dispatch_group_enter(dispatchGroup); + [[InAppPurchase allPassSubscriptionManager] restore:^(MWMValidationResult result) { + allPassResult = 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) { + if (adsResult == MWMValidationResultNotValid && + bookmarksResult == MWMValidationResultNotValid && + allPassResult == MWMValidationResultNotValid) { alertText = L(@"restore_no_subscription_alert"); - } else if (adsResult == MWMValidationResultValid || bookmarksResult == MWMValidationResultValid) { + } else if (adsResult == MWMValidationResultValid || + bookmarksResult == MWMValidationResultValid || + allPassResult == MWMValidationResultValid) { alertText = L(@"restore_success_alert"); } else { alertText = L(@"restore_error_alert"); diff --git a/iphone/Maps/UI/Welcome/PromoDiscovery/PromoDiscoveryRouter.swift b/iphone/Maps/UI/Welcome/PromoDiscovery/PromoDiscoveryRouter.swift index 86324e5ef6..90bd52214d 100644 --- a/iphone/Maps/UI/Welcome/PromoDiscovery/PromoDiscoveryRouter.swift +++ b/iphone/Maps/UI/Welcome/PromoDiscovery/PromoDiscoveryRouter.swift @@ -46,6 +46,7 @@ extension PromoDiscoveryRouter: IPromoDiscoveryRouter { let subscribeViewController = SubscriptionViewBuilder.build(type: .allPass, parentViewController: viewController, source: kStatOnboardingGuidesSubscription, + openCatalog: true, completion: nil) viewController.present(subscribeViewController, animated: true) } diff --git a/map/purchase.hpp b/map/purchase.hpp index ab25b4f92e..52c6dc5c38 100644 --- a/map/purchase.hpp +++ b/map/purchase.hpp @@ -13,6 +13,7 @@ enum class SubscriptionType : uint8_t { RemoveAds = 0, BookmarkCatalog, + AllPass, Count };