AutosensSettingsRootView.swift 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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: String?
  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
  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: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  33. verboseHint: NSLocalizedString(
  34. "This is a multiplier cap for autosens (and autotune) to set a 20% max limit on how high the autosens ratio can be, which in turn determines how high autosens can adjust basals, how low it can adjust ISF, and how low it can set the BG target.",
  35. comment: "Autosens Max"
  36. ),
  37. headerText: "Glucose Deviations Algorithm"
  38. )
  39. SettingInputSection(
  40. decimalValue: $state.autosensMin,
  41. booleanValue: $booleanPlaceholder,
  42. shouldDisplayHint: $shouldDisplayHint,
  43. selectedVerboseHint: Binding(
  44. get: { selectedVerboseHint },
  45. set: {
  46. selectedVerboseHint = $0
  47. hintLabel = NSLocalizedString("Autosens Min", comment: "Autosens Min")
  48. }
  49. ),
  50. units: state.units,
  51. type: .decimal("autosensMin"),
  52. label: NSLocalizedString("Autosens Min", comment: "Autosens Min"),
  53. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  54. verboseHint: NSLocalizedString(
  55. "The other side of the autosens safety limits, putting a cap on how low autosens can adjust basals, and how high it can adjust ISF and BG targets.",
  56. comment: "Autosens Min"
  57. )
  58. )
  59. SettingInputSection(
  60. decimalValue: $decimalPlaceholder,
  61. booleanValue: $state.rewindResetsAutosens,
  62. shouldDisplayHint: $shouldDisplayHint,
  63. selectedVerboseHint: Binding(
  64. get: { selectedVerboseHint },
  65. set: {
  66. selectedVerboseHint = $0
  67. hintLabel = NSLocalizedString("Rewind Resets Autosens", comment: "Rewind Resets Autosens")
  68. }
  69. ),
  70. units: state.units,
  71. type: .boolean,
  72. label: NSLocalizedString("Rewind Resets Autosens", comment: "Rewind Resets Autosens"),
  73. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  74. verboseHint: NSLocalizedString(
  75. "This feature, enabled by default, resets the autosens ratio to neutral when you rewind your pump, on the assumption that this corresponds to a probable site change. Autosens will begin learning sensitivity anew from the time of the rewind, which may take up to 6 hours. If you usually rewind your pump independently of site changes, you may want to consider disabling this feature.",
  76. comment: "Rewind Resets Autosens"
  77. )
  78. )
  79. }
  80. .sheet(isPresented: $shouldDisplayHint) {
  81. SettingInputHintView(
  82. hintDetent: $hintDetent,
  83. shouldDisplayHint: $shouldDisplayHint,
  84. hintLabel: hintLabel ?? "",
  85. hintText: selectedVerboseHint ?? "",
  86. sheetTitle: "Help"
  87. )
  88. }
  89. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  90. .onAppear(perform: configureView)
  91. .navigationTitle("Autosens")
  92. .navigationBarTitleDisplayMode(.automatic)
  93. }
  94. }
  95. }