[iOS] Open subscription screen on empty tier

https://jira.mail.ru/browse/MAPSME-14512
This commit is contained in:
Alexander Boriskov 2020-08-07 11:37:23 +03:00 committed by Aleksey Belousov
parent 80b0ce2614
commit 585a2e0a60

View file

@ -6,6 +6,10 @@ struct CatalogCategoryInfo {
var imageUrl: String?
var subscriptionType: SubscriptionGroupType
var hasSinglePurchase: Bool {
return productId != nil
}
init?(_ components: [String: String], type: SubscriptionGroupType) {
guard let id = components["id"],
let name = components["name"] else { return nil }
@ -177,7 +181,7 @@ final class CatalogWebViewController: WebViewController {
}
if url.path.contains(subscribePath) {
showSubscribe(type: SubscriptionGroupType(catalogURL: url))
showSubscriptionBannerScreen(SubscriptionGroupType(catalogURL: url))
return
}
@ -213,18 +217,6 @@ final class CatalogWebViewController: WebViewController {
withParameters: [kStatError: kStatUnknown])
}
private func showSubscribe(type: SubscriptionGroupType) {
let subscribeViewController = SubscriptionViewBuilder.build(type: type,
parentViewController: self,
source: kStatWebView,
successDialog: .success) { [weak self] success in
if success {
self?.webView.reloadFromOrigin()
}
}
present(subscribeViewController, animated: true)
}
private func showOnMap(_ serverId: String) {
let groupId = BookmarksManager.shared().getGroupId(serverId)
FrameworkHelper.show(onMap: groupId)
@ -339,7 +331,11 @@ final class CatalogWebViewController: WebViewController {
}
}
case .needPayment:
self?.showPaymentScreen(categoryInfo)
if categoryInfo.hasSinglePurchase {
self?.showPaymentScreen(categoryInfo)
} else {
self?.showSubscriptionScreen(categoryInfo)
}
case .notFound:
self?.showServerError()
case .networkError:
@ -389,6 +385,31 @@ final class CatalogWebViewController: WebViewController {
navigationController?.present(paymentVC, animated: true)
}
private func showSubscriptionScreen(_ productInfo: CatalogCategoryInfo) {
let subscribeViewController = SubscriptionViewBuilder.build(type: productInfo.subscriptionType,
parentViewController: self,
source: kStatWebView,
successDialog: .none) { [weak self] success in
if success {
self?.webView.reloadFromOrigin()
self?.download()
}
}
present(subscribeViewController, animated: true)
}
private func showSubscriptionBannerScreen(_ type: SubscriptionGroupType) {
let subscribeViewController = SubscriptionViewBuilder.build(type: type,
parentViewController: self,
source: kStatWebView,
successDialog: .success) { [weak self] success in
if success {
self?.webView.reloadFromOrigin()
}
}
present(subscribeViewController, animated: true)
}
private func showDiskError() {
MWMAlertViewController.activeAlert().presentDownloaderNotEnoughSpaceAlert()
}