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