StatConfigRootView.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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("Use Dynamic BG Color", isOn: $state.dynamicGlucoseColor)
  44. Toggle("Display Chart X - Grid lines", isOn: $state.xGridLines)
  45. Toggle("Display Chart Y - Grid lines", isOn: $state.yGridLines)
  46. Toggle("Display Chart Threshold lines for Low and High", isOn: $state.rulerMarks)
  47. Toggle("Standing / Laying TIR Chart", isOn: $state.oneDimensionalGraph)
  48. Toggle("Enable total insulin in scope", isOn: $state.tins)
  49. HStack {
  50. Text("Hours X-Axis (6 default)")
  51. Spacer()
  52. TextFieldWithToolBar(text: $state.hours, placeholder: "6", numberFormatter: carbsFormatter)
  53. Text("hours").foregroundColor(.secondary)
  54. }
  55. Toggle("Show Forecasts as Lines", isOn: $state.displayForecastsAsLines)
  56. } header: { Text("Home Chart settings ") }
  57. Section {
  58. HStack {
  59. Text("Low")
  60. Spacer()
  61. TextFieldWithToolBar(text: $state.low, placeholder: "0", numberFormatter: glucoseFormatter)
  62. Text(state.units.rawValue).foregroundColor(.secondary)
  63. }
  64. HStack {
  65. Text("High")
  66. Spacer()
  67. TextFieldWithToolBar(text: $state.high, placeholder: "0", numberFormatter: glucoseFormatter)
  68. Text(state.units.rawValue).foregroundColor(.secondary)
  69. }
  70. Toggle("Override HbA1c Unit", isOn: $state.overrideHbA1cUnit)
  71. } header: { Text("Statistics settings ") }
  72. Section {
  73. Toggle("Skip Bolus screen after carbs", isOn: $state.skipBolusScreenAfterCarbs)
  74. Toggle("Display and allow Fat and Protein entries", isOn: $state.useFPUconversion)
  75. } header: { Text("Add Meal View settings ") }
  76. Section {
  77. Picker(
  78. selection: $state.historyLayout,
  79. label: Text("History Layout")
  80. ) {
  81. ForEach(HistoryLayout.allCases) { selection in
  82. Text(selection.displayName).tag(selection)
  83. }
  84. }
  85. } header: { Text("History Settings") }
  86. Section {
  87. Picker(
  88. selection: $state.lockScreenView,
  89. label: Text("Lock screen widget")
  90. ) {
  91. ForEach(LockScreenView.allCases) { selection in
  92. Text(selection.displayName).tag(selection)
  93. }
  94. }
  95. } header: { Text("Lock screen widget") }
  96. }
  97. .scrollContentBackground(.hidden).background(color)
  98. .onAppear(perform: configureView)
  99. .navigationBarTitle("UI/UX")
  100. .navigationBarTitleDisplayMode(.automatic)
  101. }
  102. }
  103. }