StatConfigRootView.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import SwiftUI
  2. import Swinject
  3. extension StatConfig {
  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. } header: { Text("Home Chart settings ") }
  49. <<<<<<< HEAD
  50. Section {
  51. =======
  52. HStack {
  53. Text("Hours X-Axis (6 default)")
  54. Spacer()
  55. TextFieldWithToolBar(text: $state.hours, placeholder: "6", numberFormatter: carbsFormatter)
  56. Text("hours").foregroundColor(.secondary)
  57. }
  58. >>>>>>> 9672da256c317a314acc76d6e4f6e82cc174d133
  59. HStack {
  60. Text("Low")
  61. Spacer()
  62. TextFieldWithToolBar(text: $state.low, placeholder: "0", numberFormatter: glucoseFormatter)
  63. Text(state.units.rawValue).foregroundColor(.secondary)
  64. }
  65. HStack {
  66. Text("High")
  67. Spacer()
  68. TextFieldWithToolBar(text: $state.high, placeholder: "0", numberFormatter: glucoseFormatter)
  69. Text(state.units.rawValue).foregroundColor(.secondary)
  70. }
  71. Toggle("Override HbA1c Unit", isOn: $state.overrideHbA1cUnit)
  72. } header: { Text("Statistics settings ") }
  73. Section {
  74. Toggle("Skip Bolus screen after carbs", isOn: $state.skipBolusScreenAfterCarbs)
  75. Toggle("Display and allow Fat and Protein entries", isOn: $state.useFPUconversion)
  76. } header: { Text("Add Meal View settings ") }
  77. Section {
  78. Picker(
  79. selection: $state.historyLayout,
  80. label: Text("History Layout")
  81. ) {
  82. ForEach(HistoryLayout.allCases) { selection in
  83. Text(selection.displayName).tag(selection)
  84. }
  85. }
  86. } header: { Text("History Settings") }
  87. Section {
  88. Picker(
  89. selection: $state.lockScreenView,
  90. label: Text("Lock screen widget")
  91. ) {
  92. ForEach(LockScreenView.allCases) { selection in
  93. Text(selection.displayName).tag(selection)
  94. }
  95. }
  96. } header: { Text("Lock screen widget") }
  97. }
  98. .scrollContentBackground(.hidden).background(color)
  99. .onAppear(perform: configureView)
  100. .navigationBarTitle("UI/UX")
  101. .navigationBarTitleDisplayMode(.automatic)
  102. }
  103. }
  104. }