PumpSettingsEditorRootView.swift 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. SettingInputSection(
  38. decimalValue: $state.maxBolus,
  39. booleanValue: $booleanPlaceholder,
  40. shouldDisplayHint: $shouldDisplayHint,
  41. selectedVerboseHint: Binding(
  42. get: { selectedVerboseHint },
  43. set: {
  44. selectedVerboseHint = $0
  45. hintLabel = "Max Bolus"
  46. }
  47. ),
  48. units: state.units,
  49. type: .decimal("maxBolus"),
  50. label: "Max Bolus",
  51. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  52. verboseHint: "Max Bolus… bla bla bla"
  53. )
  54. SettingInputSection(
  55. decimalValue: $state.maxBasal,
  56. booleanValue: $booleanPlaceholder,
  57. shouldDisplayHint: $shouldDisplayHint,
  58. selectedVerboseHint: Binding(
  59. get: { selectedVerboseHint },
  60. set: {
  61. selectedVerboseHint = $0
  62. hintLabel = "Max Basal"
  63. }
  64. ),
  65. units: state.units,
  66. type: .decimal("maxBasal"),
  67. label: "Max Basal",
  68. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  69. verboseHint: "Max Basal… bla bla bla"
  70. )
  71. SettingInputSection(
  72. decimalValue: $state.dia,
  73. booleanValue: $booleanPlaceholder,
  74. shouldDisplayHint: $shouldDisplayHint,
  75. selectedVerboseHint: Binding(
  76. get: { selectedVerboseHint },
  77. set: {
  78. selectedVerboseHint = $0
  79. hintLabel = "Duration of Insulin Action"
  80. }
  81. ),
  82. units: state.units,
  83. type: .decimal("dia"),
  84. label: "Duration of Insulin Action",
  85. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  86. verboseHint: "Duration of Insulin Action… bla bla bla"
  87. )
  88. Section {
  89. HStack {
  90. if state.syncInProgress {
  91. ProgressView().padding(.trailing, 10)
  92. }
  93. Button {
  94. let impactHeavy = UIImpactFeedbackGenerator(style: .heavy)
  95. impactHeavy.impactOccurred()
  96. state.save()
  97. } label: {
  98. Text(state.syncInProgress ? "Saving..." : "Save")
  99. }
  100. .disabled(state.syncInProgress || !state.hasChanged)
  101. .frame(maxWidth: .infinity, alignment: .center)
  102. .tint(.white)
  103. }
  104. }.listRowBackground(state.syncInProgress || !state.hasChanged ? Color(.systemGray4) : Color(.systemBlue))
  105. }
  106. .sheet(isPresented: $shouldDisplayHint) {
  107. SettingInputHintView(
  108. hintDetent: $hintDetent,
  109. shouldDisplayHint: $shouldDisplayHint,
  110. hintLabel: hintLabel ?? "",
  111. hintText: selectedVerboseHint ?? "",
  112. sheetTitle: "Help"
  113. )
  114. }
  115. .scrollContentBackground(.hidden).background(color)
  116. .onAppear(perform: configureView)
  117. .navigationTitle("Delivery Limits")
  118. .navigationBarTitleDisplayMode(.automatic)
  119. }
  120. }
  121. }