MinimedPumpManager+UI.swift 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // MinimedPumpManager+UI.swift
  3. // Loop
  4. //
  5. // Copyright © 2018 LoopKit Authors. All rights reserved.
  6. //
  7. import SwiftUI
  8. import UIKit
  9. import LoopKit
  10. import LoopKitUI
  11. import MinimedKit
  12. import RileyLinkKitUI
  13. extension MinimedPumpManager: PumpManagerUI {
  14. public static var onboardingImage: UIImage? {
  15. return UIImage.pumpImage(in: nil, isLargerModel: false, isSmallImage: true)
  16. }
  17. static public func setupViewController(initialSettings settings: PumpManagerSetupSettings, bluetoothProvider: BluetoothProvider, colorPalette: LoopUIColorPalette, allowDebugFeatures: Bool, allowedInsulinTypes: [InsulinType]) -> SetupUIResult<PumpManagerViewController, PumpManagerUI> {
  18. let navVC = MinimedPumpManagerSetupViewController.instantiateFromStoryboard()
  19. navVC.supportedInsulinTypes = allowedInsulinTypes
  20. let didConfirm: (InsulinType) -> Void = { [weak navVC] (confirmedType) in
  21. if let navVC = navVC {
  22. navVC.insulinType = confirmedType
  23. let nextViewController = navVC.storyboard?.instantiateViewController(identifier: "RileyLinkSetup") as! RileyLinkSetupTableViewController
  24. navVC.pushViewController(nextViewController, animated: true)
  25. }
  26. }
  27. let didCancel: () -> Void = { [weak navVC] in
  28. if let navVC = navVC {
  29. navVC.didCancel()
  30. }
  31. }
  32. let insulinSelectionView = InsulinTypeConfirmation(initialValue: .novolog, supportedInsulinTypes: allowedInsulinTypes, didConfirm: didConfirm, didCancel: didCancel)
  33. let rootVC = UIHostingController(rootView: insulinSelectionView)
  34. rootVC.title = "Insulin Type"
  35. navVC.pushViewController(rootVC, animated: false)
  36. navVC.navigationBar.backgroundColor = .secondarySystemBackground
  37. navVC.maxBasalRateUnitsPerHour = settings.maxBasalRateUnitsPerHour
  38. navVC.maxBolusUnits = settings.maxBolusUnits
  39. navVC.basalSchedule = settings.basalSchedule
  40. return .userInteractionRequired(navVC)
  41. }
  42. public func settingsViewController(bluetoothProvider: BluetoothProvider, colorPalette: LoopUIColorPalette, allowDebugFeatures: Bool, allowedInsulinTypes: [InsulinType]) -> PumpManagerViewController {
  43. let settings = MinimedPumpSettingsViewController(pumpManager: self, supportedInsulinTypes: allowedInsulinTypes)
  44. let nav = PumpManagerSettingsNavigationViewController(rootViewController: settings)
  45. return nav
  46. }
  47. public func deliveryUncertaintyRecoveryViewController(colorPalette: LoopUIColorPalette, allowDebugFeatures: Bool) -> (UIViewController & CompletionNotifying) {
  48. // Return settings for now. No uncertainty handling atm.
  49. let settings = MinimedPumpSettingsViewController(pumpManager: self, supportedInsulinTypes: [])
  50. let nav = SettingsNavigationViewController(rootViewController: settings)
  51. return nav
  52. }
  53. public var smallImage: UIImage? {
  54. return state.smallPumpImage
  55. }
  56. public func hudProvider(bluetoothProvider: BluetoothProvider, colorPalette: LoopUIColorPalette, allowedInsulinTypes: [InsulinType]) -> HUDProvider? {
  57. return MinimedHUDProvider(pumpManager: self, bluetoothProvider: bluetoothProvider, colorPalette: colorPalette, allowedInsulinTypes: allowedInsulinTypes)
  58. }
  59. public static func createHUDView(rawValue: HUDProvider.HUDViewRawState) -> BaseHUDView? {
  60. return MinimedHUDProvider.createHUDView(rawValue: rawValue)
  61. }
  62. }
  63. // MARK: - PumpStatusIndicator
  64. extension MinimedPumpManager {
  65. public var pumpStatusHighlight: DeviceStatusHighlight? {
  66. return buildPumpStatusHighlight(for: state, recents: recents)
  67. }
  68. public var pumpLifecycleProgress: DeviceLifecycleProgress? {
  69. return nil
  70. }
  71. public var pumpStatusBadge: DeviceStatusBadge? {
  72. return nil
  73. }
  74. }