TargetBehavoirRootView.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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: "Increase sensitivity when glucose is above target if a manual Temp Target > \(state.units == .mgdL ? "110" : 110.formattedAsMmolL) \(state.units.rawValue) is set.",
  39. verboseHint:
  40. VStack(alignment: .leading, spacing: 10) {
  41. Text("Default: OFF").bold()
  42. Text(
  43. "When this feature is enabled, manually 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: "Decrease sensitivity when glucose is below target if a manual Temp Target < \(state.units == .mgdL ? "100" : 100.formattedAsMmolL) \(state.units.rawValue) is set.",
  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: "Raise target glucose if when Autosens Ratio is >1.",
  100. verboseHint: VStack(alignment: .leading, spacing: 10) {
  101. Text("Default: OFF").bold()
  102. Text(
  103. "Enabling this feature causes Trio to automatically raise the targeted glucose if it detects an increase in insulin sensitivity from your baseline."
  104. )
  105. }
  106. )
  107. SettingInputSection(
  108. decimalValue: $decimalPlaceholder,
  109. booleanValue: $state.resistanceLowersTarget,
  110. shouldDisplayHint: $shouldDisplayHint,
  111. selectedVerboseHint: Binding(
  112. get: { selectedVerboseHint },
  113. set: {
  114. selectedVerboseHint = $0.map { AnyView($0) }
  115. hintLabel = NSLocalizedString("Resistance Lowers Target", comment: "Resistance Lowers Target")
  116. }
  117. ),
  118. units: state.units,
  119. type: .boolean,
  120. label: NSLocalizedString("Resistance Lowers Target", comment: "Resistance Lowers Target"),
  121. miniHint: "Lower target glucose when Autosens Ratio is <1.",
  122. verboseHint: VStack(alignment: .leading, spacing: 10) {
  123. Text("Default: OFF").bold()
  124. Text(
  125. "Enabling this feature causes Trio to automatically reduce the targeted glucose if it detects a decrease in sensitivity (resistance) from your baseline."
  126. )
  127. }
  128. )
  129. SettingInputSection(
  130. decimalValue: $state.halfBasalExerciseTarget,
  131. booleanValue: $booleanPlaceholder,
  132. shouldDisplayHint: $shouldDisplayHint,
  133. selectedVerboseHint: Binding(
  134. get: { selectedVerboseHint },
  135. set: {
  136. selectedVerboseHint = $0.map { AnyView($0) }
  137. hintLabel = NSLocalizedString("Half Basal Exercise Target", comment: "Half Basal Exercise Target")
  138. }
  139. ),
  140. units: state.units,
  141. type: .decimal("halfBasalExerciseTarget"),
  142. label: NSLocalizedString("Half Basal Exercise Target", comment: "Half Basal Exercise Target"),
  143. miniHint: "Scales down your basal rate to 50% at this value.",
  144. verboseHint:
  145. VStack(alignment: .leading, spacing: 10) {
  146. Text(
  147. "Default: \(state.units == .mgdL ? "160" : 160.formattedAsMmolL) \(state.units.rawValue)"
  148. )
  149. .bold()
  150. Text(
  151. "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."
  152. )
  153. Text(
  154. "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))."
  155. )
  156. Text(
  157. "Note: This setting is only utilized if the settings \"Low Temp Target Lowers Sensitivity\" OR \"High Temp Target Raises Sensitivity\" are enabled."
  158. )
  159. }
  160. )
  161. }
  162. .listSectionSpacing(sectionSpacing)
  163. .sheet(isPresented: $shouldDisplayHint) {
  164. SettingInputHintView(
  165. hintDetent: $hintDetent,
  166. shouldDisplayHint: $shouldDisplayHint,
  167. hintLabel: hintLabel ?? "",
  168. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  169. sheetTitle: "Help"
  170. )
  171. }
  172. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  173. .onAppear(perform: configureView)
  174. .navigationTitle("Target Behavior")
  175. .navigationBarTitleDisplayMode(.automatic)
  176. // .onDisappear {
  177. // state.saveIfChanged()
  178. // }
  179. }
  180. }
  181. }