PumpSettingsEditorRootView.swift 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import SwiftUI
  2. import Swinject
  3. extension PumpSettingsEditor {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. @State private var shouldDisplayHint: Bool = false
  8. @State var hintDetent = PresentationDetent.large
  9. @State var selectedVerboseHint: String?
  10. @State var hintLabel: String?
  11. @State private var decimalPlaceholder: Decimal = 0.0
  12. @State private var booleanPlaceholder: Bool = false
  13. @Environment(\.colorScheme) var colorScheme
  14. var color: LinearGradient {
  15. colorScheme == .dark ? LinearGradient(
  16. gradient: Gradient(colors: [
  17. Color.bgDarkBlue,
  18. Color.bgDarkerDarkBlue
  19. ]),
  20. startPoint: .top,
  21. endPoint: .bottom
  22. )
  23. :
  24. LinearGradient(
  25. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  26. startPoint: .top,
  27. endPoint: .bottom
  28. )
  29. }
  30. private var formatter: NumberFormatter {
  31. let formatter = NumberFormatter()
  32. formatter.numberStyle = .decimal
  33. return formatter
  34. }
  35. var body: some View {
  36. Form {
  37. Section(
  38. header: Text("Insulin Pump Configuration"),
  39. content: {
  40. VStack {
  41. HStack {
  42. Text("Max Basal")
  43. Spacer()
  44. TextFieldWithToolBar(text: $state.maxBasal, placeholder: "0", numberFormatter: formatter)
  45. }.padding(.top)
  46. HStack {
  47. Text("Max Bolus")
  48. Spacer()
  49. TextFieldWithToolBar(text: $state.maxBolus, placeholder: "0", numberFormatter: formatter)
  50. }
  51. HStack(alignment: .top) {
  52. Text(
  53. "Sets delivery limits for basal and bolus insulin on pump."
  54. )
  55. .lineLimit(nil)
  56. .font(.footnote)
  57. .foregroundColor(.secondary)
  58. Spacer()
  59. Button(
  60. action: {
  61. hintLabel = "Insulin Delivery limits"
  62. selectedVerboseHint = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
  63. shouldDisplayHint.toggle()
  64. },
  65. label: {
  66. HStack {
  67. Image(systemName: "questionmark.circle")
  68. }
  69. }
  70. ).buttonStyle(BorderlessButtonStyle())
  71. }
  72. }.padding(.bottom)
  73. }
  74. ).listRowBackground(Color.chart)
  75. SettingInputSection(
  76. decimalValue: $state.dia,
  77. booleanValue: $booleanPlaceholder,
  78. shouldDisplayHint: $shouldDisplayHint,
  79. selectedVerboseHint: Binding(
  80. get: { selectedVerboseHint },
  81. set: {
  82. selectedVerboseHint = $0
  83. hintLabel = "Duration of Insulin Action"
  84. }
  85. ),
  86. type: .decimal,
  87. label: "Duration of Insulin Action",
  88. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  89. verboseHint: "Duration of Insulin Action… bla bla bla"
  90. )
  91. Section {
  92. HStack {
  93. if state.syncInProgress {
  94. ProgressView().padding(.trailing, 10)
  95. }
  96. Button {
  97. let impactHeavy = UIImpactFeedbackGenerator(style: .heavy)
  98. impactHeavy.impactOccurred()
  99. state.save()
  100. } label: {
  101. Text(state.syncInProgress ? "Saving..." : "Save on Pump")
  102. }
  103. .disabled(state.syncInProgress || !state.hasChanged)
  104. .frame(maxWidth: .infinity, alignment: .center)
  105. .tint(.white)
  106. }
  107. }.listRowBackground(state.syncInProgress || !state.hasChanged ? Color(.systemGray4) : Color(.systemBlue))
  108. }
  109. .sheet(isPresented: $shouldDisplayHint) {
  110. SettingInputHintView(
  111. hintDetent: $hintDetent,
  112. shouldDisplayHint: $shouldDisplayHint,
  113. hintLabel: hintLabel ?? "",
  114. hintText: selectedVerboseHint ?? "",
  115. sheetTitle: "Help"
  116. )
  117. }
  118. .scrollContentBackground(.hidden).background(color)
  119. .onAppear(perform: configureView)
  120. .navigationTitle("Delivery Limits & DIA")
  121. .navigationBarTitleDisplayMode(.automatic)
  122. }
  123. }
  124. }