TargetBehavoirRootView.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import SwiftUI
  2. import Swinject
  3. extension TargetBehavoir {
  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: 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. @Environment(AppState.self) var appState
  16. var body: some View {
  17. List {
  18. SettingInputSection(
  19. decimalValue: $decimalPlaceholder,
  20. booleanValue: $state.highTemptargetRaisesSensitivity,
  21. shouldDisplayHint: $shouldDisplayHint,
  22. selectedVerboseHint: Binding(
  23. get: { selectedVerboseHint },
  24. set: {
  25. selectedVerboseHint = $0.map { AnyView($0) }
  26. hintLabel = NSLocalizedString(
  27. "High Temp Target Raises Sensitivity",
  28. comment: "High Temp Target Raises Sensitivity"
  29. )
  30. }
  31. ),
  32. units: state.units,
  33. type: .boolean,
  34. label: NSLocalizedString(
  35. "High Temp Target Raises Sensitivity",
  36. comment: "High Temp Target Raises Sensitivity"
  37. ),
  38. miniHint: "A Temp Target > \(state.units == .mgdL ? "110" : 110.formattedAsMmolL) \(state.units.rawValue) increases sensitivity when glucose is above target.",
  39. verboseHint:
  40. VStack(alignment: .leading, spacing: 10) {
  41. Text("Default: OFF").bold()
  42. Text(
  43. "When this feature is enabled, setting a temporary target above \(state.units == .mgdL ? "110" : 110.formattedAsMmolL) \(state.units.rawValue) will decrease the Autosens Ratio used for ISF and basal adjustments, resulting in less insulin delivered overall. This scales with the temporary target set; the higher the temp target, the lower the Autosens Ratio used."
  44. )
  45. Text(
  46. "If Half Basal Exercise Target is set to \(state.units == .mgdL ? "160" : 160.formattedAsMmolL) \(state.units.rawValue), a temp target of \(state.units == .mgdL ? "120" : 120.formattedAsMmolL) \(state.units.rawValue) uses an Autosens Ratio of 0.75. A temp target of \(state.units == .mgdL ? "140" : 140.formattedAsMmolL) \(state.units.rawValue) uses an Autosens Ratio of 0.6."
  47. )
  48. Text("Note: The effect of this can be adjusted with the Half Basal Exercise Target")
  49. },
  50. headerText: "Algorithmic Target Settings"
  51. )
  52. SettingInputSection(
  53. decimalValue: $decimalPlaceholder,
  54. booleanValue: $state.lowTemptargetLowersSensitivity,
  55. shouldDisplayHint: $shouldDisplayHint,
  56. selectedVerboseHint: Binding(
  57. get: { selectedVerboseHint },
  58. set: {
  59. selectedVerboseHint = $0.map { AnyView($0) }
  60. hintLabel = NSLocalizedString(
  61. "Low Temp Target Lowers Sensitivity",
  62. comment: "Low Temp Target Lowers Sensitivity"
  63. )
  64. }
  65. ),
  66. units: state.units,
  67. type: .boolean,
  68. label: NSLocalizedString(
  69. "Low Temp Target Lowers Sensitivity",
  70. comment: "Low Temp Target Lowers Sensitivity"
  71. ),
  72. miniHint: "Temp Target < \(state.units == .mgdL ? "100" : 100.formattedAsMmolL) \(state.units.rawValue) decreases sensitivity when glucose is below target.",
  73. verboseHint:
  74. VStack(alignment: .leading, spacing: 10) {
  75. Text("Default: OFF").bold()
  76. Text(
  77. "When this feature is enabled, setting a temporary target below \(state.units == .mgdL ? "100" : 100.formattedAsMmolL) \(state.units.rawValue) will increase the Autosens Ratio used for ISF and basal adjustments, resulting in more insulin delivered overall. This scales with the temporary target set; the lower the Temp Target, the higher the Autosens Ratio used."
  78. )
  79. Text(
  80. "If Half Basal Exercise Target is \(state.units == .mgdL ? "160" : 160.formattedAsMmolL) \(state.units.rawValue), a Temp Target of \(state.units == .mgdL ? "95" : 95.formattedAsMmolL) \(state.units.rawValue) uses an Autosens Ratio of 1.09. A Temp Target of \(state.units == .mgdL ? "85" : 85.formattedAsMmolL) \(state.units.rawValue) uses an Autosens Ratio of 1.33."
  81. )
  82. Text("Note: The effect of this can be adjusted with the Half Basal Exercise Target")
  83. }
  84. )
  85. SettingInputSection(
  86. decimalValue: $decimalPlaceholder,
  87. booleanValue: $state.sensitivityRaisesTarget,
  88. shouldDisplayHint: $shouldDisplayHint,
  89. selectedVerboseHint: Binding(
  90. get: { selectedVerboseHint },
  91. set: {
  92. selectedVerboseHint = $0.map { AnyView($0) }
  93. hintLabel = NSLocalizedString("Sensitivity Raises Target", comment: "Sensitivity Raises Target")
  94. }
  95. ),
  96. units: state.units,
  97. type: .boolean,
  98. label: NSLocalizedString("Sensitivity Raises Target", comment: "Sensitivity Raises Target"),
  99. miniHint: "Automatically raise target glucose if sensitivity is detected.",
  100. verboseHint: VStack(alignment: .leading, spacing: 10) {
  101. Text("Default: OFF").bold()
  102. Text("Automatically increase target glucose if it detects an increase in sensitivity.")
  103. }
  104. )
  105. SettingInputSection(
  106. decimalValue: $decimalPlaceholder,
  107. booleanValue: $state.resistanceLowersTarget,
  108. shouldDisplayHint: $shouldDisplayHint,
  109. selectedVerboseHint: Binding(
  110. get: { selectedVerboseHint },
  111. set: {
  112. selectedVerboseHint = $0.map { AnyView($0) }
  113. hintLabel = NSLocalizedString("Resistance Lowers Target", comment: "Resistance Lowers Target")
  114. }
  115. ),
  116. units: state.units,
  117. type: .boolean,
  118. label: NSLocalizedString("Resistance Lowers Target", comment: "Resistance Lowers Target"),
  119. miniHint: "Automatically lower target glucose if resistance is detected.",
  120. verboseHint: VStack(alignment: .leading, spacing: 10) {
  121. Text("Default: OFF").bold()
  122. Text(
  123. "Enabling this feature causes Trio to automatically reduce the targeted glucose if it detects a decrease in sensitivity (resistance)."
  124. )
  125. }
  126. )
  127. SettingInputSection(
  128. decimalValue: $state.halfBasalExerciseTarget,
  129. booleanValue: $booleanPlaceholder,
  130. shouldDisplayHint: $shouldDisplayHint,
  131. selectedVerboseHint: Binding(
  132. get: { selectedVerboseHint },
  133. set: {
  134. selectedVerboseHint = $0.map { AnyView($0) }
  135. hintLabel = NSLocalizedString("Half Basal Exercise Target", comment: "Half Basal Exercise Target")
  136. }
  137. ),
  138. units: state.units,
  139. type: .decimal("halfBasalExerciseTarget"),
  140. label: NSLocalizedString("Half Basal Exercise Target", comment: "Half Basal Exercise Target"),
  141. miniHint: "Scales down your basal rate to 50% at this value.",
  142. verboseHint:
  143. VStack(alignment: .leading, spacing: 10) {
  144. Text(
  145. "Default: \(state.units == .mgdL ? "160" : 160.formattedAsMmolL) \(state.units.rawValue)"
  146. )
  147. .bold()
  148. Text(
  149. "The Half Basal Exercise Target allows you to scale down your basal insulin during exercise or scale up your basal insulin when eating soon when a temporary glucose target is set."
  150. )
  151. Text(
  152. "For example, at a temp target of \(state.units == .mgdL ? "160" : 160.formattedAsMmolL) \(state.units.rawValue), your basal is reduced to 50%, but this scales depending on the target (e.g., 75% at \(state.units == .mgdL ? "120" : 120.formattedAsMmolL) \(state.units.rawValue), 60% at \(state.units == .mgdL ? "140" : 140.formattedAsMmolL) \(state.units.rawValue))."
  153. )
  154. Text(
  155. "Note: This setting is only utilized if the settings \"Low Temp Target Lowers Sensitivity\" OR \"High Temp Target Raises Sensitivity\" are enabled."
  156. )
  157. }
  158. )
  159. }
  160. .listSectionSpacing(sectionSpacing)
  161. .sheet(isPresented: $shouldDisplayHint) {
  162. SettingInputHintView(
  163. hintDetent: $hintDetent,
  164. shouldDisplayHint: $shouldDisplayHint,
  165. hintLabel: hintLabel ?? "",
  166. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  167. sheetTitle: "Help"
  168. )
  169. }
  170. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  171. .onAppear(perform: configureView)
  172. .navigationTitle("Target Behavior")
  173. .navigationBarTitleDisplayMode(.automatic)
  174. // .onDisappear {
  175. // state.saveIfChanged()
  176. // }
  177. }
  178. }
  179. }