AutosensSettingsRootView.swift 7.1 KB

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