diff --git a/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift b/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift index f753da6e2f..74cc1a5e0b 100644 --- a/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift @@ -6,7 +6,7 @@ struct CatalogCategoryInfo { var imageUrl: String? var subscriptionType: SubscriptionGroupType - init?(_ components: [String : String], type: SubscriptionGroupType) { + init?(_ components: [String: String], type: SubscriptionGroupType) { guard let id = components["id"], let name = components["name"] else { return nil } self.id = id @@ -33,11 +33,11 @@ final class CatalogWebViewController: WebViewController { var noInternetView: CatalogConnectionErrorView! @objc static func catalogFromAbsoluteUrl(_ url: URL? = nil, utm: MWMUTM = .none) -> CatalogWebViewController { - return CatalogWebViewController(url, utm:utm, isAbsoluteUrl:true) + return CatalogWebViewController(url, utm: utm, isAbsoluteUrl: true) } - + @objc static func catalogFromDeeplink(_ url: URL, utm: MWMUTM = .none) -> CatalogWebViewController { - return CatalogWebViewController(url, utm:utm) + return CatalogWebViewController(url, utm: utm) } private init(_ url: URL? = nil, utm: MWMUTM = .none, isAbsoluteUrl: Bool = false) { @@ -55,7 +55,7 @@ final class CatalogWebViewController: WebViewController { } else { deeplink = url } - Statistics.logEvent(kStatCatalogOpen, withParameters: [kStatFrom : kStatDeeplink]) + Statistics.logEvent(kStatCatalogOpen, withParameters: [kStatFrom: kStatDeeplink]) } } super.init(url: catalogUrl, title: L("guides_catalogue_title"))! @@ -109,7 +109,7 @@ final class CatalogWebViewController: WebViewController { let connected = FrameworkHelper.isNetworkConnected() if !connected { Statistics.logEvent("Bookmarks_Downloaded_Catalogue_error", - withParameters: [kStatError : "no_internet"]) + withParameters: [kStatError: "no_internet"]) } noInternetView.isHidden = connected @@ -125,8 +125,8 @@ final class CatalogWebViewController: WebViewController { } progressView.styleName = "MWMWhite" - self.view.styleName = "Background" - + view.styleName = "Background" + updateProgress() navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "ic_nav_bar_back"), style: .plain, @@ -135,7 +135,7 @@ final class CatalogWebViewController: WebViewController { navigationItem.rightBarButtonItem = UIBarButtonItem(title: L("core_exit"), style: .plain, target: self, - action: #selector(onExitPressed)) + action: #selector(onExitPressed)) } override func viewDidAppear(_ animated: Bool) { @@ -145,8 +145,8 @@ final class CatalogWebViewController: WebViewController { } } - override func willLoadUrl(_ decisionHandler: @escaping (Bool, Dictionary?) -> Void) { - buildHeaders { [weak self] (headers) in + override func willLoadUrl(_ decisionHandler: @escaping (Bool, [String: String]?) -> Void) { + buildHeaders { [weak self] headers in self?.handlePendingTransactions { decisionHandler($0, headers) self?.checkInvalidSubscription() @@ -173,7 +173,7 @@ final class CatalogWebViewController: WebViewController { } defer { - decisionHandler(.cancel); + decisionHandler(.cancel) } if url.path.contains(subscribePath) { @@ -202,7 +202,7 @@ final class CatalogWebViewController: WebViewController { override func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { loadingIndicator.stopAnimating() Statistics.logEvent("Bookmarks_Downloaded_Catalogue_error", - withParameters: [kStatError : kStatUnknown]) + withParameters: [kStatError: kStatUnknown]) } override func webView(_ webView: WKWebView, @@ -210,15 +210,15 @@ final class CatalogWebViewController: WebViewController { withError error: Error) { loadingIndicator.stopAnimating() Statistics.logEvent("Bookmarks_Downloaded_Catalogue_error", - withParameters: [kStatError : kStatUnknown]) + 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) { + successDialog: .success) { [weak self] success in + if success { self?.webView.reloadFromOrigin() } } @@ -231,9 +231,9 @@ final class CatalogWebViewController: WebViewController { navigationController?.popToRootViewController(animated: true) } - private func buildHeaders(completion: @escaping ([String : String]?) -> Void) { - billing.requestProducts(Set(MWMPurchaseManager.bookmarkInappIds()), completion: { (products, error) in - var productsInfo: [String : [String: String]] = [:] + private func buildHeaders(completion: @escaping ([String: String]?) -> Void) { + billing.requestProducts(Set(MWMPurchaseManager.bookmarkInappIds()), completion: { products, error in + var productsInfo: [String: [String: String]] = [:] if let products = products { let formatter = NumberFormatter() formatter.numberStyle = .currency @@ -250,7 +250,7 @@ final class CatalogWebViewController: WebViewController { completion(nil) return } - + var result = MWMBookmarksManager.shared().getCatalogHeaders() result["X-Mapsme-Bundle-Tiers"] = encodedString completion(result) @@ -258,7 +258,7 @@ final class CatalogWebViewController: WebViewController { } private func handlePendingTransactions(completion: @escaping (Bool) -> Void) { - pendingTransactionsHandler.handlePendingTransactions { [weak self] (status) in + pendingTransactionsHandler.handlePendingTransactions { [weak self] status in switch status { case .none: fallthrough @@ -282,7 +282,6 @@ final class CatalogWebViewController: WebViewController { } }) } - break; } } } @@ -293,7 +292,7 @@ final class CatalogWebViewController: WebViewController { } func processDeeplink(_ url: URL) { - self.deeplink = nil + deeplink = nil guard let categoryInfo = parseUrl(url) else { MWMAlertViewController.activeAlert().presentInfoAlert(L("title_error_downloading_bookmarks"), text: L("subtitle_error_downloading_guide")) @@ -319,9 +318,9 @@ final class CatalogWebViewController: WebViewController { return } - MWMBookmarksManager.shared().downloadItem(withId: categoryInfo.id, name: categoryInfo.name, progress: { [weak self] (progress) in + MWMBookmarksManager.shared().downloadItem(withId: categoryInfo.id, name: categoryInfo.name, progress: { [weak self] progress in self?.updateProgress() - }) { [weak self] (categoryId, error) in + }) { [weak self] categoryId, error in if let error = error as NSError? { if error.code == kCategoryDownloadFailedCode { guard let statusCode = error.userInfo[kCategoryDownloadStatusKey] as? NSNumber else { @@ -332,26 +331,21 @@ final class CatalogWebViewController: WebViewController { assertionFailure() return } - switch (status) { + switch status { case .needAuth: - if let s = self, let navBar = s.navigationController?.navigationBar{ + if let s = self, let navBar = s.navigationController?.navigationBar { s.signup(anchor: navBar, source: .guideCatalogue) { if $0 { s.download() } } } - break case .needPayment: self?.showPaymentScreen(categoryInfo) - break case .notFound: self?.showServerError() - break case .networkError: self?.showNetworkError() - break case .diskError: self?.showDiskError() - break } } else if error.code == kCategoryImportFailedCode { self?.showImportError() @@ -392,7 +386,7 @@ final class CatalogWebViewController: WebViewController { paymentVC.delegate = self paymentVC.modalTransitionStyle = .coverVertical paymentVC.modalPresentationStyle = .fullScreen - self.navigationController?.present(paymentVC, animated: true) + navigationController?.present(paymentVC, animated: true) } private func showDiskError() { @@ -400,7 +394,7 @@ final class CatalogWebViewController: WebViewController { } private func showNetworkError() { - MWMAlertViewController.activeAlert().presentNoConnectionAlert(); + MWMAlertViewController.activeAlert().presentNoConnectionAlert() } private func showServerError() { @@ -424,7 +418,7 @@ final class CatalogWebViewController: WebViewController { } @objc private func onBackPressed() { - if (webView.canGoBack) { + if webView.canGoBack { back() Statistics.logEvent(kStatGuidesBack, withParameters: [kStatMethod: kStatBack]) } else { @@ -445,14 +439,14 @@ final class CatalogWebViewController: WebViewController { private func logToPushWoosh(_ categoryInfo: CatalogCategoryInfo) { let pushManager = PushNotificationManager.push() - + if categoryInfo.productId == nil { - pushManager!.setTags(["Bookmarks_Guides_free_title": categoryInfo.name]); - pushManager!.setTags(["Bookmarks_Guides_free_date": MWMPushNotifications.formattedTimestamp()]); + pushManager!.setTags(["Bookmarks_Guides_free_title": categoryInfo.name]) + pushManager!.setTags(["Bookmarks_Guides_free_date": MWMPushNotifications.formattedTimestamp()]) } else { - pushManager!.setTags(["Bookmarks_Guides_paid_tier": categoryInfo.productId!]); - pushManager!.setTags(["Bookmarks_Guides_paid_title": categoryInfo.name]); - pushManager!.setTags(["Bookmarks_Guides_paid_date": MWMPushNotifications.formattedTimestamp()]); + pushManager!.setTags(["Bookmarks_Guides_paid_tier": categoryInfo.productId!]) + pushManager!.setTags(["Bookmarks_Guides_paid_title": categoryInfo.name]) + pushManager!.setTags(["Bookmarks_Guides_paid_date": MWMPushNotifications.formattedTimestamp()]) } } @@ -460,7 +454,7 @@ extension CatalogWebViewController: PaidRouteViewControllerDelegate { func didCompleteSubscription(_ viewController: PaidRouteViewController) { dismiss(animated: true) download() - self.webView.reloadFromOrigin() + webView.reloadFromOrigin() } func didCompletePurchase(_ viewController: PaidRouteViewController) { diff --git a/iphone/Maps/Bookmarks/Catalog/Subscription/AllPassSubscriptionViewController.swift b/iphone/Maps/Bookmarks/Catalog/Subscription/AllPassSubscriptionViewController.swift index 62d5472c23..700f197d28 100644 --- a/iphone/Maps/Bookmarks/Catalog/Subscription/AllPassSubscriptionViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/Subscription/AllPassSubscriptionViewController.swift @@ -1,5 +1,6 @@ class AllPassSubscriptionViewController: BaseSubscriptionViewController { - //MARK:outlets + // MARK: outlets + @IBOutlet private var backgroundImageView: ImageViewCrossDisolve! @IBOutlet private var annualSubscriptionButton: BookmarksSubscriptionButton! @IBOutlet private var annualDiscountLabel: InsetsLabel! @@ -11,25 +12,23 @@ class AllPassSubscriptionViewController: BaseSubscriptionViewController { //MARK: locals private var pageWidth: CGFloat { - return self.descriptionPageScrollView.frame.width; + return descriptionPageScrollView.frame.width } - private let maxPages = 3; + + private let maxPages = 3 private var currentPage: Int { - return Int(self.descriptionPageScrollView.contentOffset.x/self.pageWidth) + 1; + return Int(descriptionPageScrollView.contentOffset.x / pageWidth) + 1 } + private var animatingTask: DispatchWorkItem? private let animationDelay: TimeInterval = 2 private let animationDuration: TimeInterval = 0.75 private let animationBackDuration: TimeInterval = 0.3 private let statusBarBackVisibleThreshold: CGFloat = 60 - override var subscriptionManager: ISubscriptionManager? { - get { return InAppPurchase.allPassSubscriptionManager } - } - - override var preferredStatusBarStyle: UIStatusBarStyle { - get { return .lightContent } - } + override var subscriptionManager: ISubscriptionManager? { return InAppPurchase.allPassSubscriptionManager } + + override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) @@ -43,11 +42,11 @@ class AllPassSubscriptionViewController: BaseSubscriptionViewController { super.viewDidLoad() backgroundImageView.images = [ - UIImage.init(named: "AllPassSubscriptionBg1"), - UIImage.init(named: "AllPassSubscriptionBg2"), - UIImage.init(named: "AllPassSubscriptionBg3") + UIImage(named: "AllPassSubscriptionBg1"), + UIImage(named: "AllPassSubscriptionBg2"), + UIImage(named: "AllPassSubscriptionBg3") ] - startAnimating(); + startAnimating() annualSubscriptionButton.config(title: L("annual_subscription_title"), price: "...", @@ -63,17 +62,17 @@ class AllPassSubscriptionViewController: BaseSubscriptionViewController { let css = "" zip(descriptionSubtitles, ["all_pass_subscription_message_subtitle", "all_pass_subscription_message_subtitle_3", - "all_pass_subscription_message_subtitle_2"]).forEach { (title, loc) in + "all_pass_subscription_message_subtitle_2"]).forEach { title, loc in title.attributedText = NSAttributedString.string(withHtml: css + L(loc), defaultAttributes: [:]) } - self.configure(buttons: [ + configure(buttons: [ .year: annualSubscriptionButton, .month: monthlySubscriptionButton], discountLabels:[ .year: annualDiscountLabel]) - self.preferredContentSize = CGSize(width: 414, height: contentView.frame.height) + preferredContentSize = CGSize(width: 414, height: contentView.frame.height) } @IBAction func onAnnualButtonTap(_ sender: UIButton) { @@ -95,9 +94,9 @@ extension AllPassSubscriptionViewController { private func startAnimating() { if animatingTask != nil { - animatingTask?.cancel(); + animatingTask?.cancel() } - animatingTask = DispatchWorkItem.init {[weak self, animationDelay] in + animatingTask = DispatchWorkItem.init { [weak self, animationDelay] in self?.scrollToWithAnimation(page: (self?.currentPage ?? 0) + 1, completion: { self?.perform(withDelay: animationDelay, execute: self?.animatingTask) }) @@ -106,12 +105,12 @@ extension AllPassSubscriptionViewController { } private func stopAnimating() { - animatingTask?.cancel(); + animatingTask?.cancel() animatingTask = nil view.layer.removeAllAnimations() } - private func scrollToWithAnimation(page: Int, completion: @escaping ()->()) { + private func scrollToWithAnimation(page: Int, completion: @escaping () -> Void) { var nextPage = page var duration = animationDuration if nextPage < 1 || nextPage > maxPages { @@ -125,7 +124,7 @@ extension AllPassSubscriptionViewController { options: [.curveEaseInOut, .allowUserInteraction], animations: { [weak self] in self?.descriptionPageScrollView.contentOffset.x = xOffset - }, completion:{ complete in + }, completion: { complete in completion() }) } @@ -134,13 +133,12 @@ extension AllPassSubscriptionViewController { extension AllPassSubscriptionViewController: UIScrollViewDelegate { func scrollViewDidScroll(_ scrollView: UIScrollView) { if scrollView == descriptionPageScrollView { - let pageProgress = scrollView.contentOffset.x/self.pageWidth + let pageProgress = scrollView.contentOffset.x / pageWidth backgroundImageView.currentPage = pageProgress } else { - let statusBarAlpha = min(scrollView.contentOffset.y/self.statusBarBackVisibleThreshold, 1) + let statusBarAlpha = min(scrollView.contentOffset.y / statusBarBackVisibleThreshold, 1) statusBarBackgroundView.alpha = statusBarAlpha } - } func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { @@ -151,4 +149,3 @@ extension AllPassSubscriptionViewController: UIScrollViewDelegate { startAnimating() } } - diff --git a/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift b/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift index dba1341a06..e82eb8d9b8 100644 --- a/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift @@ -14,13 +14,9 @@ class BaseSubscriptionViewController: MWMViewController { @objc var source: String = kStatWebView private let transitioning = FadeTransitioning() - override var supportedInterfaceOrientations: UIInterfaceOrientationMask { - get { return [.portrait] } - } + override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return [.portrait] } - override var preferredStatusBarStyle: UIStatusBarStyle { - get { return .lightContent } - } + override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) @@ -47,7 +43,7 @@ class BaseSubscriptionViewController: MWMViewController { func configure(buttons: [SubscriptionPeriod: BookmarksSubscriptionButton], discountLabels: [SubscriptionPeriod: InsetsLabel]) { - subscriptionManager?.getAvailableSubscriptions { [weak self] (subscriptions, error) in + subscriptionManager?.getAvailableSubscriptions { [weak self] subscriptions, error in self?.loadingView.isHidden = true guard let subscriptions = subscriptions, subscriptions.count >= buttons.count else { MWMAlertViewController.activeAlert().presentInfoAlert(L("price_error_title"), @@ -65,7 +61,7 @@ class BaseSubscriptionViewController: MWMViewController { enabled: true) if subscriptionItem.hasDiscount, let discountLabel = discountLabels[period] { - discountLabel.isHidden = false; + discountLabel.isHidden = false discountLabel.text = L("all_pass_screen_best_value") } } @@ -80,7 +76,7 @@ class BaseSubscriptionViewController: MWMViewController { func purchase(sender: UIButton, period: SubscriptionPeriod) { subscriptionManager?.addListener(self) - guard let subscription = subscriptionGroup?[period]?.subscription else{ + guard let subscription = subscriptionGroup?[period]?.subscription else { return } signup(anchor: sender, source: .subscription) { [weak self] success in @@ -108,7 +104,7 @@ class BaseSubscriptionViewController: MWMViewController { @IBAction func onRestore(_ sender: UIButton) { subscriptionManager?.addListener(self) Statistics.logEvent(kStatInappRestore, withParameters: [kStatPurchase: subscriptionManager?.serverId ?? ""]) - signup(anchor: sender, source: .subscription) { [weak self] (success) in + signup(anchor: sender, source: .subscription) { [weak self] success in guard success else { return } self?.loadingView.isHidden = false self?.subscriptionManager?.restore { result in @@ -135,13 +131,13 @@ class BaseSubscriptionViewController: MWMViewController { @IBAction func onTerms(_ sender: UIButton) { guard let url = URL(string: User.termsOfUseLink()) else { return } let safari = SFSafariViewController(url: url) - self.present(safari, animated: true, completion: nil) + present(safari, animated: true, completion: nil) } @IBAction func onPrivacy(_ sender: UIButton) { guard let url = URL(string: User.privacyPolicyLink()) else { return } let safari = SFSafariViewController(url: url) - self.present(safari, animated: true, completion: nil) + present(safari, animated: true, completion: nil) } } @@ -160,7 +156,7 @@ extension BaseSubscriptionViewController: SubscriptionManagerListener { func didValidate(_ isValid: Bool) { loadingView.isHidden = true - if (isValid) { + if isValid { onSubscribe?() } else { MWMAlertViewController.activeAlert().presentInfoAlert(L("bookmarks_convert_error_title"), @@ -183,5 +179,3 @@ extension BaseSubscriptionViewController: SubscriptionManagerListener { } } - - diff --git a/iphone/Maps/Core/InappPurchase/Impl/PaidRouteStatistics.swift b/iphone/Maps/Core/InappPurchase/Impl/PaidRouteStatistics.swift index 0315568590..0779b8dcb6 100644 --- a/iphone/Maps/Core/InappPurchase/Impl/PaidRouteStatistics.swift +++ b/iphone/Maps/Core/InappPurchase/Impl/PaidRouteStatistics.swift @@ -51,7 +51,7 @@ class PaidRouteStatistics: IPaidRouteStatistics { logEvent(kStatInappValidationSuccess, withParameters: [kStatPurchase: serverId, kStatErrorCode: code]) } - + private func logEvent(_ eventName: String, withParameters: [String: Any], withChannel: StatisticsChannel = .default) { Statistics.logEvent(eventName, withParameters: withParameters, with: withChannel) diff --git a/iphone/Maps/Core/InappPurchase/InAppPurchase.swift b/iphone/Maps/Core/InappPurchase/InAppPurchase.swift index 2950c7efe3..9ecc0ec2d9 100644 --- a/iphone/Maps/Core/InappPurchase/InAppPurchase.swift +++ b/iphone/Maps/Core/InappPurchase/InAppPurchase.swift @@ -34,20 +34,20 @@ final class InAppPurchase: NSObject { } @objc static var adsRemovalSubscriptionManager: ISubscriptionManager = { - return SubscriptionManager(productIds: MWMPurchaseManager.productIds(), - serverId: MWMPurchaseManager.adsRemovalServerId(), - vendorId: MWMPurchaseManager.adsRemovalVendorId()) - } () + SubscriptionManager(productIds: MWMPurchaseManager.productIds(), + serverId: MWMPurchaseManager.adsRemovalServerId(), + vendorId: MWMPurchaseManager.adsRemovalVendorId()) + }() @objc static var bookmarksSubscriptionManager: ISubscriptionManager = { - return SubscriptionManager(productIds: MWMPurchaseManager.bookmakrsProductIds(), - serverId: MWMPurchaseManager.bookmarksSubscriptionServerId(), - vendorId: MWMPurchaseManager.bookmarksSubscriptionVendorId()) - } () + SubscriptionManager(productIds: MWMPurchaseManager.bookmakrsProductIds(), + serverId: MWMPurchaseManager.bookmarksSubscriptionServerId(), + vendorId: MWMPurchaseManager.bookmarksSubscriptionVendorId()) + }() @objc static var allPassSubscriptionManager: ISubscriptionManager = { - return SubscriptionManager(productIds: MWMPurchaseManager.allPassProductIds(), - serverId: MWMPurchaseManager.allPassSubscriptionServerId(), - vendorId: MWMPurchaseManager.allPassSubscriptionVendorId()) - } () + SubscriptionManager(productIds: MWMPurchaseManager.allPassProductIds(), + serverId: MWMPurchaseManager.allPassSubscriptionServerId(), + vendorId: MWMPurchaseManager.allPassSubscriptionVendorId()) + }() }