diff --git a/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift b/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift index e3ad7c692b..c59f56a687 100644 --- a/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift @@ -4,8 +4,9 @@ struct CatalogCategoryInfo { var author: String? var productId: String? var imageUrl: String? + var subscriptionType: SubscriptionGroupType - init?(_ components: [String : String]) { + init?(_ components: [String : String], type: SubscriptionGroupType) { guard let id = components["id"], let name = components["name"] else { return nil } self.id = id @@ -13,6 +14,7 @@ struct CatalogCategoryInfo { author = components["author_name"] productId = components["tier"] imageUrl = components["img"] + subscriptionType = type } } @@ -166,7 +168,7 @@ final class CatalogWebViewController: WebViewController { } if url.path.contains(subscribePath) { - showSubscribe(type: .sightseeing) + showSubscribe(type: SubscriptionGroupType(catalogURL: url)) decisionHandler(.cancel); return } @@ -202,7 +204,7 @@ final class CatalogWebViewController: WebViewController { withParameters: [kStatError : kStatUnknown]) } - private func showSubscribe(type: SubscriptionScreenType) { + private func showSubscribe(type: SubscriptionGroupType) { let subscribeViewController: BaseSubscriptionViewController switch type { case .allPass: @@ -286,7 +288,7 @@ final class CatalogWebViewController: WebViewController { guard let components = urlComponents.queryItems?.reduce(into: [:], { $0[$1.name] = $1.value }) else { return nil } - return CatalogCategoryInfo(components) + return CatalogCategoryInfo(components, type: SubscriptionGroupType(catalogURL: url)) } func processDeeplink(_ url: URL) { @@ -379,6 +381,7 @@ final class CatalogWebViewController: WebViewController { let paymentVC = PaidRouteViewController(name: productInfo.name, author: productInfo.author, imageUrl: URL(string: productInfo.imageUrl ?? ""), + subscriptionType: productInfo.subscriptionType, purchase: purchase, statistics: stats) paymentVC.delegate = self diff --git a/iphone/Maps/Bookmarks/Catalog/Dialogs/SubscriptionGoToCatalogViewController.swift b/iphone/Maps/Bookmarks/Catalog/Dialogs/SubscriptionGoToCatalogViewController.swift index b68aa33f6a..2a940d4125 100644 --- a/iphone/Maps/Bookmarks/Catalog/Dialogs/SubscriptionGoToCatalogViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/Dialogs/SubscriptionGoToCatalogViewController.swift @@ -2,12 +2,12 @@ private let transitioning = FadeTransitioning() private let onOk: MWMVoidBlock private let onCancel: MWMVoidBlock - private let screenType: SubscriptionScreenType + private let screenType: SubscriptionGroupType @IBOutlet private var titleLabel: UILabel! @IBOutlet private var textLabel: UILabel! - @objc init(_ screenType:SubscriptionScreenType, onOk: @escaping MWMVoidBlock, onCancel: @escaping MWMVoidBlock) { + @objc init(_ screenType:SubscriptionGroupType, onOk: @escaping MWMVoidBlock, onCancel: @escaping MWMVoidBlock) { self.onOk = onOk self.onCancel = onCancel self.screenType = screenType diff --git a/iphone/Maps/Bookmarks/Catalog/Dialogs/SubscriptionSuccessViewController.swift b/iphone/Maps/Bookmarks/Catalog/Dialogs/SubscriptionSuccessViewController.swift index 058a033c73..5c82c9870f 100644 --- a/iphone/Maps/Bookmarks/Catalog/Dialogs/SubscriptionSuccessViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/Dialogs/SubscriptionSuccessViewController.swift @@ -1,12 +1,12 @@ class SubscriptionSuccessViewController: UIViewController { private let transitioning = FadeTransitioning() private let onOk: MWMVoidBlock - private let screenType: SubscriptionScreenType + private let screenType: SubscriptionGroupType @IBOutlet private var titleLabel: UILabel! @IBOutlet private var textLabel: UILabel! - init(_ screenType:SubscriptionScreenType, onOk: @escaping MWMVoidBlock) { + init(_ screenType:SubscriptionGroupType, onOk: @escaping MWMVoidBlock) { self.onOk = onOk self.screenType = screenType super.init(nibName: nil, bundle: nil) diff --git a/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift b/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift index 64ae42d8dc..db6928135b 100644 --- a/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift @@ -37,6 +37,7 @@ class PaidRouteViewController: MWMViewController { init(name: String, author: String?, imageUrl: URL?, + subscriptionType: SubscriptionGroupType, purchase: IPaidRoutePurchase, statistics: IPaidRouteStatistics) { self.name = name @@ -44,7 +45,12 @@ class PaidRouteViewController: MWMViewController { self.imageUrl = imageUrl self.purchase = purchase self.statistics = statistics - self.subscriptionManager = InAppPurchase.bookmarksSubscriptionManager + switch subscriptionType { + case .sightseeing: + self.subscriptionManager = InAppPurchase.bookmarksSubscriptionManager + case .allPass: + self.subscriptionManager = InAppPurchase.allPassSubscriptionManager + } super.init(nibName: nil, bundle: nil) self.subscriptionManager.addListener(self) } diff --git a/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift b/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift index 30c7b15aab..cb4a780d94 100644 --- a/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift @@ -1,11 +1,5 @@ -import Foundation import SafariServices -@objc enum SubscriptionScreenType: Int{ - case allPass - case sightseeing -} - class BaseSubscriptionViewController: MWMViewController { //MARK: base outlets @IBOutlet private var loadingView: UIView! diff --git a/iphone/Maps/Core/Subscriptions/SubscriptionGroup.swift b/iphone/Maps/Core/Subscriptions/SubscriptionGroup.swift index 78b20886ac..c90a9f62e6 100644 --- a/iphone/Maps/Core/Subscriptions/SubscriptionGroup.swift +++ b/iphone/Maps/Core/Subscriptions/SubscriptionGroup.swift @@ -1,4 +1,49 @@ -import Foundation +@objc enum SubscriptionGroupType: Int { + case allPass + case sightseeing + + init?(serverId: String) { + switch serverId { + case MWMPurchaseManager.bookmarksSubscriptionServerId(): + self = .sightseeing + case MWMPurchaseManager.allPassSubscriptionServerId(): + self = .allPass + default: + return nil + } + } + + init(catalogURL: URL) { + guard let urlComponents = URLComponents(url: catalogURL, resolvingAgainstBaseURL: false) else { + self = .allPass + return + } + let subscriptionGroup = urlComponents.queryItems? + .filter({ $0.name == "groups" }) + .map({ $0.value ?? "" }) + .first(where: { + $0 == MWMPurchaseManager.allPassSubscriptionServerId() || + $0 == MWMPurchaseManager.bookmarksSubscriptionServerId() + }) + switch subscriptionGroup { + case MWMPurchaseManager.bookmarksSubscriptionServerId(): + self = .sightseeing + case MWMPurchaseManager.allPassSubscriptionServerId(): + self = .allPass + default: + self = .allPass + } + } + + var serverId: String { + switch self { + case .sightseeing: + return MWMPurchaseManager.bookmarksSubscriptionServerId() + case .allPass: + return MWMPurchaseManager.allPassSubscriptionServerId() + } + } +} protocol ISubscriptionGroup { var count: Int { get }