forked from organicmaps/organicmaps
[ios] Make CTA button on WhatsNew optional, remove dead code, refactoring
This commit is contained in:
parent
830ba9f67a
commit
01d2fa5181
4 changed files with 46 additions and 42 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -8,7 +8,6 @@ protocol WelcomeConfig {
|
|||
protocol WelcomeViewControllerDelegate: class {
|
||||
func welcomeViewControllerDidPressNext(_ viewContoller: WelcomeViewController)
|
||||
func welcomeViewControllerDidPressClose(_ viewContoller: WelcomeViewController)
|
||||
func viewSize() -> CGSize
|
||||
}
|
||||
|
||||
class WelcomeViewController: MWMViewController {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue