CGMManagerUI.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // CGMManagerUI.swift
  3. // LoopKitUI
  4. //
  5. // Copyright © 2018 LoopKit Authors. All rights reserved.
  6. //
  7. import HealthKit
  8. import SwiftUI
  9. import LoopKit
  10. public struct CGMManagerDescriptor {
  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 protocol CGMStatusIndicator {
  19. /// a message from the cgm that needs to be brought to the user's attention in the status bar
  20. var cgmStatusHighlight: DeviceStatusHighlight? { get }
  21. /// the completed percent of the progress bar to display in the status bar
  22. var cgmLifecycleProgress: DeviceLifecycleProgress? { get }
  23. /// a badge from the cgm that needs to be brought to the user's attention in the status bar
  24. var cgmStatusBadge: DeviceStatusBadge? { get }
  25. /// gets the range category of a glucose sample using the CGM manager managed glucose thresholds
  26. func glucoseRangeCategory(for glucose: GlucoseSampleValue) -> GlucoseRangeCategory?
  27. }
  28. public typealias CGMManagerViewController = (UIViewController & CGMManagerOnboarding & CompletionNotifying)
  29. public protocol CGMManagerUI: CGMManager, DeviceManagerUI, DisplayGlucoseUnitObserver, CGMStatusIndicator {
  30. /// Create and onboard a new CGM manager.
  31. ///
  32. /// - Parameters:
  33. /// - bluetoothProvider: The provider of Bluetooth functionality.
  34. /// - displayGlucoseUnitObservable: The glucose units to use for display.
  35. /// - colorPalette: Color palette to use for any UI.
  36. /// - Returns: Either a conforming view controller to create and onboard the CGM manager or a newly created and onboarded CGM manager.
  37. static func setupViewController(bluetoothProvider: BluetoothProvider, displayGlucoseUnitObservable: DisplayGlucoseUnitObservable, colorPalette: LoopUIColorPalette, allowDebugFeatures: Bool) -> SetupUIResult<CGMManagerViewController, CGMManagerUI>
  38. /// Configure settings for an existing CGM manager.
  39. ///
  40. /// - Parameters:
  41. /// - bluetoothProvider: The provider of Bluetooth functionality.
  42. /// - displayGlucoseUnitObservable: The glucose units to use for display.
  43. /// - colorPalette: Color palette to use for any UI.
  44. /// - Returns: A view controller to configure an existing CGM manager.
  45. func settingsViewController(bluetoothProvider: BluetoothProvider, displayGlucoseUnitObservable: DisplayGlucoseUnitObservable, colorPalette: LoopUIColorPalette, allowDebugFeatures: Bool) -> CGMManagerViewController
  46. }
  47. extension CGMManagerUI {
  48. public func glucoseRangeCategory(for glucose: GlucoseSampleValue) -> GlucoseRangeCategory? {
  49. return nil
  50. }
  51. /// When conformance to the DisplayGlucoseUnitObserver is desired, use this function to be notified when the user display glucose unit changes
  52. public func displayGlucoseUnitDidChange(to displayGlucoseUnit: HKUnit) {
  53. // optional
  54. }
  55. }
  56. public protocol CGMManagerOnboardingDelegate: AnyObject {
  57. /// Informs the delegate that the specified CGM manager was created.
  58. ///
  59. /// - Parameters:
  60. /// - cgmManager: The CGM manager created.
  61. func cgmManagerOnboarding(didCreateCGMManager cgmManager: CGMManagerUI)
  62. /// Informs the delegate that the specified CGM manager was onboarded.
  63. ///
  64. /// - Parameters:
  65. /// - cgmManager: The CGM manager onboarded.
  66. func cgmManagerOnboarding(didOnboardCGMManager cgmManager: CGMManagerUI)
  67. }
  68. public protocol CGMManagerOnboarding {
  69. /// Delegate to notify about CGM manager onboarding.
  70. var cgmManagerOnboardingDelegate: CGMManagerOnboardingDelegate? { get set }
  71. }