StatConfigRootView.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. 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 {
  71. Toggle("Display and allow Fat and Protein entries", isOn: $state.useFPUconversion)
  72. } header: { Text("Add Meal View settings ") }
  73. Section {
  74. Picker(
  75. selection: $state.lockScreenView,
  76. label: Text("Lock screen widget")
  77. ) {
  78. ForEach(LockScreenView.allCases) { selection in
  79. Text(selection.displayName).tag(selection)
  80. }
  81. }
  82. } header: { Text("Lock screen widget") }
  83. }
  84. .scrollContentBackground(.hidden).background(color)
  85. .onAppear(perform: configureView)
  86. .navigationBarTitle("UI/UX")
  87. .navigationBarTitleDisplayMode(.automatic)
  88. }
  89. }
  90. }