[iOS] Business logic AllPass/Sightseeing

https://jira.mail.ru/browse/MAPSME-12289
This commit is contained in:
Alexander Boriskov 2019-11-21 18:15:02 +03:00 committed by Aleksey Belousov
parent a12b4b8cd4
commit d9d00406e7
18 changed files with 71 additions and 21 deletions

View file

@ -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()
}

View file

@ -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")
}

View file

@ -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")
}

View file

@ -268,7 +268,7 @@ extension PaidRouteViewController : SubscriptionManagerListener {
}
func didSubscribe(_ subscription: ISubscription) {
MWMPurchaseManager.setBookmarksSubscriptionActive(true)
subscriptionManager.setSubscriptionActive(true)
MWMBookmarksManager.shared().resetInvalidCategories()
}

View file

@ -165,7 +165,7 @@ extension BaseSubscriptionViewController: SubscriptionManagerListener {
}
func didSubscribe(_ subscription: ISubscription) {
MWMPurchaseManager.setBookmarksSubscriptionActive(true)
subscriptionManager?.setSubscriptionActive(true)
bookmarksManager.resetInvalidCategories()
}

View file

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

View file

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

View file

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

View file

@ -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];
}];

View file

@ -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()
}

View file

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

View file

@ -29,6 +29,7 @@ typedef void (^StartTransactionCallback)(BOOL success, NSString * serverId);
+ (NSArray<NSString *> *)bookmarkInappIds;
+ (void)setAdsDisabled:(BOOL)disabled;
+ (void)setBookmarksSubscriptionActive:(BOOL)active;
+ (void)setAllPassSubscriptionActive:(BOOL)active;
- (instancetype)initWithVendorId:(NSString *)vendorId;
- (void)validateReceipt:(NSString *)serverId

View file

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

View file

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

View file

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

View file

@ -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");

View file

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

View file

@ -13,6 +13,7 @@ enum class SubscriptionType : uint8_t
{
RemoveAds = 0,
BookmarkCatalog,
AllPass,
Count
};