TargetBehavoirRootView.swift 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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: """
  54. A Temp Target above 110 mg/dL increases sensitivity when glucose is above target
  55. Default: OFF
  56. """,
  57. verboseHint: VStack {
  58. Text("Exercise Mode").bold().italic()
  59. Text("Default: OFF").bold()
  60. Text("""
  61. 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.
  62. 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.
  63. """)
  64. Text("The effect of this can be adjusted with the Half Basal Exercise Target").italic()
  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: """
  89. A Temp Target below 100 mg/dL decreases sensitivity when glucose is below target
  90. Default setting: OFF
  91. """,
  92. verboseHint: VStack {
  93. Text("Eating Soon Mode").bold().italic()
  94. Text("Default: OFF").bold()
  95. Text("""
  96. 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.
  97. 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.
  98. """)
  99. Text("The effect of this can be adjusted with the Half Basal Exercise Target").italic()
  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: """
  117. Trio will automatically raise your target glucose with increased sensitivity
  118. Default: OFF
  119. """,
  120. verboseHint: VStack {
  121. Text("Default: OFF").bold()
  122. Text("""
  123. Enabling this feature causes Trio to automatically increase the targeted glucose if it detects an increase in sensitivity.
  124. """)
  125. }
  126. )
  127. SettingInputSection(
  128. decimalValue: $decimalPlaceholder,
  129. booleanValue: $state.resistanceLowersTarget,
  130. shouldDisplayHint: $shouldDisplayHint,
  131. selectedVerboseHint: Binding(
  132. get: { selectedVerboseHint },
  133. set: {
  134. selectedVerboseHint = $0.map { AnyView($0) }
  135. hintLabel = NSLocalizedString("Resistance Lowers Target", comment: "Resistance Lowers Target")
  136. }
  137. ),
  138. units: state.units,
  139. type: .boolean,
  140. label: NSLocalizedString("Resistance Lowers Target", comment: "Resistance Lowers Target"),
  141. miniHint: """
  142. Trio will automatically lower your target glucose when it detects resistance
  143. Default: OFF
  144. """,
  145. verboseHint: VStack {
  146. Text("Default: OFF").bold()
  147. Text("""
  148. Enabling this feature causes Trio to automatically reduce the targeted glucose if it detects a decrease in sensitivity (resistance).
  149. """)
  150. }
  151. )
  152. SettingInputSection(
  153. decimalValue: $state.halfBasalExerciseTarget,
  154. booleanValue: $booleanPlaceholder,
  155. shouldDisplayHint: $shouldDisplayHint,
  156. selectedVerboseHint: Binding(
  157. get: { selectedVerboseHint },
  158. set: {
  159. selectedVerboseHint = $0.map { AnyView($0) }
  160. hintLabel = NSLocalizedString("Half Basal Exercise Target", comment: "Half Basal Exercise Target")
  161. }
  162. ),
  163. units: state.units,
  164. type: .decimal("halfBasalExerciseTarget"),
  165. label: NSLocalizedString("Half Basal Exercise Target", comment: "Half Basal Exercise Target"),
  166. miniHint: """
  167. Sets your current basal rate to 50% when a temp target is set to this number (in mg/dL)
  168. Default: 160 mg/dL
  169. """,
  170. verboseHint: VStack {
  171. Text("Default: 160 mg/dL").bold()
  172. Text("""
  173. 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. 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).
  174. """)
  175. Text("""
  176. This setting is only utilized if the settings "Low Temp Target Lowers Sensitivity" OR "High Temp Target Raises Sensitivity" are enabled.
  177. """).italic()
  178. }
  179. )
  180. }
  181. .sheet(isPresented: $shouldDisplayHint) {
  182. SettingInputHintView(
  183. hintDetent: $hintDetent,
  184. shouldDisplayHint: $shouldDisplayHint,
  185. hintLabel: hintLabel ?? "",
  186. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  187. sheetTitle: "Help"
  188. )
  189. }
  190. .scrollContentBackground(.hidden).background(color)
  191. .onAppear(perform: configureView)
  192. .navigationTitle("Target Behavior")
  193. .navigationBarTitleDisplayMode(.automatic)
  194. .onDisappear {
  195. state.saveIfChanged()
  196. }
  197. }
  198. }
  199. }