SMBSettingsView.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import HealthKit
  2. import LoopKit
  3. import LoopKitUI
  4. import SwiftUI
  5. import Swinject
  6. extension SMBSettings {
  7. struct RootView: BaseView {
  8. let resolver: Resolver
  9. @StateObject var state = StateModel()
  10. @State private var showHint: Bool = false
  11. @State var hintDetent = PresentationDetent.large
  12. @State var selectedVerboseHint: String?
  13. @State var hintLabel: String?
  14. @State private var decimalPlaceholder: Decimal = 0.0
  15. @State private var booleanPlaceholder: Bool = false
  16. @Environment(\.colorScheme) var colorScheme
  17. @EnvironmentObject var appIcons: Icons
  18. private var color: LinearGradient {
  19. colorScheme == .dark ? LinearGradient(
  20. gradient: Gradient(colors: [
  21. Color.bgDarkBlue,
  22. Color.bgDarkerDarkBlue
  23. ]),
  24. startPoint: .top,
  25. endPoint: .bottom
  26. )
  27. :
  28. LinearGradient(
  29. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  30. startPoint: .top,
  31. endPoint: .bottom
  32. )
  33. }
  34. private var formatter: NumberFormatter {
  35. let formatter = NumberFormatter()
  36. formatter.numberStyle = .decimal
  37. return formatter
  38. }
  39. var body: some View {
  40. List {
  41. SettingInputSection(
  42. decimalValue: $decimalPlaceholder,
  43. booleanValue: $state.enableSMBAlways,
  44. showHint: $showHint,
  45. selectedVerboseHint: Binding(
  46. get: { selectedVerboseHint },
  47. set: {
  48. selectedVerboseHint = $0
  49. hintLabel = NSLocalizedString("Enable SMB Always", comment: "Enable SMB Always")
  50. }
  51. ),
  52. type: .boolean,
  53. label: NSLocalizedString("Enable SMB Always", comment: "Enable SMB Always"),
  54. shortHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  55. verboseHint: "Enable SMB always bla bla bla",
  56. headerText: "Super-Micro-Bolus",
  57. footerText: nil
  58. )
  59. if state.enableSMBAlways {
  60. SettingInputSection(
  61. decimalValue: $state.maxDeltaBGthreshold,
  62. booleanValue: $booleanPlaceholder,
  63. showHint: $showHint,
  64. selectedVerboseHint: Binding(
  65. get: { selectedVerboseHint },
  66. set: {
  67. selectedVerboseHint = $0
  68. hintLabel = NSLocalizedString("Max Delta-BG Threshold SMB", comment: "Max Delta-BG Threshold")
  69. }
  70. ),
  71. type: .decimal,
  72. label: NSLocalizedString("Max Delta-BG Threshold SMB", comment: "Max Delta-BG Threshold"),
  73. shortHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  74. verboseHint: "Max Delta BG bla bla bla",
  75. headerText: nil,
  76. footerText: nil
  77. )
  78. SettingInputSection(
  79. decimalValue: $decimalPlaceholder,
  80. booleanValue: $state.enableSMBWithCOB,
  81. showHint: $showHint,
  82. selectedVerboseHint: Binding(
  83. get: { selectedVerboseHint },
  84. set: {
  85. selectedVerboseHint = $0
  86. hintLabel = NSLocalizedString("Enable SMB With COB", comment: "Enable SMB With COB")
  87. }
  88. ),
  89. type: .boolean,
  90. label: NSLocalizedString("Enable SMB With COB", comment: "Enable SMB With COB"),
  91. shortHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  92. verboseHint: "Enable SMB for COB bla bla bla bla",
  93. headerText: nil,
  94. footerText: nil
  95. )
  96. }
  97. }
  98. .sheet(isPresented: $showHint) {
  99. SettingInputHintView(
  100. hintDetent: $hintDetent,
  101. showHint: $showHint,
  102. hintLabel: hintLabel ?? "",
  103. hintText: selectedVerboseHint ?? "",
  104. sheetTitle: "Hint"
  105. )
  106. }
  107. .scrollContentBackground(.hidden).background(color)
  108. .navigationTitle("SMB Settings")
  109. .navigationBarTitleDisplayMode(.automatic)
  110. // .onDisappear {
  111. // state.saveIfChanged()
  112. // }
  113. }
  114. }
  115. }