PumpManagerUI.swift 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // PumpManagerUI.swift
  3. // Loop
  4. //
  5. // Copyright © 2018 LoopKit Authors. All rights reserved.
  6. //
  7. import UIKit
  8. import SwiftUI
  9. import LoopKit
  10. public struct PumpManagerDescriptor {
  11. public let identifier: String
  12. public let localizedTitle: String
  13. public init(identifier: String, localizedTitle: String) {
  14. self.identifier = identifier
  15. self.localizedTitle = localizedTitle
  16. }
  17. }
  18. public struct PumpManagerSetupSettings {
  19. public var maxBasalRateUnitsPerHour: Double
  20. public var maxBolusUnits: Double
  21. public var basalSchedule: BasalRateSchedule
  22. public init(maxBasalRateUnitsPerHour: Double, maxBolusUnits: Double, basalSchedule: BasalRateSchedule) {
  23. self.maxBasalRateUnitsPerHour = maxBasalRateUnitsPerHour
  24. self.maxBolusUnits = maxBolusUnits
  25. self.basalSchedule = basalSchedule
  26. }
  27. }
  28. public protocol PumpStatusIndicator {
  29. /// a message from the pump that needs to be brought to the user's attention in the status bar
  30. var pumpStatusHighlight: DeviceStatusHighlight? { get }
  31. /// the completed percent of the progress bar to display in the status bar
  32. var pumpLifecycleProgress: DeviceLifecycleProgress? { get }
  33. /// a badge from the pump that needs to be brought to the user's attention in the status bar
  34. var pumpStatusBadge: DeviceStatusBadge? { get }
  35. }
  36. public typealias PumpManagerViewController = (UIViewController & PumpManagerOnboarding & CompletionNotifying)
  37. public protocol PumpManagerUI: DeviceManagerUI, PumpStatusIndicator, PumpManager {
  38. /// Create and onboard a new pump manager.
  39. ///
  40. /// - Parameters:
  41. /// - settings: Settings used to configure the pump manager.
  42. /// - bluetoothProvider: The provider of Bluetooth functionality.
  43. /// - colorPalette: Color palette to use for any UI.
  44. /// - allowedInsulinTypes: Types that the caller allows to be selected.
  45. /// - Returns: Either a conforming view controller to create and onboard the pump manager or a newly created and onboarded pump manager.
  46. static func setupViewController(initialSettings settings: PumpManagerSetupSettings, bluetoothProvider: BluetoothProvider, colorPalette: LoopUIColorPalette, allowDebugFeatures: Bool, allowedInsulinTypes: [InsulinType]) -> SetupUIResult<PumpManagerViewController, PumpManagerUI>
  47. /// Configure settings for an existing pump manager.
  48. ///
  49. /// - Parameters:
  50. /// - bluetoothProvider: The provider of Bluetooth functionality.
  51. /// - colorPalette: Color palette to use for any UI.
  52. /// - Returns: A view controller to configure an existing pump manager.
  53. func settingsViewController(bluetoothProvider: BluetoothProvider, colorPalette: LoopUIColorPalette, allowDebugFeatures: Bool, allowedInsulinTypes: [InsulinType]) -> PumpManagerViewController
  54. // View for recovering from delivery uncertainty
  55. func deliveryUncertaintyRecoveryViewController(colorPalette: LoopUIColorPalette, allowDebugFeatures: Bool) -> (UIViewController & CompletionNotifying)
  56. // Returns a class that can provide HUD views
  57. func hudProvider(bluetoothProvider: BluetoothProvider, colorPalette: LoopUIColorPalette, allowedInsulinTypes: [InsulinType]) -> HUDProvider?
  58. // Instantiates HUD view (typically reservoir volume) from the raw state returned by hudViewRawState
  59. static func createHUDView(rawValue: HUDProvider.HUDViewRawState) -> BaseHUDView?
  60. }
  61. public protocol PumpManagerOnboardingDelegate: AnyObject {
  62. /// Informs the delegate that the specified pump manager was created.
  63. ///
  64. /// - Parameters:
  65. /// - pumpManager: The pump manager created.
  66. func pumpManagerOnboarding(didCreatePumpManager pumpManager: PumpManagerUI)
  67. /// Informs the delegate that the specified pump manager was onboarded.
  68. ///
  69. /// - Parameters:
  70. /// - pumpManager: The pump manager onboarded.
  71. func pumpManagerOnboarding(didOnboardPumpManager pumpManager: PumpManagerUI)
  72. }
  73. public protocol PumpManagerOnboarding {
  74. /// Delegate to notify about pump manager onboarding.
  75. var pumpManagerOnboardingDelegate: PumpManagerOnboardingDelegate? { get set }
  76. }