UserInterfaceSettingsRootView.swift 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import SwiftUI
  2. import Swinject
  3. extension UserInterfaceSettings {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. @Environment(\.colorScheme) var colorScheme
  8. var color: LinearGradient {
  9. colorScheme == .dark ? LinearGradient(
  10. gradient: Gradient(colors: [
  11. Color.bgDarkBlue,
  12. Color.bgDarkerDarkBlue
  13. ]),
  14. startPoint: .top,
  15. endPoint: .bottom
  16. )
  17. :
  18. LinearGradient(
  19. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  20. startPoint: .top,
  21. endPoint: .bottom
  22. )
  23. }
  24. private var glucoseFormatter: NumberFormatter {
  25. let formatter = NumberFormatter()
  26. formatter.numberStyle = .decimal
  27. formatter.maximumFractionDigits = 0
  28. if state.units == .mmolL {
  29. formatter.maximumFractionDigits = 1
  30. }
  31. formatter.roundingMode = .halfUp
  32. return formatter
  33. }
  34. private var carbsFormatter: NumberFormatter {
  35. let formatter = NumberFormatter()
  36. formatter.numberStyle = .decimal
  37. formatter.maximumFractionDigits = 0
  38. return formatter
  39. }
  40. var body: some View {
  41. Form {
  42. Section {
  43. Toggle("Display Chart X - Grid lines", isOn: $state.xGridLines)
  44. Toggle("Display Chart Y - Grid lines", isOn: $state.yGridLines)
  45. Toggle("Display Chart Threshold lines for Low and High", isOn: $state.rulerMarks)
  46. Toggle("Standing / Laying TIR Chart", isOn: $state.oneDimensionalGraph)
  47. Toggle("Enable total insulin in scope", isOn: $state.tins)
  48. HStack {
  49. Text("Hours X-Axis (6 default)")
  50. Spacer()
  51. TextFieldWithToolBar(text: $state.hours, placeholder: "6", numberFormatter: carbsFormatter)
  52. Text("hours").foregroundColor(.secondary)
  53. }
  54. } header: { Text("Home Chart settings ") }
  55. Section {
  56. HStack {
  57. Text("Low")
  58. Spacer()
  59. TextFieldWithToolBar(text: $state.low, placeholder: "0", numberFormatter: glucoseFormatter)
  60. Text(state.units.rawValue).foregroundColor(.secondary)
  61. }
  62. HStack {
  63. Text("High")
  64. Spacer()
  65. TextFieldWithToolBar(text: $state.high, placeholder: "0", numberFormatter: glucoseFormatter)
  66. Text(state.units.rawValue).foregroundColor(.secondary)
  67. }
  68. Toggle("Override HbA1c Unit", isOn: $state.overrideHbA1cUnit)
  69. } header: { Text("Statistics settings ") }
  70. Section(header: Text("Other")) {
  71. HStack {
  72. Text("Carbs Required Threshold")
  73. Spacer()
  74. TextFieldWithToolBar(
  75. text: $state.carbsRequiredThreshold,
  76. placeholder: "0",
  77. numberFormatter: carbsFormatter
  78. )
  79. Text("g").foregroundColor(.secondary)
  80. }
  81. }
  82. }
  83. .scrollContentBackground(.hidden).background(color)
  84. .onAppear(perform: configureView)
  85. .navigationBarTitle("User Interface")
  86. .navigationBarTitleDisplayMode(.automatic)
  87. }
  88. }
  89. }