PodReplacementNavigationController.swift 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // PodReplacementNavigationController.swift
  3. // OmniKitUI
  4. //
  5. // Created by Pete Schwamb on 11/28/18.
  6. // Copyright © 2018 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. import OmniKit
  10. import LoopKitUI
  11. class PodReplacementNavigationController: UINavigationController, UINavigationControllerDelegate, CompletionNotifying {
  12. weak var completionDelegate: CompletionDelegate?
  13. class func instantiatePodReplacementFlow(_ pumpManager: OmnipodPumpManager) -> PodReplacementNavigationController {
  14. let vc = UIStoryboard(name: "OmnipodPumpManager", bundle: Bundle(for: PodReplacementNavigationController.self)).instantiateViewController(withIdentifier: "PodReplacementFlow") as! PodReplacementNavigationController
  15. vc.pumpManager = pumpManager
  16. return vc
  17. }
  18. class func instantiateNewPodFlow(_ pumpManager: OmnipodPumpManager) -> PodReplacementNavigationController {
  19. let vc = UIStoryboard(name: "OmnipodPumpManager", bundle: Bundle(for: PodReplacementNavigationController.self)).instantiateViewController(withIdentifier: "NewPodFlow") as! PodReplacementNavigationController
  20. vc.pumpManager = pumpManager
  21. return vc
  22. }
  23. class func instantiateInsertCannulaFlow(_ pumpManager: OmnipodPumpManager) -> PodReplacementNavigationController {
  24. let vc = UIStoryboard(name: "OmnipodPumpManager", bundle: Bundle(for: PodReplacementNavigationController.self)).instantiateViewController(withIdentifier: "InsertCannulaFlow") as! PodReplacementNavigationController
  25. vc.pumpManager = pumpManager
  26. return vc
  27. }
  28. private(set) var pumpManager: OmnipodPumpManager!
  29. override func viewDidLoad() {
  30. super.viewDidLoad()
  31. if #available(iOSApplicationExtension 13.0, *) {
  32. // Prevent interactive dismissal
  33. isModalInPresentation = true
  34. }
  35. delegate = self
  36. }
  37. func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
  38. if let setupViewController = viewController as? SetupTableViewController {
  39. setupViewController.delegate = self
  40. }
  41. switch viewController {
  42. case let vc as ReplacePodViewController:
  43. vc.pumpManager = pumpManager
  44. case let vc as PairPodSetupViewController:
  45. vc.pumpManager = pumpManager
  46. case let vc as InsertCannulaSetupViewController:
  47. vc.pumpManager = pumpManager
  48. case let vc as PodSetupCompleteViewController:
  49. vc.pumpManager = pumpManager
  50. default:
  51. break
  52. }
  53. }
  54. func completeSetup() {
  55. completionDelegate?.completionNotifyingDidComplete(self)
  56. }
  57. }
  58. extension PodReplacementNavigationController: SetupTableViewControllerDelegate {
  59. func setupTableViewControllerCancelButtonPressed(_ viewController: SetupTableViewController) {
  60. completionDelegate?.completionNotifyingDidComplete(self)
  61. }
  62. }