diff --git a/iphone/Maps/UI/Welcome/FirstLaunchController.swift b/iphone/Maps/UI/Welcome/FirstLaunchController.swift index 062846e494..301b5e6a38 100644 --- a/iphone/Maps/UI/Welcome/FirstLaunchController.swift +++ b/iphone/Maps/UI/Welcome/FirstLaunchController.swift @@ -1,40 +1,41 @@ -fileprivate struct FirstLaunchConfig: WelcomeConfig { - let image: UIImage - let title: String - let text: String - let buttonTitle: String - let requestLocationPermission: Bool - let requestNotificationsPermission: Bool -} - final class FirstLaunchController: WelcomeViewController { + private enum Permission { + case location + case notifications + case nothing + } + + private struct FirstLaunchConfig: WelcomeConfig { + let image: UIImage + let title: String + let text: String + let buttonTitle: String + let requestPermission: Permission + } + static var welcomeConfigs: [WelcomeConfig] { return [ FirstLaunchConfig(image: #imageLiteral(resourceName: "img_onboarding_offline_maps"), title: "onboarding_offline_maps_title", text: "onboarding_offline_maps_message", buttonTitle: "whats_new_next_button", - requestLocationPermission: false, - requestNotificationsPermission: false), + requestPermission: .nothing), FirstLaunchConfig(image: #imageLiteral(resourceName: "img_onboarding_geoposition"), title: "onboarding_location_title", text: "onboarding_location_message", buttonTitle: "whats_new_next_button", - requestLocationPermission: false, - requestNotificationsPermission: false), + requestPermission: .nothing), FirstLaunchConfig(image: #imageLiteral(resourceName: "img_onboarding_notification"), title: "onboarding_notifications_title", text: "onboarding_notifications_message", buttonTitle: "whats_new_next_button", - requestLocationPermission: true, - requestNotificationsPermission: false), + requestPermission: .location), FirstLaunchConfig(image: #imageLiteral(resourceName: "img_onboarding_done"), title: "first_launch_congrats_title", text: "first_launch_congrats_text", buttonTitle: "done", - requestLocationPermission: false, - requestNotificationsPermission: true) + requestPermission: .notifications) ] } @@ -53,13 +54,14 @@ final class FirstLaunchController: WelcomeViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - if let config = pageConfig as? FirstLaunchConfig { - if config.requestLocationPermission { - MWMLocationManager.start() - } - if config.requestNotificationsPermission { - MWMPushNotifications.setup(nil) - } + let config = pageConfig as! FirstLaunchConfig + switch config.requestPermission { + case .location: + MWMLocationManager.start() + case .notifications: + MWMPushNotifications.setup(nil) + case .nothing: + break } } diff --git a/iphone/Maps/UI/Welcome/WelcomePageController.swift b/iphone/Maps/UI/Welcome/WelcomePageController.swift index cedd21c08b..88f79363e0 100644 --- a/iphone/Maps/UI/Welcome/WelcomePageController.swift +++ b/iphone/Maps/UI/Welcome/WelcomePageController.swift @@ -11,7 +11,7 @@ protocol WelcomePageControllerProtocol { @objc(MWMWelcomePageController) final class WelcomePageController: UIPageViewController { - + fileprivate var controllers: [UIViewController] = [] private var parentController: WelcomePageControllerProtocol! private var iPadBackgroundView: SolidTouchView? @@ -133,10 +133,6 @@ extension WelcomePageController: UIPageViewControllerDataSource { } extension WelcomePageController: WelcomeViewControllerDelegate { - func viewSize() -> CGSize { - return view.size - } - func welcomeViewControllerDidPressNext(_ viewContoller: WelcomeViewController) { guard let index = controllers.index(of: viewContoller) else { close() diff --git a/iphone/Maps/UI/Welcome/WelcomeViewController.swift b/iphone/Maps/UI/Welcome/WelcomeViewController.swift index 37c1b6c64b..1d75762407 100644 --- a/iphone/Maps/UI/Welcome/WelcomeViewController.swift +++ b/iphone/Maps/UI/Welcome/WelcomeViewController.swift @@ -8,7 +8,6 @@ protocol WelcomeConfig { protocol WelcomeViewControllerDelegate: class { func welcomeViewControllerDidPressNext(_ viewContoller: WelcomeViewController) func welcomeViewControllerDidPressClose(_ viewContoller: WelcomeViewController) - func viewSize() -> CGSize } class WelcomeViewController: MWMViewController { diff --git a/iphone/Maps/UI/Welcome/WhatsNewController.swift b/iphone/Maps/UI/Welcome/WhatsNewController.swift index d13399d4fe..db7a8a9683 100644 --- a/iphone/Maps/UI/Welcome/WhatsNewController.swift +++ b/iphone/Maps/UI/Welcome/WhatsNewController.swift @@ -1,14 +1,15 @@ -fileprivate struct WhatsNewConfig: WelcomeConfig { - let image: UIImage - let title: String - let text: String - let buttonTitle: String - let ctaButtonTitle: String - let ctaButtonUrl: String -} - final class WhatsNewController: WelcomeViewController { + private struct WhatsNewConfig: WelcomeConfig { + let image: UIImage + let title: String + let text: String + let buttonTitle: String + let ctaButtonTitle: String? + let ctaButtonUrl: String? + } + + static let ctaUrl = "https://b2b.maps.me/whatsnew/us" static var welcomeConfigs: [WelcomeConfig] { return [ WhatsNewConfig(image: #imageLiteral(resourceName: "img_wn_business"), @@ -16,7 +17,7 @@ final class WhatsNewController: WelcomeViewController { text: "whats_new_localbiz_message", buttonTitle: "done", ctaButtonTitle: "whats_new_order_button", - ctaButtonUrl: "https://b2b.maps.me/whatsnew/us") + ctaButtonUrl: ctaUrl) ] } @@ -38,13 +39,19 @@ final class WhatsNewController: WelcomeViewController { override func viewDidLoad() { super.viewDidLoad() let config = pageConfig as! WhatsNewConfig - ctaButton.setTitle(L(config.ctaButtonTitle), for: .normal) + if let ctaTitleKey = config.ctaButtonTitle { + ctaButton.setTitle(L(ctaTitleKey), for: .normal) + } else { + ctaButton.isHidden = true + } } @IBAction func onCta() { let config = pageConfig as! WhatsNewConfig - if let url = URL(string: config.ctaButtonUrl) { + if let url = URL(string: config.ctaButtonUrl!) { UIApplication.shared.openURL(url) + } else { + assertionFailure() } close() }