StatConfigRootView.swift 4.5 KB

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