|
//
// GroupDetailCoordinator.swift
// Paiai_iOS
//
// Created by FFIB on 2018/12/19.
// Copyright © 2018 FFIB. All rights reserved.
//
import UIKit
import RxSwift
import PaiaiDataKit
enum GroupDetailCoordinatorResult {
case quit
case cancel
}
class GroupDetailCoordinator: BaseCoordinator<GroupDetailCoordinatorResult> {
let groupDetailViewController: GroupDetailViewController
let source: NavigationSource.Group
var coordinatorResult = PublishSubject<GroupDetailCoordinatorResult>()
init(_ viewController: GroupDetailViewController,
navigationController: UINavigationController,
navigationSource: NavigationSource.Group) {
self.source = navigationSource
self.groupDetailViewController = viewController
super.init(navigationController: navigationController, viewController: viewController)
}
override func start() -> Observable<GroupDetailCoordinatorResult> {
groupDetailViewController.viewModel.delegate = self
let quit = groupDetailViewController.viewModel.didQuit.map { _ in GroupDetailCoordinatorResult.quit }
let cancel = didCancel.map { _ in GroupDetailCoordinatorResult.cancel }
return Observable.amb([cancel, quit])
}
}
extension GroupDetailCoordinator: GroupDetailViewModelDelegate {
func navigationBackToGroupDetail() {
navigationController.popViewController(animated: true)
}
func navigateToRootViewController() {
coordinatorResult.onNext(.quit)
switch source {
case .createGroup, .scan, .photoDetail, .recentGroup:
navigationController.popToRootViewController(animated: true)
break
case .mineGroup:
let targetVC = navigationController.viewControllers[navigationController.viewControllers.count - 3]
navigationController.popToViewController(targetVC, animated: true)
}
}
func navigateToGroupMember(_ item: GroupDetailItem) {
navigationController.pushViewController(makeGroupMemberViewController(item))
}
func navigateToGroupNameModification(_ item: GroupDetailItem) {
navigationController.pushViewController(makeGroupNameModificationViewController(item))
}
}
extension GroupDetailCoordinator {
func makeGroupMemberViewController(_ item: GroupDetailItem) -> GroupMemberViewController {
let vc = GroupMemberViewController.instantiate()
vc.viewModel = GroupMemberViewModel(item: item)
return vc
}
func makeGroupNameModificationViewController(_ item: GroupDetailItem) -> GroupNameModificationViewController {
let vc = GroupNameModificationViewController.instantiate()
vc.viewModel = groupDetailViewController.viewModel
return vc
}
}
extension UIStoryboard {
static var groupDetail: UIStoryboard {
return UIStoryboard(name: "GroupDetail", bundle: Bundle(identifier: "com.Paiai-iOS"))
}
}
|