TargetBehavoirRootView.swift 10 KB

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