StatConfigRootView.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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("Background_1"),
  12. Color("Background_1"),
  13. Color("Background_2")
  14. // Color("Background_1")
  15. ]),
  16. startPoint: .top,
  17. endPoint: .bottom
  18. )
  19. :
  20. LinearGradient(
  21. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  22. startPoint: .top,
  23. endPoint: .bottom
  24. )
  25. }
  26. private var glucoseFormatter: NumberFormatter {
  27. let formatter = NumberFormatter()
  28. formatter.numberStyle = .decimal
  29. formatter.maximumFractionDigits = 0
  30. if state.units == .mmolL {
  31. formatter.maximumFractionDigits = 1
  32. }
  33. formatter.roundingMode = .halfUp
  34. return formatter
  35. }
  36. private var carbsFormatter: NumberFormatter {
  37. let formatter = NumberFormatter()
  38. formatter.numberStyle = .decimal
  39. formatter.maximumFractionDigits = 0
  40. return formatter
  41. }
  42. var body: some View {
  43. Form {
  44. Section {
  45. Toggle("Display Chart X - Grid lines", isOn: $state.xGridLines)
  46. Toggle("Display Chart Y - Grid lines", isOn: $state.yGridLines)
  47. Toggle("Display Chart Threshold lines for Low and High", isOn: $state.rulerMarks)
  48. Toggle("Standing / Laying TIR Chart", isOn: $state.oneDimensionalGraph)
  49. Toggle("Enable total insulin in scope", isOn: $state.tins)
  50. } header: { Text("Home Chart settings ") }
  51. Section {
  52. HStack {
  53. Text("Low")
  54. Spacer()
  55. DecimalTextField("0", value: $state.low, formatter: glucoseFormatter)
  56. Text(state.units.rawValue).foregroundColor(.secondary)
  57. }
  58. HStack {
  59. Text("High")
  60. Spacer()
  61. DecimalTextField("0", value: $state.high, formatter: glucoseFormatter)
  62. Text(state.units.rawValue).foregroundColor(.secondary)
  63. }
  64. Toggle("Override HbA1c Unit", isOn: $state.overrideHbA1cUnit)
  65. } header: { Text("Statistics settings ") }
  66. Section {
  67. Toggle("Skip Bolus screen after carbs", isOn: $state.skipBolusScreenAfterCarbs)
  68. Toggle("Display and allow Fat and Protein entries", isOn: $state.useFPUconversion)
  69. } header: { Text("Add Meal View settings ") }
  70. Section {
  71. Picker(
  72. selection: $state.historyLayout,
  73. label: Text("History Layout")
  74. ) {
  75. ForEach(HistoryLayout.allCases) { selection in
  76. Text(selection.displayName).tag(selection)
  77. }
  78. }
  79. } header: { Text("History Settings") }
  80. Section {
  81. Picker(
  82. selection: $state.lockScreenView,
  83. label: Text("Lock screen widget")
  84. ) {
  85. ForEach(LockScreenView.allCases) { selection in
  86. Text(selection.displayName).tag(selection)
  87. }
  88. }
  89. } header: { Text("Lock screen widget") }
  90. }
  91. .scrollContentBackground(.hidden).background(color)
  92. .onAppear(perform: configureView)
  93. .navigationBarTitle("UI/UX")
  94. .navigationBarTitleDisplayMode(.automatic)
  95. .navigationBarItems(trailing: Button("Close", action: state.hideModal))
  96. }
  97. }
  98. }