UnitsLimitsSettingsRootView.swift 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import SwiftUI
  2. import Swinject
  3. extension UnitsLimitsSettings {
  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. Section(
  19. header: Text("Trio Core Setup"),
  20. content: {
  21. Picker("Glucose Units", selection: $state.unitsIndex) {
  22. Text("mg/dL").tag(0)
  23. Text("mmol/L").tag(1)
  24. }
  25. }
  26. ).listRowBackground(Color.chart)
  27. SettingInputSection(
  28. decimalValue: $state.maxIOB,
  29. booleanValue: $booleanPlaceholder,
  30. shouldDisplayHint: $shouldDisplayHint,
  31. selectedVerboseHint: Binding(
  32. get: { selectedVerboseHint },
  33. set: {
  34. selectedVerboseHint = $0
  35. hintLabel = NSLocalizedString("Max IOB", comment: "Max IOB")
  36. }
  37. ),
  38. units: state.units,
  39. type: .decimal("maxIOB"),
  40. label: NSLocalizedString("Max IOB", comment: "Max IOB"),
  41. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  42. verboseHint: NSLocalizedString(
  43. "Max IOB is the maximum amount of insulin on board from all sources – both basal (or SMB correction) and bolus insulin – that your loop is allowed to accumulate to treat higher-than-target BG. Unlike the other two OpenAPS safety settings (max_daily_safety_multiplier and current_basal_safety_multiplier), max_iob is set as a fixed number of units of insulin. As of now manual boluses are NOT limited by this setting. \n\n To test your basal rates during nighttime, you can modify the Max IOB setting to zero while in Closed Loop. This will enable low glucose suspend mode while testing your basal rates settings.",
  44. comment: "Max IOB"
  45. )
  46. )
  47. SettingInputSection(
  48. decimalValue: $state.maxBolus,
  49. booleanValue: $booleanPlaceholder,
  50. shouldDisplayHint: $shouldDisplayHint,
  51. selectedVerboseHint: Binding(
  52. get: { selectedVerboseHint },
  53. set: {
  54. selectedVerboseHint = $0
  55. hintLabel = "Max Bolus"
  56. }
  57. ),
  58. units: state.units,
  59. type: .decimal("maxBolus"),
  60. label: "Max Bolus",
  61. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  62. verboseHint: "Max Bolus… bla bla bla"
  63. )
  64. SettingInputSection(
  65. decimalValue: $state.maxBasal,
  66. booleanValue: $booleanPlaceholder,
  67. shouldDisplayHint: $shouldDisplayHint,
  68. selectedVerboseHint: Binding(
  69. get: { selectedVerboseHint },
  70. set: {
  71. selectedVerboseHint = $0
  72. hintLabel = "Max Basal"
  73. }
  74. ),
  75. units: state.units,
  76. type: .decimal("maxBasal"),
  77. label: "Max Basal",
  78. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  79. verboseHint: "Max Basal… bla bla bla"
  80. )
  81. SettingInputSection(
  82. decimalValue: $state.maxCOB,
  83. booleanValue: $booleanPlaceholder,
  84. shouldDisplayHint: $shouldDisplayHint,
  85. selectedVerboseHint: Binding(
  86. get: { selectedVerboseHint },
  87. set: {
  88. selectedVerboseHint = $0
  89. hintLabel = NSLocalizedString("Max COB", comment: "Max COB")
  90. }
  91. ),
  92. units: state.units,
  93. type: .decimal("maxCOB"),
  94. label: NSLocalizedString("Max COB", comment: "Max COB"),
  95. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  96. verboseHint: NSLocalizedString(
  97. "The default of maxCOB is 120. (If someone enters more carbs in one or multiple entries, Trio will cap COB to maxCOB and keep it at maxCOB until the carbs entered above maxCOB have shown to be absorbed. Essentially, this just limits UAM as a safety cap against weird COB calculations due to fluky data.)",
  98. comment: "Max COB"
  99. )
  100. )
  101. }
  102. .sheet(isPresented: $shouldDisplayHint) {
  103. SettingInputHintView(
  104. hintDetent: $hintDetent,
  105. shouldDisplayHint: $shouldDisplayHint,
  106. hintLabel: hintLabel ?? "",
  107. hintText: selectedVerboseHint ?? "",
  108. sheetTitle: "Help"
  109. )
  110. }
  111. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  112. .onAppear(perform: configureView)
  113. .navigationTitle("General")
  114. .navigationBarTitleDisplayMode(.automatic)
  115. .onDisappear {
  116. state.saveIfChanged()
  117. }
  118. }
  119. }
  120. }