AutosensSettingsRootView.swift 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import SwiftUI
  2. import Swinject
  3. extension AutosensSettings {
  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: $state.autosensMax,
  20. booleanValue: $booleanPlaceholder,
  21. shouldDisplayHint: $shouldDisplayHint,
  22. selectedVerboseHint: Binding(
  23. get: { selectedVerboseHint },
  24. set: {
  25. selectedVerboseHint = $0.map { AnyView($0) }
  26. hintLabel = NSLocalizedString("Autosens Max", comment: "Autosens Max")
  27. }
  28. ),
  29. units: state.units,
  30. type: .decimal("autosensMax"),
  31. label: NSLocalizedString("Autosens Max", comment: "Autosens Max"),
  32. miniHint: "The higher limit of the Autosens Ratio.",
  33. verboseHint:
  34. VStack(alignment: .leading, spacing: 10) {
  35. Text("Default: 120%").bold()
  36. Text(
  37. "Autosens Max sets the maximum Autosens Ratio used by Autosens, Dynamic ISF, or Sigmoid Formula."
  38. )
  39. Text(
  40. "The Autosens Ratio is used to calculate the amount of adjustment needed to basal rates, ISF, and CR."
  41. )
  42. Text(
  43. "Tip: Increasing this value allows automatic adjustments of basal rates to be higher, ISF to be lower, and CR to be lower."
  44. )
  45. },
  46. headerText: "Glucose Deviations Algorithm"
  47. )
  48. SettingInputSection(
  49. decimalValue: $state.autosensMin,
  50. booleanValue: $booleanPlaceholder,
  51. shouldDisplayHint: $shouldDisplayHint,
  52. selectedVerboseHint: Binding(
  53. get: { selectedVerboseHint },
  54. set: {
  55. selectedVerboseHint = $0.map { AnyView($0) }
  56. hintLabel = NSLocalizedString("Autosens Min", comment: "Autosens Min")
  57. }
  58. ),
  59. units: state.units,
  60. type: .decimal("autosensMin"),
  61. label: NSLocalizedString("Autosens Min", comment: "Autosens Min"),
  62. miniHint: "The lower limit of the Autosens Ratio.",
  63. verboseHint:
  64. VStack(alignment: .leading, spacing: 10) {
  65. Text("Default: 80%").bold()
  66. Text(
  67. "Autosens Min sets the minimum Autosens Ratio used by Autosens, Dynamic ISF, or Sigmoid Formula."
  68. )
  69. Text(
  70. "The Autosens Ratio is used to calculate the amount of adjustment needed to basal rates, ISF, and CR."
  71. )
  72. Text(
  73. "Tip: Decreasing this value allows automatic adjustments of basal rates to be lower, ISF to be higher, and CR to be higher."
  74. )
  75. }
  76. )
  77. SettingInputSection(
  78. decimalValue: $decimalPlaceholder,
  79. booleanValue: $state.rewindResetsAutosens,
  80. shouldDisplayHint: $shouldDisplayHint,
  81. selectedVerboseHint: Binding(
  82. get: { selectedVerboseHint },
  83. set: {
  84. selectedVerboseHint = $0.map { AnyView($0) }
  85. hintLabel = NSLocalizedString("Rewind Resets Autosens", comment: "Rewind Resets Autosens")
  86. }
  87. ),
  88. units: state.units,
  89. type: .boolean,
  90. label: NSLocalizedString("Rewind Resets Autosens", comment: "Rewind Resets Autosens"),
  91. miniHint: "Pump rewind initiates a reset in Autosens Ratio.",
  92. verboseHint: VStack(alignment: .leading, spacing: 10) {
  93. Text("Default: ON").bold()
  94. Text("Medtronic Users Only").bold()
  95. VStack(alignment: .leading, spacing: 10) {
  96. Text(
  97. "This feature resets the Autosens Ratio to neutral when you rewind your pump on the assumption that this corresponds to a site change."
  98. )
  99. Text(
  100. "Autosens will begin learning sensitivity anew from the time of the rewind, which may take up to 6 hours."
  101. )
  102. Text(
  103. "Tip: If you usually rewind your pump independently of site changes, you may want to consider disabling this feature."
  104. )
  105. }
  106. }
  107. )
  108. }
  109. .listSectionSpacing(sectionSpacing)
  110. .sheet(isPresented: $shouldDisplayHint) {
  111. SettingInputHintView(
  112. hintDetent: $hintDetent,
  113. shouldDisplayHint: $shouldDisplayHint,
  114. hintLabel: hintLabel ?? "",
  115. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  116. sheetTitle: "Help"
  117. )
  118. }
  119. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  120. .onAppear(perform: configureView)
  121. .navigationTitle("Autosens")
  122. .navigationBarTitleDisplayMode(.automatic)
  123. }
  124. }
  125. }