TargetBehavoirRootView.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 = String(
  27. localized:
  28. "High Temp Target Raises Sensitivity",
  29. comment: "High Temp Target Raises Sensitivity"
  30. )
  31. }
  32. ),
  33. units: state.units,
  34. type: .boolean,
  35. label: String(
  36. localized:
  37. "High Temp Target Raises Sensitivity",
  38. comment: "High Temp Target Raises Sensitivity"
  39. ),
  40. miniHint: "Increase sensitivity when glucose is above target if a manual Temp Target > \(state.units == .mgdL ? "110" : 110.formattedAsMmolL) \(state.units.rawValue) is set.",
  41. verboseHint:
  42. VStack(alignment: .leading, spacing: 10) {
  43. Text("Default: OFF").bold()
  44. Text(
  45. "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."
  46. )
  47. Text(
  48. "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."
  49. )
  50. Text("Note: The effect of this can be adjusted with the Half Basal Exercise Target")
  51. },
  52. headerText: String(localized: "Algorithmic Target Settings")
  53. )
  54. SettingInputSection(
  55. decimalValue: $decimalPlaceholder,
  56. booleanValue: $state.lowTemptargetLowersSensitivity,
  57. shouldDisplayHint: $shouldDisplayHint,
  58. selectedVerboseHint: Binding(
  59. get: { selectedVerboseHint },
  60. set: {
  61. selectedVerboseHint = $0.map { AnyView($0) }
  62. hintLabel = String(
  63. localized:
  64. "Low Temp Target Lowers Sensitivity",
  65. comment: "Low Temp Target Lowers Sensitivity"
  66. )
  67. }
  68. ),
  69. units: state.units,
  70. type: .boolean,
  71. label: String(
  72. localized:
  73. "Low Temp Target Lowers Sensitivity",
  74. comment: "Low Temp Target Lowers Sensitivity"
  75. ),
  76. miniHint: "Decrease sensitivity when glucose is below target if a manual Temp Target < \(state.units == .mgdL ? "100" : 100.formattedAsMmolL) \(state.units.rawValue) is set.",
  77. verboseHint:
  78. VStack(alignment: .leading, spacing: 10) {
  79. Text("Default: OFF").bold()
  80. Text(
  81. "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."
  82. )
  83. Text(
  84. "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."
  85. )
  86. Text("Note: The effect of this can be adjusted with the Half Basal Exercise Target")
  87. }
  88. )
  89. SettingInputSection(
  90. decimalValue: $decimalPlaceholder,
  91. booleanValue: $state.sensitivityRaisesTarget,
  92. shouldDisplayHint: $shouldDisplayHint,
  93. selectedVerboseHint: Binding(
  94. get: { selectedVerboseHint },
  95. set: {
  96. selectedVerboseHint = $0.map { AnyView($0) }
  97. hintLabel = String(localized: "Sensitivity Raises Target", comment: "Sensitivity Raises Target")
  98. }
  99. ),
  100. units: state.units,
  101. type: .boolean,
  102. label: String(localized: "Sensitivity Raises Target", comment: "Sensitivity Raises Target"),
  103. miniHint: "Raise target glucose if when Autosens Ratio is >1.",
  104. verboseHint: VStack(alignment: .leading, spacing: 10) {
  105. Text("Default: OFF").bold()
  106. Text(
  107. "Enabling this feature causes Trio to automatically raise the targeted glucose if it detects an increase in insulin sensitivity from your baseline."
  108. )
  109. }
  110. )
  111. SettingInputSection(
  112. decimalValue: $decimalPlaceholder,
  113. booleanValue: $state.resistanceLowersTarget,
  114. shouldDisplayHint: $shouldDisplayHint,
  115. selectedVerboseHint: Binding(
  116. get: { selectedVerboseHint },
  117. set: {
  118. selectedVerboseHint = $0.map { AnyView($0) }
  119. hintLabel = String(localized: "Resistance Lowers Target", comment: "Resistance Lowers Target")
  120. }
  121. ),
  122. units: state.units,
  123. type: .boolean,
  124. label: String(localized: "Resistance Lowers Target", comment: "Resistance Lowers Target"),
  125. miniHint: "Lower target glucose when Autosens Ratio is <1.",
  126. verboseHint: VStack(alignment: .leading, spacing: 10) {
  127. Text("Default: OFF").bold()
  128. Text(
  129. "Enabling this feature causes Trio to automatically reduce the targeted glucose if it detects a decrease in sensitivity (resistance) from your baseline."
  130. )
  131. }
  132. )
  133. SettingInputSection(
  134. decimalValue: $state.halfBasalExerciseTarget,
  135. booleanValue: $booleanPlaceholder,
  136. shouldDisplayHint: $shouldDisplayHint,
  137. selectedVerboseHint: Binding(
  138. get: { selectedVerboseHint },
  139. set: {
  140. selectedVerboseHint = $0.map { AnyView($0) }
  141. hintLabel = String(localized: "Half Basal Exercise Target", comment: "Half Basal Exercise Target")
  142. }
  143. ),
  144. units: state.units,
  145. type: .decimal("halfBasalExerciseTarget"),
  146. label: String(localized: "Half Basal Exercise Target", comment: "Half Basal Exercise Target"),
  147. miniHint: "Scales down your basal rate to 50% at this value.",
  148. verboseHint:
  149. VStack(alignment: .leading, spacing: 10) {
  150. Text(
  151. "Default: \(state.units == .mgdL ? "160" : 160.formattedAsMmolL) \(state.units.rawValue)"
  152. )
  153. .bold()
  154. Text(
  155. "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."
  156. )
  157. Text(
  158. "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))."
  159. )
  160. Text(
  161. "Note: This setting is only utilized if the settings \"Low Temp Target Lowers Sensitivity\" OR \"High Temp Target Raises Sensitivity\" are enabled."
  162. )
  163. }
  164. )
  165. }
  166. .listSectionSpacing(sectionSpacing)
  167. .sheet(isPresented: $shouldDisplayHint) {
  168. SettingInputHintView(
  169. hintDetent: $hintDetent,
  170. shouldDisplayHint: $shouldDisplayHint,
  171. hintLabel: hintLabel ?? "",
  172. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  173. sheetTitle: String(localized: "Help", comment: "Help sheet title")
  174. )
  175. }
  176. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  177. .onAppear(perform: configureView)
  178. .navigationTitle("Target Behavior")
  179. .navigationBarTitleDisplayMode(.automatic)
  180. // .onDisappear {
  181. // state.saveIfChanged()
  182. // }
  183. }
  184. }
  185. }