PumpConfigRootView.swift 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. shouldDisplayHint.toggle()
  56. },
  57. label: {
  58. HStack {
  59. Image(systemName: "questionmark.circle")
  60. }
  61. }
  62. ).buttonStyle(BorderlessButtonStyle())
  63. }.padding(.top)
  64. }.padding(.vertical)
  65. }
  66. }
  67. )
  68. .padding(.top)
  69. .listRowBackground(Color.chart)
  70. }
  71. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  72. .onAppear(perform: configureView)
  73. .navigationTitle("Insulin Pump")
  74. .navigationBarTitleDisplayMode(.automatic)
  75. .navigationBarItems(leading: displayClose ? Button("Close", action: state.hideModal) : nil)
  76. .sheet(isPresented: $state.setupPump) {
  77. if let pumpManager = state.provider.apsManager.pumpManager {
  78. PumpSettingsView(
  79. pumpManager: pumpManager,
  80. bluetoothManager: state.provider.apsManager.bluetoothManager!,
  81. completionDelegate: state,
  82. setupDelegate: state
  83. )
  84. } else {
  85. PumpSetupView(
  86. pumpType: state.setupPumpType,
  87. pumpInitialSettings: state.initialSettings,
  88. bluetoothManager: state.provider.apsManager.bluetoothManager!,
  89. completionDelegate: state,
  90. setupDelegate: state
  91. )
  92. }
  93. }
  94. .sheet(isPresented: $shouldDisplayHint) {
  95. SettingInputHintView(
  96. hintDetent: $hintDetent,
  97. shouldDisplayHint: $shouldDisplayHint,
  98. hintLabel: "Pump Pairing to Trio",
  99. hintText: AnyView(
  100. VStack(alignment: .leading, spacing: 10) {
  101. Text(
  102. "Current Pump Models Supported:"
  103. )
  104. VStack(alignment: .leading) {
  105. Text("• Medtronic")
  106. Text("• Omnipod Eros")
  107. Text("• Omnipod Dash")
  108. Text("• Dana (RS/-i)")
  109. Text("• Pump Simulator")
  110. }
  111. Text(
  112. "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."
  113. )
  114. }
  115. ),
  116. sheetTitle: "Help"
  117. )
  118. }
  119. .confirmationDialog("Pump Model", isPresented: $showPumpSelection) {
  120. Button("Medtronic") { state.addPump(.minimed) }
  121. Button("Omnipod Eros") { state.addPump(.omnipod) }
  122. Button("Omnipod Dash") { state.addPump(.omnipodBLE) }
  123. Button("Dana(RS/-i)") { state.addPump(.dana) }
  124. Button("Pump Simulator") { state.addPump(.simulator) }
  125. } message: { Text("Select Pump Model") }
  126. }
  127. }
  128. }
  129. }