PumpConfigRootView.swift 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. @Environment(AppState.self) var appState
  17. var body: some View {
  18. NavigationView {
  19. Form {
  20. Section(
  21. header: Text("Pump Integration to Trio"),
  22. content: {
  23. if let pumpState = state.pumpState {
  24. Button {
  25. state.setupPump = true
  26. } label: {
  27. HStack {
  28. Image(uiImage: pumpState.image ?? UIImage()).padding()
  29. Text(pumpState.name)
  30. }
  31. }
  32. if state.alertNotAck {
  33. Spacer()
  34. Button("Acknowledge all alerts") { state.ack() }
  35. }
  36. } else {
  37. VStack {
  38. Button {
  39. showPumpSelection.toggle()
  40. } label: {
  41. Text("Add Pump")
  42. .font(.title3) }
  43. .frame(maxWidth: .infinity, alignment: .center)
  44. .buttonStyle(.bordered)
  45. HStack(alignment: .center) {
  46. Text(
  47. "Pair your insulin pump with Trio. See hint for compatible devices."
  48. )
  49. .font(.footnote)
  50. .foregroundColor(.secondary)
  51. .lineLimit(nil)
  52. Spacer()
  53. Button(
  54. action: {
  55. hintLabel = "Pump Pairing to Trio"
  56. selectedVerboseHint =
  57. AnyView(
  58. VStack(alignment: .leading, spacing: 10) {
  59. Text(
  60. "Current Pump Models Supported:"
  61. )
  62. VStack(alignment: .leading) {
  63. Text("• Medtronic")
  64. Text("• Omnipod Eros")
  65. Text("• Omnipod Dash")
  66. Text("• Dana (RS/-i)")
  67. Text("• Pump Simulator")
  68. }
  69. Text(
  70. "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."
  71. )
  72. }
  73. )
  74. shouldDisplayHint.toggle()
  75. },
  76. label: {
  77. HStack {
  78. Image(systemName: "questionmark.circle")
  79. }
  80. }
  81. ).buttonStyle(BorderlessButtonStyle())
  82. }.padding(.top)
  83. }.padding(.vertical)
  84. }
  85. }
  86. )
  87. .padding(.top)
  88. .listRowBackground(Color.chart)
  89. }
  90. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  91. .onAppear(perform: configureView)
  92. .navigationTitle("Insulin Pump")
  93. .navigationBarTitleDisplayMode(.automatic)
  94. .navigationBarItems(leading: displayClose ? Button("Close", action: state.hideModal) : nil)
  95. .sheet(isPresented: $shouldDisplayHint) {
  96. SettingInputHintView(
  97. hintDetent: $hintDetent,
  98. shouldDisplayHint: $shouldDisplayHint,
  99. hintLabel: hintLabel ?? "",
  100. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  101. sheetTitle: "Help"
  102. )
  103. }
  104. .confirmationDialog("Pump Model", isPresented: $showPumpSelection) {
  105. Button("Medtronic") { state.addPump(.minimed) }
  106. Button("Omnipod Eros") { state.addPump(.omnipod) }
  107. Button("Omnipod Dash") { state.addPump(.omnipodBLE) }
  108. Button("Dana(RS/-i)") { state.addPump(.dana) }
  109. Button("Pump Simulator") { state.addPump(.simulator) }
  110. } message: { Text("Select Pump Model") }
  111. }
  112. .sheet(isPresented: $state.setupPump) {
  113. if let pumpManager = state.provider.apsManager.pumpManager {
  114. PumpSettingsView(
  115. pumpManager: pumpManager,
  116. bluetoothManager: state.provider.apsManager.bluetoothManager!,
  117. completionDelegate: state,
  118. setupDelegate: state
  119. )
  120. } else {
  121. PumpSetupView(
  122. pumpType: state.setupPumpType,
  123. pumpInitialSettings: state.initialSettings,
  124. bluetoothManager: state.provider.apsManager.bluetoothManager!,
  125. completionDelegate: state,
  126. setupDelegate: state
  127. )
  128. }
  129. }
  130. }
  131. }
  132. }