MinimedPumpManager+UI.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. return MinimedUICoordinator(pumpManager: self, colorPalette: colorPalette, allowDebugFeatures: allowDebugFeatures, allowedInsulinTypes: allowedInsulinTypes)
  44. }
  45. public func deliveryUncertaintyRecoveryViewController(colorPalette: LoopUIColorPalette, allowDebugFeatures: Bool) -> (UIViewController & CompletionNotifying) {
  46. return MinimedUICoordinator(pumpManager: self, colorPalette: colorPalette, allowDebugFeatures: allowDebugFeatures, allowedInsulinTypes: [])
  47. }
  48. public var smallImage: UIImage? {
  49. return state.smallPumpImage
  50. }
  51. public func hudProvider(bluetoothProvider: BluetoothProvider, colorPalette: LoopUIColorPalette, allowedInsulinTypes: [InsulinType]) -> HUDProvider? {
  52. return MinimedHUDProvider(pumpManager: self, bluetoothProvider: bluetoothProvider, colorPalette: colorPalette, allowedInsulinTypes: allowedInsulinTypes)
  53. }
  54. public static func createHUDView(rawValue: HUDProvider.HUDViewRawState) -> BaseHUDView? {
  55. return MinimedHUDProvider.createHUDView(rawValue: rawValue)
  56. }
  57. }
  58. // MARK: - PumpStatusIndicator
  59. extension MinimedPumpManager {
  60. public var pumpStatusHighlight: DeviceStatusHighlight? {
  61. return buildPumpStatusHighlight(for: state, recents: recents, andDate: dateGenerator())
  62. }
  63. public var pumpLifecycleProgress: DeviceLifecycleProgress? {
  64. return nil
  65. }
  66. public var pumpStatusBadge: DeviceStatusBadge? {
  67. return nil
  68. }
  69. }