You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

240 lines
11 KiB

//
// Navigator.swift
// FireBoltt
//
// Created by lemo. on 2020/3/7.
// Copyright © 2020 Sheldon. All rights reserved.
//
import Foundation
import UIKit
import RxSwift
import RxCocoa
protocol Navigatable {
var navigator: Navigator! { get set }
}
class Navigator {
static var `default` = Navigator()
// MARK: - segues list, all app scenes
enum Scene {
case tabs(viewModel: HomeTabBarViewModel)
case guideUserInfo
case binding(viewModel: BindingViewModels)
case notice(viewModel: NoticeViewModels)
case heartRateCheck(viewModel: HeartRateCheckViewModels)
case notDisturb(viewModel: NotDisturbViewModels)
case drinkRemind(viewModel: DrinkRemindViewModels)
case repeatSet(viewModel: RepeatViewModels)
case sedentary(viewModel: SedentaryViewModels)
case alarmList(viewModel: NewAlarmListViewModel)
case addAlarm(viewModel: NewAddAlarmViewModel)
case about
case target(viewModel: TargetVM)
case unitSet
case userInfo(viewModel: UserInfoViewModel)
case step(viewModel: StepViewModels)
case sleep(viewModel: SleepViewModels)
case heartRate(viewModel: HRViewModels)
case sportDetail(viewModel: SportDetailViewModels)
case firmwareUpdate(viewModel: FirmwareUpdateViewModels)
case dialPush(viewModel: DialPushViewModels)
case temperatureCheck(viewModel: TemperarureCheckViewModels)
case temperature(viewModel: TemperatureViewModels)
case wechatSport(viewModel: WeChatSportViewModelss)
case bloodPressure(viewModel: BloodPressureViewModels)
case bloodOxygen(viewModel: BloodOxygenViewModels)
case telephonebook(ViewModel: TelephoneBookViewModels)
case businesscard(ViewModel: businessCardViewModels)
case theWallet(ViewModel: PaymentCodeViewModels)
case upDataQRCodeImg(ViewModel:UpdataQRCodeImgViewModels)
}
enum Transition {
case root(in: UIWindow)
case navigation
case modal
}
// MARK: - get a single VC
func get(segue: Scene) -> UIViewController? {
switch segue {
case .tabs(let viewModel):
let rootVC = HomeTabBarController(viewModel: viewModel, navigator: self)
return rootVC
case .guideUserInfo:
let guideVC = GuideUserInfoViewController(viewModel: nil, navigator: self)
guideVC.modalPresentationStyle = .fullScreen
return guideVC
case .binding(let viewModel):
let bindingVC = BindingViewControllers(viewModel: viewModel, navigator: self)
bindingVC.navigationTitle = MultiLanguageKey_FB.bindingFB.localized
return bindingVC
case .notice(let viewModel):
let noticeVC = NoticeViewConrtollers(viewModel: viewModel, navigator: self)
noticeVC.navigationTitle = MultiLanguageKey_FB.noticeFB.localized
return noticeVC
case .heartRateCheck(let viewModel):
let heartRateCheckVC = HeartRateMonitorViewControllers(viewModel: viewModel, navigator: self)
heartRateCheckVC.navigationTitle = MultiLanguageKey_FB.heartCheckFB.localized
return heartRateCheckVC
case .notDisturb(let viewModel):
let notDisturbVC = NotDisturbViewControllers(viewModel: viewModel, navigator: self)
notDisturbVC.navigationTitle = MultiLanguageKey_FB.notDisturbFB.localized
return notDisturbVC
case .drinkRemind(let viewModel):
let drinkRemindVC = DrinkRemindViewControllers(viewModel: viewModel, navigator: self)
drinkRemindVC.navigationTitle = MultiLanguageKey_FB.drinkRemindFB.localized
return drinkRemindVC
case .repeatSet(let viewModel):
let repeatTimeVC = RepeatTimeViewControllers(viewModel: viewModel, navigator: self)
repeatTimeVC.navigationTitle = MultiLanguageKey_FB.repeatCycleFB.localized
return repeatTimeVC
case .sedentary(let viewModel):
let sedentaryVC = SedentaryViewControllers(viewModel: viewModel, navigator: self)
sedentaryVC.navigationTitle = MultiLanguageKey_FB.sedentaryFB.localized
return sedentaryVC
case .alarmList(let viewModel):
let newAlarmVC = NewAlarmViewController(viewModel: viewModel, navigator: self)
newAlarmVC.navigationTitle = MultiLanguageKey_FB.alarmClockFB.localized
return newAlarmVC
case .addAlarm(let viewModel):
let newAddAlarmVC = NewAddAlarmVC(viewModel: viewModel, navigator: self)
newAddAlarmVC.navigationTitle = viewModel.isAdd ? MultiLanguageKey_FB.addAlarmFB.localized : MultiLanguageKey_FB.editAlarmFB.localized
return newAddAlarmVC
case .about:
let vc = AboutVC(viewModel: nil, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.aboutFB.localized
return vc
case .target(let viewModel):
let vc = TargetVC(viewModel: viewModel, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.targetSetFB.localized
return vc
case .unitSet:
let vc = UnitSetVC(viewModel: nil, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.unitSetFB.localized
return vc
case .userInfo(let viewModel):
let vc = UserInfoViewController(viewModel: viewModel, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.mineInfoFB.localized
return vc
case .step(let viewModel):
let vc = StepViewControllers(viewModel: viewModel, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.stepFB.localized
return vc
case .sleep(let viewModel):
let vc = SleepViewControllers(viewModel: viewModel, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.sleepFB.localized
return vc
case .heartRate(let viewModel):
let vc = HRViewControllers(viewModel: viewModel, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.heartRateFB.localized
return vc
case .sportDetail(let viewModel):
let vc = SportDetailViewControllers(viewModel: viewModel, navigator: self)
return vc
case .firmwareUpdate(let viewModel):
let vc = FirmwareUpdateViewControllers(viewModel: viewModel, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.firmwareUpgradeFB.localized
return vc
case .dialPush(let viewModel):
let vc = DialPushViewControllers(viewModel: viewModel, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.dialPushFB.localized
return vc
case .temperatureCheck(let viewModel):
let vc = TemperarureCheckViewControllers(viewModel: viewModel, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.temperatureCheckFB.localized
return vc
case .temperature(let viewModel):
let vc = TemperatureViewControllers(viewModel: viewModel, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.temperatureFB.localized
return vc
case .wechatSport(let viewModel):
let vc = WeChatSportViewControllerss(viewModel: viewModel, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.wechatSportFB.localized
return vc
case .bloodPressure(let viewModel):
let vc = BloodPressureViewControllers(viewModel: viewModel, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.bloodPressureFB.localized
return vc
case .bloodOxygen(let viewModel):
let vc = BloodOxygenViewControllers(viewModel: viewModel, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.bloodOxygenFB.localized
return vc
case .telephonebook(let viewModel):
let vc = TelephoneBookViewControllers(viewModel: viewModel, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.telephoneBookFB.localized
return vc
case .theWallet(let viewModel):
let vc = PaymentCodeViewControllers(viewModel: viewModel, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.theWalletFB.localized
return vc
case .businesscard(let viewModel):
let vc = businessCardViewControllers(viewModel: viewModel, navigator: self)
vc.navigationTitle = MultiLanguageKey_FB.businessCardFB.localized
return vc
case .upDataQRCodeImg(let viewModel):
let vc = UpdataQRCodeImgViewControllers(viewModel: viewModel, navigator: self)
vc.navigationTitle = viewModel.titleName
return vc
}
}
func pop(sender: UIViewController?, toRoot: Bool = false) {
if toRoot {
sender?.navigationController?.popToRootViewController(animated: true)
} else {
sender?.navigationController?.popViewController(animated: true)
}
}
func dismiss(sender: UIViewController?) {
sender?.navigationController?.dismiss(animated: true, completion: nil)
}
// MARK: - invoke a single segue
func show(segue: Scene, sender: UIViewController?, transition: Transition = .navigation) {
if let target = get(segue: segue) {
show(target: target, sender: sender, transition: transition)
}
}
private func show(target: UIViewController, sender: UIViewController?, transition: Transition) {
switch transition {
case .root(in: let window):
window.rootViewController = target
window.makeKeyAndVisible()
return
default: break
}
guard let sender = sender else {
fatalError("You need to pass in a sender for .navigation or .modal transitions")
}
if let nav = sender as? UINavigationController {
//push root controller on navigation stack
nav.pushViewController(target, animated: false)
return
}
switch transition {
case .navigation:
if let nav = sender.navigationController {
// push controller to navigation stack
nav.pushViewController(target, animated: true)
}
case .modal:
// present modally
DispatchQueue.main.async {
let nav = NavigationController(rootViewController: target)
nav.modalPresentationStyle = target.modalPresentationStyle
sender.present(nav, animated: true, completion: nil)
}
default: break
}
}
}