PumpConfigRootView.swift 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import SwiftUI
  2. import Swinject
  3. extension PumpConfig {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. let displayClose: Bool
  7. @StateObject var state = StateModel()
  8. @State private var shouldDisplayHint: Bool = false
  9. @State var hintDetent = PresentationDetent.large
  10. @State var selectedVerboseHint: AnyView?
  11. @State var hintLabel: String?
  12. @State private var decimalPlaceholder: Decimal = 0.0
  13. @State private var booleanPlaceholder: Bool = false
  14. @State var showPumpSelection: Bool = false
  15. @Environment(\.colorScheme) var colorScheme
  16. var color: LinearGradient {
  17. colorScheme == .dark ? LinearGradient(
  18. gradient: Gradient(colors: [
  19. Color.bgDarkBlue,
  20. Color.bgDarkerDarkBlue
  21. ]),
  22. startPoint: .top,
  23. endPoint: .bottom
  24. )
  25. :
  26. LinearGradient(
  27. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  28. startPoint: .top,
  29. endPoint: .bottom
  30. )
  31. }
  32. var body: some View {
  33. NavigationView {
  34. Form {
  35. Section(
  36. header: Text("Pump Integration to Trio"),
  37. content: {
  38. if let pumpState = state.pumpState {
  39. Button {
  40. state.setupPump = true
  41. } label: {
  42. HStack {
  43. Image(uiImage: pumpState.image ?? UIImage()).padding()
  44. Text(pumpState.name)
  45. }
  46. }
  47. if state.alertNotAck {
  48. Spacer()
  49. Button("Acknowledge all alerts") { state.ack() }
  50. }
  51. } else {
  52. VStack {
  53. Button {
  54. showPumpSelection.toggle()
  55. } label: {
  56. Text("Add Pump")
  57. .font(.title3) }
  58. .frame(maxWidth: .infinity, alignment: .center)
  59. .buttonStyle(.bordered)
  60. HStack(alignment: .center) {
  61. Text(
  62. "Pair a compatible pump with Trio. See details for available devices."
  63. )
  64. .font(.footnote)
  65. .foregroundColor(.secondary)
  66. .lineLimit(nil)
  67. Spacer()
  68. Button(
  69. action: {
  70. hintLabel = "Pump Pairing to Trio"
  71. selectedVerboseHint =
  72. AnyView(
  73. VStack(alignment: .leading, spacing: 10) {
  74. Text(
  75. "Current Pump Models Supported:"
  76. )
  77. VStack {
  78. Text("• Medtronic")
  79. Text("• Omnipod Eros")
  80. Text("• Omnipod Dash")
  81. Text("• Pump Simulator")
  82. }
  83. Text(
  84. "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."
  85. )
  86. }
  87. )
  88. shouldDisplayHint.toggle()
  89. },
  90. label: {
  91. HStack {
  92. Image(systemName: "questionmark.circle")
  93. }
  94. }
  95. ).buttonStyle(BorderlessButtonStyle())
  96. }.padding(.top)
  97. }.padding(.vertical)
  98. }
  99. }
  100. )
  101. .padding(.top)
  102. .listRowBackground(Color.chart)
  103. }
  104. .scrollContentBackground(.hidden).background(color)
  105. .onAppear(perform: configureView)
  106. .navigationTitle("Insulin Pump")
  107. .navigationBarTitleDisplayMode(.automatic)
  108. .navigationBarItems(leading: displayClose ? Button("Close", action: state.hideModal) : nil)
  109. .sheet(isPresented: $state.setupPump) {
  110. if let pumpManager = state.provider.apsManager.pumpManager {
  111. PumpSettingsView(
  112. pumpManager: pumpManager,
  113. bluetoothManager: state.provider.apsManager.bluetoothManager!,
  114. completionDelegate: state,
  115. setupDelegate: state
  116. )
  117. } else {
  118. PumpSetupView(
  119. pumpType: state.setupPumpType,
  120. pumpInitialSettings: state.initialSettings,
  121. bluetoothManager: state.provider.apsManager.bluetoothManager!,
  122. completionDelegate: state,
  123. setupDelegate: state
  124. )
  125. }
  126. }
  127. .sheet(isPresented: $shouldDisplayHint) {
  128. SettingInputHintView(
  129. hintDetent: $hintDetent,
  130. shouldDisplayHint: $shouldDisplayHint,
  131. hintLabel: hintLabel ?? "",
  132. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  133. sheetTitle: "Help"
  134. )
  135. }
  136. .confirmationDialog("Pump Model", isPresented: $showPumpSelection) {
  137. Button("Medtronic") { state.addPump(.minimed) }
  138. Button("Omnipod Eros") { state.addPump(.omnipod) }
  139. Button("Omnipod Dash") { state.addPump(.omnipodBLE) }
  140. Button("Pump Simulator") { state.addPump(.simulator) }
  141. } message: { Text("Select Pump Model") }
  142. }
  143. }
  144. }
  145. }