MinimedPumpManagerSetupViewController.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // MinimedPumpSetupViewController.swift
  3. // Loop
  4. //
  5. // Copyright © 2018 LoopKit Authors. All rights reserved.
  6. //
  7. import UIKit
  8. import LoopKit
  9. import LoopKitUI
  10. import MinimedKit
  11. import RileyLinkBLEKit
  12. import RileyLinkKit
  13. import RileyLinkKitUI
  14. public class MinimedPumpManagerSetupViewController: RileyLinkManagerSetupViewController {
  15. class func instantiateFromStoryboard() -> MinimedPumpManagerSetupViewController {
  16. return UIStoryboard(name: "MinimedPumpManager", bundle: Bundle(for: MinimedPumpManagerSetupViewController.self)).instantiateInitialViewController() as! MinimedPumpManagerSetupViewController
  17. }
  18. override public func viewDidLoad() {
  19. super.viewDidLoad()
  20. if #available(iOSApplicationExtension 13.0, *) {
  21. view.backgroundColor = .systemBackground
  22. } else {
  23. view.backgroundColor = .white
  24. }
  25. navigationBar.shadowImage = UIImage()
  26. if let pumpIDSetupVC = topViewController as? MinimedPumpIDSetupViewController, let rileyLinkPumpManager = rileyLinkPumpManager {
  27. pumpIDSetupVC.rileyLinkPumpManager = rileyLinkPumpManager
  28. }
  29. }
  30. private(set) var pumpManager: MinimedPumpManager?
  31. internal var insulinType: InsulinType?
  32. internal var supportedInsulinTypes: [InsulinType]?
  33. /*
  34. 1. RileyLink
  35. - RileyLinkPumpManagerState
  36. 2. Pump
  37. - PumpSettings
  38. - PumpColor
  39. -- Submit --
  40. - PumpOps
  41. - PumpState
  42. 3. (Optional) Connect Devices
  43. 4. Time
  44. 5. Basal Rates & Delivery Limits
  45. 6. Pump Setup Complete
  46. */
  47. override public func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
  48. super.navigationController(navigationController, willShow: viewController, animated: animated)
  49. if let setupViewController = viewController as? SetupTableViewController {
  50. setupViewController.delegate = self
  51. }
  52. // Set state values
  53. switch viewController {
  54. case let vc as MinimedPumpIDSetupViewController:
  55. vc.rileyLinkPumpManager = rileyLinkPumpManager
  56. vc.maxBolusUnits = maxBolusUnits
  57. vc.maxBasalRateUnitsPerHour = maxBasalRateUnitsPerHour
  58. vc.basalSchedule = basalSchedule
  59. case let vc as MinimedPumpSentrySetupViewController:
  60. vc.pumpManager = pumpManager
  61. case is MinimedPumpClockSetupViewController:
  62. break
  63. case let vc as MinimedPumpSetupCompleteViewController:
  64. vc.pumpImage = pumpManager?.state.largePumpImage
  65. default:
  66. break
  67. }
  68. // Adjust the appearance for the main setup view controllers only
  69. if viewController is SetupTableViewController {
  70. navigationBar.isTranslucent = false
  71. navigationBar.shadowImage = UIImage()
  72. } else {
  73. navigationBar.isTranslucent = true
  74. navigationBar.shadowImage = nil
  75. viewController.navigationItem.largeTitleDisplayMode = .never
  76. }
  77. }
  78. public func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
  79. // Adjust the appearance for the main setup view controllers only
  80. if viewController is SetupTableViewController {
  81. navigationBar.isTranslucent = false
  82. navigationBar.shadowImage = UIImage()
  83. } else {
  84. navigationBar.isTranslucent = true
  85. navigationBar.shadowImage = nil
  86. }
  87. }
  88. public func pumpManagerSetupComplete(_ pumpManager: MinimedPumpManager) {
  89. self.pumpManager = pumpManager
  90. pumpManagerOnboardingDelegate?.pumpManagerOnboarding(didCreatePumpManager: pumpManager)
  91. }
  92. override open func finishedSetup() {
  93. if let pumpManager = pumpManager {
  94. pumpManager.completeOnboard()
  95. pumpManagerOnboardingDelegate?.pumpManagerOnboarding(didOnboardPumpManager: pumpManager)
  96. let settingsViewController = MinimedPumpSettingsViewController(pumpManager: pumpManager, supportedInsulinTypes: supportedInsulinTypes!)
  97. setViewControllers([settingsViewController], animated: true)
  98. }
  99. }
  100. public func finishedSettingsDisplay() {
  101. completionDelegate?.completionNotifyingDidComplete(self)
  102. }
  103. public func didCancel() {
  104. completionDelegate?.completionNotifyingDidComplete(self)
  105. }
  106. }
  107. extension MinimedPumpManagerSetupViewController: SetupTableViewControllerDelegate {
  108. public func setupTableViewControllerCancelButtonPressed(_ viewController: SetupTableViewController) {
  109. didCancel()
  110. }
  111. }