StatConfigRootView.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. Section {
  50. HStack {
  51. Text("Low")
  52. Spacer()
  53. DecimalTextField("0", value: $state.low, formatter: glucoseFormatter)
  54. Text(state.units.rawValue).foregroundColor(.secondary)
  55. }
  56. HStack {
  57. Text("High")
  58. Spacer()
  59. DecimalTextField("0", value: $state.high, formatter: glucoseFormatter)
  60. Text(state.units.rawValue).foregroundColor(.secondary)
  61. }
  62. Toggle("Override HbA1c Unit", isOn: $state.overrideHbA1cUnit)
  63. } header: { Text("Statistics settings ") }
  64. Section {
  65. Toggle("Skip Bolus screen after carbs", isOn: $state.skipBolusScreenAfterCarbs)
  66. Toggle("Display and allow Fat and Protein entries", isOn: $state.useFPUconversion)
  67. } header: { Text("Add Meal View settings ") }
  68. Section {
  69. Picker(
  70. selection: $state.historyLayout,
  71. label: Text("History Layout")
  72. ) {
  73. ForEach(HistoryLayout.allCases) { selection in
  74. Text(selection.displayName).tag(selection)
  75. }
  76. }
  77. } header: { Text("History Settings") }
  78. Section {
  79. Picker(
  80. selection: $state.lockScreenView,
  81. label: Text("Lock screen widget")
  82. ) {
  83. ForEach(LockScreenView.allCases) { selection in
  84. Text(selection.displayName).tag(selection)
  85. }
  86. }
  87. } header: { Text("Lock screen widget") }
  88. }
  89. .scrollContentBackground(.hidden).background(color)
  90. .onAppear(perform: configureView)
  91. .navigationBarTitle("UI/UX")
  92. .navigationBarTitleDisplayMode(.automatic)
  93. }
  94. }
  95. }