PumpConfigRootView.swift 6.7 KB

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