Merge pull request #5400 from igrechuhin/whatsnew

[ios] Changed what’s new controller key getter.
This commit is contained in:
Vlad Mihaylenko 2017-02-13 13:47:23 +03:00 committed by GitHub
commit 12bbe3b60d
3 changed files with 62 additions and 61 deletions

View file

@ -2,34 +2,28 @@ import UIKit
final class FirstLaunchController: MWMViewController, WelcomeProtocol {
typealias ConfigBlock = (FirstLaunchController) -> Void
static var pagesConfigBlocks: [ConfigBlock]! = [{
$0.setup(image: #imageLiteral(resourceName: "img_onboarding_offline_maps"),
title: L("onboarding_offline_maps_title"),
text: L("onboarding_offline_maps_message"),
buttonTitle: L("whats_new_next_button"),
buttonAction: #selector(nextPage))
}, {
$0.setup(image: #imageLiteral(resourceName: "img_onboarding_geoposition"),
title: L("onboarding_location_title"),
text: L("onboarding_location_message"),
buttonTitle: L("whats_new_next_button"),
buttonAction: #selector(nextPage))
}, {
$0.setup(image: #imageLiteral(resourceName: "img_onboarding_notification"),
title: L("onboarding_notifications_title"),
text: L("onboarding_notifications_message"),
buttonTitle: L("whats_new_next_button"),
buttonAction: #selector(nextPage))
}, {
$0.setup(image: #imageLiteral(resourceName: "img_onboarding_done"),
title: L("first_launch_congrats_title"),
text: L("first_launch_congrats_text"),
buttonTitle: L("done"),
buttonAction: #selector(close))
}]
static var key: String { return "\(self)" }
static var welcomeConfigs: [WelcomeConfig] = [
WelcomeConfig(image: #imageLiteral(resourceName: "img_onboarding_offline_maps"),
title: "onboarding_offline_maps_title",
text: "onboarding_offline_maps_message",
buttonTitle: "whats_new_next_button",
buttonAction: #selector(nextPage)),
WelcomeConfig(image: #imageLiteral(resourceName: "img_onboarding_geoposition"),
title: "onboarding_location_title",
text: "onboarding_location_message",
buttonTitle: "whats_new_next_button",
buttonAction: #selector(nextPage)),
WelcomeConfig(image: #imageLiteral(resourceName: "img_onboarding_notification"),
title: "onboarding_notifications_title",
text: "onboarding_notifications_message",
buttonTitle: "whats_new_next_button",
buttonAction: #selector(nextPage)),
WelcomeConfig(image: #imageLiteral(resourceName: "img_onboarding_done"),
title: "first_launch_congrats_title",
text: "first_launch_congrats_text",
buttonTitle: "done",
buttonAction: #selector(close))
]
var pageIndex: Int!
weak var pageController: WelcomePageController!

View file

@ -1,5 +1,4 @@
protocol WelcomeProtocolBase: class {
static var key: String { get }
var pageIndex: Int! { get set }
@ -21,9 +20,6 @@ protocol WelcomeProtocolBase: class {
}
extension WelcomeProtocolBase {
static var key: String { return "\(self)" + AppInfo.shared().bundleVersion! }
static func controller(_ pageIndex: Int) -> UIViewController {
let sb = UIStoryboard.instance(.welcome)
let vc = sb.instantiateViewController(withIdentifier: toString(self))
@ -50,20 +46,35 @@ extension WelcomeProtocolBase {
}
}
struct WelcomeConfig {
let image: UIImage
let title: String
let text: String
let buttonTitle: String
let buttonAction: Selector
}
protocol WelcomeProtocol: WelcomeProtocolBase {
typealias ConfigBlock = (Self) -> Void
static var pagesConfigBlocks: [ConfigBlock]! { get }
static var welcomeConfigs: [WelcomeConfig] { get }
static func configBlock(pageIndex: Int) -> ConfigBlock
func config()
}
extension WelcomeProtocol {
static var key: String { return welcomeConfigs.reduce("\(self)@") { "\($0)\($1.title):" } }
static var pagesConfigBlocks: [ConfigBlock]! { return nil }
static func configBlock(pageIndex: Int) -> ConfigBlock {
let welcomeConfig = welcomeConfigs[pageIndex]
return {
$0.setup(image:welcomeConfig.image,
title:L(welcomeConfig.title),
text:L(welcomeConfig.text),
buttonTitle:L(welcomeConfig.buttonTitle),
buttonAction:welcomeConfig.buttonAction)
}
}
static var pagesCount: Int { return welcomeConfigs.count }
static var pagesCount: Int { return pagesConfigBlocks.count }
func config() { type(of: self).pagesConfigBlocks[pageIndex](self) }
func config() { type(of: self).configBlock(pageIndex: pageIndex)(self) }
}

View file

@ -2,27 +2,23 @@ import UIKit
final class WhatsNewController: MWMViewController, WelcomeProtocol {
static var key: String { return "\(self)@" + "improved_search&filters_in_search&font_size" }
typealias ConfigBlock = (WhatsNewController) -> Void
static var pagesConfigBlocks: [ConfigBlock]! = [{
$0.setup(image: #imageLiteral(resourceName: "wn_img_1"),
title: L("whatsnew_improved_search"),
text: L("whatsnew_improved_search_text"),
buttonTitle: L("whats_new_next_button"),
buttonAction: #selector(nextPage))
}, {
$0.setup(image: #imageLiteral(resourceName: "wn_img_2"),
title: L("whatsnew_filters_in_search"),
text: L("whatsnew_filters_in_search_text"),
buttonTitle: L("whats_new_next_button"),
buttonAction: #selector(nextPage))
}, {
$0.setup(image: #imageLiteral(resourceName: "wn_img_3"),
title: L("whatsnew_font_size"),
text: L("whatsnew_font_size_text"),
buttonTitle: L("done"),
buttonAction: #selector(close))
}]
static var welcomeConfigs: [WelcomeConfig] = [
WelcomeConfig(image: #imageLiteral(resourceName: "wn_img_1"),
title: "whatsnew_improved_search",
text: "whatsnew_improved_search_text",
buttonTitle: "whats_new_next_button",
buttonAction: #selector(nextPage)),
WelcomeConfig(image: #imageLiteral(resourceName: "wn_img_2"),
title: "whatsnew_filters_in_search",
text: "whatsnew_filters_in_search_text",
buttonTitle: "whats_new_next_button",
buttonAction: #selector(nextPage)),
WelcomeConfig(image: #imageLiteral(resourceName: "wn_img_3"),
title: "whatsnew_font_size",
text: "whatsnew_font_size_text",
buttonTitle: "done",
buttonAction: #selector(close))
]
var pageIndex: Int!
weak var pageController: WelcomePageController!