PumpConfigRootView.swift 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import SwiftUI
  2. import Swinject
  3. extension PumpConfig {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. let displayClose: Bool
  7. let bluetoothManager: BluetoothStateManager
  8. @StateObject var state = StateModel()
  9. @State private var shouldDisplayHint: Bool = false
  10. @State var hintDetent = PresentationDetent.large
  11. @State var selectedVerboseHint: AnyView?
  12. @State var hintLabel: String?
  13. @State private var decimalPlaceholder: Decimal = 0.0
  14. @State private var booleanPlaceholder: Bool = false
  15. @State var showPumpSelection: Bool = false
  16. @Environment(\.colorScheme) var colorScheme
  17. @Environment(AppState.self) var appState
  18. var body: some View {
  19. NavigationView {
  20. Form {
  21. Section(
  22. header: Text("Pump Integration to Trio"),
  23. content: {
  24. if bluetoothManager.bluetoothAuthorization != .authorized {
  25. HStack {
  26. Spacer()
  27. BluetoothRequiredView()
  28. Spacer()
  29. }
  30. } else if let pumpState = state.pumpState {
  31. Button {
  32. state.setupPump = true
  33. } label: {
  34. HStack {
  35. Image(uiImage: pumpState.image ?? UIImage())
  36. .resizable()
  37. .scaledToFit()
  38. .frame(maxWidth: 100)
  39. Text(pumpState.name)
  40. }
  41. .frame(maxWidth: .infinity, minHeight: 50, alignment: .center)
  42. .font(.title2)
  43. }.padding()
  44. if state.hasUnacknowledgedAlert {
  45. Spacer()
  46. Button("Acknowledge all alerts") { state.ack() }
  47. }
  48. } else {
  49. VStack {
  50. Button {
  51. showPumpSelection.toggle()
  52. } label: {
  53. Text("Add Pump")
  54. .font(.title3) }
  55. .frame(maxWidth: .infinity, alignment: .center)
  56. .buttonStyle(.bordered)
  57. HStack(alignment: .center) {
  58. Text(
  59. "Pair your insulin pump with Trio. See hint for compatible devices."
  60. )
  61. .font(.footnote)
  62. .foregroundColor(.secondary)
  63. .lineLimit(nil)
  64. Spacer()
  65. Button(
  66. action: {
  67. shouldDisplayHint.toggle()
  68. },
  69. label: {
  70. HStack {
  71. Image(systemName: "questionmark.circle")
  72. }
  73. }
  74. ).buttonStyle(BorderlessButtonStyle())
  75. }.padding(.top)
  76. }.padding(.vertical)
  77. }
  78. }
  79. )
  80. .listRowBackground(Color.chart)
  81. }
  82. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  83. .onAppear(perform: configureView)
  84. .navigationTitle("Insulin Pump")
  85. .navigationBarTitleDisplayMode(.automatic)
  86. .navigationBarItems(leading: displayClose ? Button("Close", action: state.hideModal) : nil)
  87. .sheet(isPresented: $state.setupPump) {
  88. if let pumpManager = state.provider.apsManager.pumpManager {
  89. PumpSettingsView(
  90. pumpManager: pumpManager,
  91. bluetoothManager: state.provider.apsManager.bluetoothManager!,
  92. completionDelegate: state,
  93. setupDelegate: state
  94. )
  95. } else {
  96. PumpSetupView(
  97. pumpType: state.setupPumpType,
  98. pumpInitialSettings: state.initialSettings,
  99. bluetoothManager: state.provider.apsManager.bluetoothManager!,
  100. completionDelegate: state,
  101. setupDelegate: state
  102. )
  103. }
  104. }
  105. .sheet(isPresented: $shouldDisplayHint) {
  106. SettingInputHintView(
  107. hintDetent: $hintDetent,
  108. shouldDisplayHint: $shouldDisplayHint,
  109. hintLabel: "Pump Pairing to Trio",
  110. hintText: AnyView(
  111. VStack(alignment: .leading, spacing: 10) {
  112. Text(
  113. "Current Pump Models Supported:"
  114. )
  115. VStack(alignment: .leading) {
  116. Text("• Medtronic")
  117. Text("• All Omnipod Types")
  118. Text("• Omnipod Eros")
  119. Text("• Omnipod DASH")
  120. Text("• Dana (RS/-i)")
  121. Text("• Medtrum Nano (200u/300u)")
  122. Text("• Pump Simulator")
  123. }
  124. Text(
  125. "Note: If using a pump simulator, you will not have continuous readings from the CGM in Trio. Using a pump simulator is only advisable for becoming familiar with the app user interface. It will not give you insight on how the algorithm will respond."
  126. )
  127. }
  128. ),
  129. sheetTitle: String(localized: "Help", comment: "Help sheet title")
  130. )
  131. }
  132. .confirmationDialog("Pump Model", isPresented: $showPumpSelection) {
  133. Button("Medtronic") { state.addPump(.minimed) }
  134. Button("All Omnipod Types") { state.addPump(.omni) }
  135. Button("Omnipod Eros") { state.addPump(.omnipod) }
  136. Button("Omnipod DASH") { state.addPump(.omnipodBLE) }
  137. Button("Dana(RS/-i)") { state.addPump(.dana) }
  138. Button("Medtrum Nano") { state.addPump(.medtrum) }
  139. Button("Pump Simulator") { state.addPump(.simulator) }
  140. } message: { Text("Select Pump Model") }
  141. }
  142. }
  143. }
  144. }