AutosensSettingsRootView.swift 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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: """
  48. The higher limit of the Autosens Ratio
  49. Default: 120%
  50. """,
  51. verboseHint: VStack {
  52. Text("Default: 120%").bold()
  53. Text(
  54. """
  55. Autosens Max sets the maximum Autosens Ratio used by Autosens, Dynamic ISF, Sigmoid Formula, and/or Autotune.
  56. The Autosens Ratio is used to calculate the amount of adjustment needed to basals, ISF, and CR.
  57. """
  58. )
  59. Text(
  60. "Increasing this value allows automatic adjustments of basal rates to be higher, ISF to be lower, and CR to be lower."
  61. )
  62. .italic()
  63. },
  64. headerText: "Glucose Deviations Algorithm"
  65. )
  66. SettingInputSection(
  67. decimalValue: $state.autosensMin,
  68. booleanValue: $booleanPlaceholder,
  69. shouldDisplayHint: $shouldDisplayHint,
  70. selectedVerboseHint: Binding(
  71. get: { selectedVerboseHint },
  72. set: {
  73. selectedVerboseHint = $0.map { AnyView($0) }
  74. hintLabel = NSLocalizedString("Autosens Min", comment: "Autosens Min")
  75. }
  76. ),
  77. units: state.units,
  78. type: .decimal("autosensMin"),
  79. label: NSLocalizedString("Autosens Min", comment: "Autosens Min"),
  80. miniHint: """
  81. The lower limit of the Autosens Ratio
  82. Default: 80%
  83. """,
  84. verboseHint: VStack {
  85. Text("Default: 80%").bold()
  86. Text(
  87. """
  88. Autosens Min sets the minimum Autosens Ratio used by Autosens, Dynamic ISF, Sigmoid Formula, and/or Autotune.
  89. The Autosens Ratio is used to calculate the amount of adjustment needed to basals, ISF, and CR.
  90. """
  91. )
  92. Text(
  93. "Decreasing this value allows automatic adjustments of basal rates to be lower, ISF to be higher, and CR to be higher."
  94. )
  95. .italic()
  96. }
  97. )
  98. SettingInputSection(
  99. decimalValue: $decimalPlaceholder,
  100. booleanValue: $state.rewindResetsAutosens,
  101. shouldDisplayHint: $shouldDisplayHint,
  102. selectedVerboseHint: Binding(
  103. get: { selectedVerboseHint },
  104. set: {
  105. selectedVerboseHint = $0.map { AnyView($0) }
  106. hintLabel = NSLocalizedString("Rewind Resets Autosens", comment: "Rewind Resets Autosens")
  107. }
  108. ),
  109. units: state.units,
  110. type: .boolean,
  111. label: NSLocalizedString("Rewind Resets Autosens", comment: "Rewind Resets Autosens"),
  112. miniHint: """
  113. Pump rewind initiates a reset in Autosens Ratio
  114. Default: ON
  115. """,
  116. verboseHint: VStack {
  117. Text("Default: ON").bold()
  118. Text("Medtronic Users Only").bold().italic()
  119. Text("This feature resets the Autosens Ratio to neutral when you rewind your pump on the assumption that this corresponds to a site change.")
  120. Text("Autosens will begin learning sensitivity anew from the time of the rewind, which may take up to 6 hours.")
  121. Text("If you usually rewind your pump independently of site changes, you may want to consider disabling this feature.").italic()
  122. }
  123. )
  124. }
  125. .sheet(isPresented: $shouldDisplayHint) {
  126. SettingInputHintView(
  127. hintDetent: $hintDetent,
  128. shouldDisplayHint: $shouldDisplayHint,
  129. hintLabel: hintLabel ?? "",
  130. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  131. sheetTitle: "Help"
  132. )
  133. }
  134. .scrollContentBackground(.hidden).background(color)
  135. .onAppear(perform: configureView)
  136. .navigationTitle("Autosens")
  137. .navigationBarTitleDisplayMode(.automatic)
  138. .onDisappear {
  139. state.saveIfChanged()
  140. }
  141. }
  142. }
  143. }