forked from organicmaps/organicmaps
[iOS] CatalogWebView: new parameter in urls for subscription groups
https://jira.mail.ru/browse/MAPSME-12424
This commit is contained in:
parent
8554b2de6b
commit
a3c791be14
6 changed files with 64 additions and 16 deletions
|
@ -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
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
private let transitioning = FadeTransitioning<AlertPresentationController>()
|
||||
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
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
class SubscriptionSuccessViewController: UIViewController {
|
||||
private let transitioning = FadeTransitioning<AlertPresentationController>()
|
||||
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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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 }
|
||||
|
|
Loading…
Add table
Reference in a new issue