AutosensSettingsRootView.swift 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import SwiftUI
  2. import Swinject
  3. extension AutosensSettings {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @State var state = StateModel()
  7. @State private var shouldDisplayHint: Bool = false
  8. @State var hintDetent = PresentationDetent.large
  9. @State var selectedVerboseHint: AnyView?
  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. @EnvironmentObject var appIcons: Icons
  15. private var color: LinearGradient {
  16. colorScheme == .dark ? LinearGradient(
  17. gradient: Gradient(colors: [
  18. Color.bgDarkBlue,
  19. Color.bgDarkerDarkBlue
  20. ]),
  21. startPoint: .top,
  22. endPoint: .bottom
  23. )
  24. :
  25. LinearGradient(
  26. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  27. startPoint: .top,
  28. endPoint: .bottom
  29. )
  30. }
  31. var body: some View {
  32. List {
  33. SettingInputSection(
  34. decimalValue: $state.autosensMax,
  35. booleanValue: $booleanPlaceholder,
  36. shouldDisplayHint: $shouldDisplayHint,
  37. selectedVerboseHint: Binding(
  38. get: { selectedVerboseHint },
  39. set: {
  40. selectedVerboseHint = $0.map { AnyView($0) }
  41. hintLabel = NSLocalizedString("Autosens Max", comment: "Autosens Max")
  42. }
  43. ),
  44. units: state.units,
  45. type: .decimal("autosensMax"),
  46. label: NSLocalizedString("Autosens Max", comment: "Autosens Max"),
  47. miniHint: "The higher limit of the Autosens Ratio",
  48. verboseHint: VStack(spacing: 10) {
  49. Text("Default: 120%").bold()
  50. VStack(alignment: .leading, spacing: 10) {
  51. Text(
  52. "Autosens Max sets the maximum Autosens Ratio used by Autosens, Dynamic ISF, or Sigmoid Formula"
  53. )
  54. Text(
  55. "The Autosens Ratio is used to calculate the amount of adjustment needed to basal rates, ISF, and CR."
  56. )
  57. Text(
  58. "Tip: Increasing this value allows automatic adjustments of basal rates to be higher, ISF to be lower, and CR to be lower."
  59. )
  60. }
  61. },
  62. headerText: "Glucose Deviations Algorithm"
  63. )
  64. SettingInputSection(
  65. decimalValue: $state.autosensMin,
  66. booleanValue: $booleanPlaceholder,
  67. shouldDisplayHint: $shouldDisplayHint,
  68. selectedVerboseHint: Binding(
  69. get: { selectedVerboseHint },
  70. set: {
  71. selectedVerboseHint = $0.map { AnyView($0) }
  72. hintLabel = NSLocalizedString("Autosens Min", comment: "Autosens Min")
  73. }
  74. ),
  75. units: state.units,
  76. type: .decimal("autosensMin"),
  77. label: NSLocalizedString("Autosens Min", comment: "Autosens Min"),
  78. miniHint: "The lower limit of the Autosens Ratio",
  79. verboseHint: VStack(spacing: 10) {
  80. Text("Default: 80%").bold()
  81. VStack(alignment: .leading, spacing: 10) {
  82. Text(
  83. "Autosens Min sets the minimum Autosens Ratio used by Autosens, Dynamic ISF, or Sigmoid Formula."
  84. )
  85. Text(
  86. "The Autosens Ratio is used to calculate the amount of adjustment needed to basal rates, ISF, and CR."
  87. )
  88. Text(
  89. "Tip: Decreasing this value allows automatic adjustments of basal rates to be lower, ISF to be higher, and CR to be higher."
  90. )
  91. }
  92. }
  93. )
  94. SettingInputSection(
  95. decimalValue: $decimalPlaceholder,
  96. booleanValue: $state.rewindResetsAutosens,
  97. shouldDisplayHint: $shouldDisplayHint,
  98. selectedVerboseHint: Binding(
  99. get: { selectedVerboseHint },
  100. set: {
  101. selectedVerboseHint = $0.map { AnyView($0) }
  102. hintLabel = NSLocalizedString("Rewind Resets Autosens", comment: "Rewind Resets Autosens")
  103. }
  104. ),
  105. units: state.units,
  106. type: .boolean,
  107. label: NSLocalizedString("Rewind Resets Autosens", comment: "Rewind Resets Autosens"),
  108. miniHint: "Pump rewind initiates a reset in Autosens Ratio",
  109. verboseHint: VStack(spacing: 10) {
  110. Text("Default: ON").bold()
  111. Text("Medtronic Users Only").bold()
  112. VStack(alignment: .leading, spacing: 10) {
  113. Text(
  114. "This feature resets the Autosens Ratio to neutral when you rewind your pump on the assumption that this corresponds to a site change."
  115. )
  116. Text(
  117. "Autosens will begin learning sensitivity anew from the time of the rewind, which may take up to 6 hours."
  118. )
  119. Text(
  120. "Tip: If you usually rewind your pump independently of site changes, you may want to consider disabling this feature."
  121. )
  122. }
  123. }
  124. )
  125. }
  126. .sheet(isPresented: $shouldDisplayHint) {
  127. SettingInputHintView(
  128. hintDetent: $hintDetent,
  129. shouldDisplayHint: $shouldDisplayHint,
  130. hintLabel: hintLabel ?? "",
  131. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  132. sheetTitle: "Help"
  133. )
  134. }
  135. .scrollContentBackground(.hidden).background(color)
  136. .onAppear(perform: configureView)
  137. .navigationTitle("Autosens")
  138. .navigationBarTitleDisplayMode(.automatic)
  139. .onDisappear {
  140. state.saveIfChanged()
  141. }
  142. }
  143. }
  144. }