PumpConfigRootView.swift 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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: .top) {
  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. Text(
  74. "Current Pump Models Supported:\n\n•Medtronic\n•Omnipod Eros\n•Omnipod Dash\n•Pump Simulator\n\nNote: 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."
  75. )
  76. )
  77. shouldDisplayHint.toggle()
  78. },
  79. label: {
  80. HStack {
  81. Image(systemName: "questionmark.circle")
  82. }
  83. }
  84. ).buttonStyle(BorderlessButtonStyle())
  85. }.padding(.top)
  86. }.padding(.vertical)
  87. }
  88. }
  89. )
  90. .padding(.top)
  91. .listRowBackground(Color.chart)
  92. }
  93. .scrollContentBackground(.hidden).background(color)
  94. .onAppear(perform: configureView)
  95. .navigationTitle("Insulin Pump")
  96. .navigationBarTitleDisplayMode(.automatic)
  97. .navigationBarItems(leading: displayClose ? Button("Close", action: state.hideModal) : nil)
  98. .sheet(isPresented: $state.setupPump) {
  99. if let pumpManager = state.provider.apsManager.pumpManager {
  100. PumpSettingsView(
  101. pumpManager: pumpManager,
  102. bluetoothManager: state.provider.apsManager.bluetoothManager!,
  103. completionDelegate: state,
  104. setupDelegate: state
  105. )
  106. } else {
  107. PumpSetupView(
  108. pumpType: state.setupPumpType,
  109. pumpInitialSettings: state.initialSettings,
  110. bluetoothManager: state.provider.apsManager.bluetoothManager!,
  111. completionDelegate: state,
  112. setupDelegate: state
  113. )
  114. }
  115. }
  116. .sheet(isPresented: $shouldDisplayHint) {
  117. SettingInputHintView(
  118. hintDetent: $hintDetent,
  119. shouldDisplayHint: $shouldDisplayHint,
  120. hintLabel: hintLabel ?? "",
  121. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  122. sheetTitle: "Help"
  123. )
  124. }
  125. .confirmationDialog("Pump Model", isPresented: $showPumpSelection) {
  126. Button("Medtronic") { state.addPump(.minimed) }
  127. Button("Omnipod Eros") { state.addPump(.omnipod) }
  128. Button("Omnipod Dash") { state.addPump(.omnipodBLE) }
  129. Button("Pump Simulator") { state.addPump(.simulator) }
  130. } message: { Text("Select Pump Model") }
  131. }
  132. }
  133. }
  134. }