Created
May 29, 2017 13:45
-
-
Save abdulowork/fd290fdf2a5e5e4a23c4384781af2543 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class MoreItems: BasicCollection<Item> { | |
init(for viewController: UIViewController) { | |
let items: [Item] = [ | |
BasicItem( | |
image: #imageLiteral(resourceName: "ImageProfilePlaceholder"), | |
title: "Профиль", | |
description: "", | |
command: CommandToPerform{ [weak viewController] in | |
viewController?.navigationController?.pushViewController(Storyboard.More.profileViewController(), animated: true) | |
}), | |
{ | |
let title = "О нас" | |
return BasicItem( | |
image: #imageLiteral(resourceName: "ImageMoreHand"), | |
title: title, | |
description: "", | |
command: CommandToPerform{ [weak viewController] in | |
let aboutViewController = Storyboard.Onboarding.demoAboutViewController() | |
aboutViewController.outsideDemoMode = true | |
aboutViewController.items = Array(MainScreenItems(for: aboutViewController)) | |
aboutViewController.title = title | |
viewController?.navigationController?.pushViewController(aboutViewController, animated: true) | |
}) | |
}(), | |
BasicItem( | |
image: #imageLiteral(resourceName: "ImageDemo2"), | |
title: "Тарифы", | |
description: "", | |
command: CommandToPerform{ [weak viewController] in | |
let navigationController = TelemedNavigationViewController() | |
navigationController.viewControllers = [Storyboard.More.plansViewController()] | |
viewController?.present(navigationController, animated: true, completion: nil) | |
}), | |
BasicItem( | |
image: #imageLiteral(resourceName: "ImageDemoFamily1"), | |
title: "Способы оплаты", | |
description: "", | |
command: CommandToPerform{ [weak viewController] in | |
viewController?.navigationController?.pushViewController(Storyboard.More.paymentMethodsViewController(), animated: true) | |
}), | |
BasicItem( | |
image: #imageLiteral(resourceName: "ImageMoreContact"), | |
title: "Связаться с нами", | |
description: "", | |
command: CommandToPerform{ [weak viewController] in | |
viewController?.navigationController?.pushViewController(SharedStoryboard.Shared.ContactUsViewController(), animated: true) | |
}), | |
BasicItem( | |
image: #imageLiteral(resourceName: "ImageDemo3"), | |
title: "Часто задаваемые вопросы", | |
description: "", | |
command: CommandToPerform{ [weak viewController] in | |
viewController?.navigationController?.pushViewController(SharedStoryboard.Shared.FAQViewController(), animated: true) | |
}) | |
] | |
super.init(origin: items) | |
} | |
} | |
final class MainScreenItems: BasicCollection<Item> { | |
init(for viewController: UIViewController) { | |
let items: [Item] = [ | |
{ | |
let title = "Медицинская карта" | |
return BasicItem( | |
image: #imageLiteral(resourceName: "ImageDemo2"), | |
title: "Медицинская карта", | |
description: "Данные о здоровье вашей семьи в одном месте", | |
command: CommandToPerform{ [weak viewController] in | |
let demoVC = Storyboard.Onboarding.demoAboutViewController() | |
demoVC.items = Array(MedicalInfoItems(for: demoVC)) | |
demoVC.title = title | |
viewController?.navigationController?.pushViewController(demoVC, animated: true) | |
}) | |
}() | |
] | |
super.init(origin: items) | |
} | |
} | |
final class DemoItems: BasicCollection<Item> { | |
init(for viewController: UIViewController) { | |
super.init(origin: | |
[BasicItem( | |
image: #imageLiteral(resourceName: "ImageDemo1"), | |
title: "Врачи", | |
description: "Видеоконсультации для вас и для вашей семьи", | |
command: CommandToPerform{ [weak viewController] in | |
viewController?.navigationController?.pushViewController(Storyboard.Doctors.specializationsViewController(), animated: true) | |
}), | |
BasicItem( | |
image: #imageLiteral(resourceName: "ImageDemo3"), | |
title: "Часто задаваемые вопросы", | |
description: "", | |
command: CommandToPerform{ [weak viewController] in | |
viewController?.navigationController?.pushViewController(SharedStoryboard.Shared.FAQViewController(), animated: true) | |
})] + MainScreenItems(for: viewController) | |
) | |
} | |
} | |
fileprivate final class MedicalInfoItems: BasicCollection<Item> { | |
typealias LineNumber = Int | |
private struct CommandToOpenMedicalInfo: Command { | |
private let toPerform: CommandToPerform | |
init(with viewController: UIViewController, at line: LineNumber) { | |
toPerform = CommandToPerform { [weak viewController] in | |
let textViewController = Storyboard.Onboarding.textInfoViewController() | |
textViewController.text = AboutTexts.forTheme(.medicalInfo, index: line) | |
viewController?.navigationController?.pushViewController(textViewController, animated: true) | |
} | |
} | |
func execute() { | |
toPerform.execute() | |
} | |
} | |
init(for viewController: UIViewController) { | |
let items: [Item] = [ | |
BasicItem( | |
image: #imageLiteral(resourceName: "ImageDemoMedInfo1"), | |
title: "Получение и загрузка данных", | |
description: "", | |
command: CommandToOpenMedicalInfo(with: viewController, at: 0) | |
), | |
BasicItem( | |
image: #imageLiteral(resourceName: "ImageDemoMedInfo2"), | |
title: "Хранение данных", | |
description: "", | |
command: CommandToOpenMedicalInfo(with: viewController, at: 1) | |
), | |
BasicItem( | |
image: #imageLiteral(resourceName: "ImageDemoMedInfo3"), | |
title: "Передача данных", | |
description: "", | |
command: CommandToOpenMedicalInfo(with: viewController, at: 2) | |
), | |
BasicItem( | |
image: #imageLiteral(resourceName: "ImageDemoMedInfo4"), | |
title: "Конфиденциальность", | |
description: "", | |
command: CommandToOpenMedicalInfo(with: viewController, at: 3) | |
) | |
] | |
super.init(origin: items) | |
} | |
} | |
protocol Command { | |
func execute() | |
} | |
protocol Item { | |
var image: UIImage { get } | |
var title: String { get } | |
var description: String { get } | |
var command: Command { get } | |
} | |
class BasicItem: Item { | |
let image: UIImage | |
let title: String | |
let description: String | |
let command: Command | |
init(image: UIImage, title: String, description: String, command: Command) { | |
self.image = image | |
self.title = title | |
self.description = description | |
self.command = command | |
} | |
} | |
class CommandToPerform: Command { | |
private let action: () -> () | |
init(_ action: @escaping () -> ()) { | |
self.action = action | |
} | |
func execute() { | |
action() | |
} | |
} | |
//TODO: Maybe it's not the best implementation idea. Try creating CollectionOfItems protocol | |
class BasicCollection<T>: RandomAccessCollection { | |
private let origin: Array<T> | |
init<Base: Collection>(origin: Base) where Base.Iterator.Element == AnyCollection<T>.Iterator.Element { | |
self.origin = Array(origin) | |
} | |
var startIndex: Array<T>.Index { | |
return origin.startIndex | |
} | |
var endIndex: Array<T>.Index { | |
return origin.endIndex | |
} | |
func index(after i: Array<T>.Index) -> Array<T>.Index { | |
return origin.index(after: i) | |
} | |
func index(before i: Array<T>.Index) -> Array<T>.Index { | |
return origin.index(before: i) | |
} | |
subscript(i: Array<T>.Index) -> T { | |
get { | |
return origin[i] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment