PumpConfigRootView.swift 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. Spacer()
  49. } else {
  50. VStack {
  51. Button {
  52. showPumpSelection.toggle()
  53. } label: {
  54. Text("Add Pump")
  55. .font(.title3) }
  56. .frame(maxWidth: .infinity, alignment: .center)
  57. .buttonStyle(.bordered)
  58. HStack(alignment: .center) {
  59. Text(
  60. "Pair your insulin pump with Trio. See hint for compatible devices."
  61. )
  62. .font(.footnote)
  63. .foregroundColor(.secondary)
  64. .lineLimit(nil)
  65. Spacer()
  66. Button(
  67. action: {
  68. shouldDisplayHint.toggle()
  69. },
  70. label: {
  71. HStack {
  72. Image(systemName: "questionmark.circle")
  73. }
  74. }
  75. ).buttonStyle(BorderlessButtonStyle())
  76. }.padding(.top)
  77. }.padding(.vertical)
  78. }
  79. }
  80. )
  81. .listRowBackground(Color.chart)
  82. }
  83. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  84. .onAppear(perform: configureView)
  85. .navigationTitle("Insulin Pump")
  86. .navigationBarTitleDisplayMode(.automatic)
  87. .navigationBarItems(leading: displayClose ? Button("Close", action: state.hideModal) : nil)
  88. .sheet(isPresented: $state.setupPump) {
  89. if let pumpManager = state.provider.apsManager.pumpManager {
  90. PumpSettingsView(
  91. pumpManager: pumpManager,
  92. bluetoothManager: state.provider.apsManager.bluetoothManager!,
  93. completionDelegate: state,
  94. setupDelegate: state
  95. )
  96. } else {
  97. PumpSetupView(
  98. pumpType: state.setupPumpType,
  99. pumpInitialSettings: state.initialSettings,
  100. bluetoothManager: state.provider.apsManager.bluetoothManager!,
  101. completionDelegate: state,
  102. setupDelegate: state
  103. )
  104. }
  105. }
  106. .sheet(isPresented: $shouldDisplayHint) {
  107. SettingInputHintView(
  108. hintDetent: $hintDetent,
  109. shouldDisplayHint: $shouldDisplayHint,
  110. hintLabel: "Pump Pairing to Trio",
  111. hintText: AnyView(
  112. VStack(alignment: .leading, spacing: 10) {
  113. Text(
  114. "Current Pump Models Supported:"
  115. )
  116. VStack(alignment: .leading) {
  117. Text("• Medtronic")
  118. Text("• All Omnipod Types")
  119. Text("• Omnipod Eros")
  120. Text("• Omnipod DASH")
  121. Text("• Dana (RS/-i)")
  122. Text("• Medtrum Nano (200u/300u)")
  123. Text("• Pump Simulator")
  124. }
  125. Text(
  126. "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."
  127. )
  128. }
  129. ),
  130. sheetTitle: String(localized: "Help", comment: "Help sheet title")
  131. )
  132. }
  133. .confirmationDialog("Pump Model", isPresented: $showPumpSelection) {
  134. Button("Medtronic") { state.addPump(.minimed) }
  135. Button("All Omnipod Types") { state.addPump(.omni) }
  136. Button("Dana(RS/-i)") { state.addPump(.dana) }
  137. Button("Medtrum Nano") { state.addPump(.medtrum) }
  138. Button("Pump Simulator") { state.addPump(.simulator) }
  139. } message: { Text("Select Pump Model") }
  140. }
  141. }
  142. }
  143. }