AutosensSettingsRootView.swift 6.8 KB

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