StatConfigRootView.swift 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import SwiftUI
  2. import Swinject
  3. extension StatConfig {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. private var glucoseFormatter: NumberFormatter {
  8. let formatter = NumberFormatter()
  9. formatter.numberStyle = .decimal
  10. formatter.maximumFractionDigits = 0
  11. if state.units == .mmolL {
  12. formatter.maximumFractionDigits = 1
  13. }
  14. formatter.roundingMode = .halfUp
  15. return formatter
  16. }
  17. private var carbsFormatter: NumberFormatter {
  18. let formatter = NumberFormatter()
  19. formatter.numberStyle = .decimal
  20. formatter.maximumFractionDigits = 0
  21. return formatter
  22. }
  23. var body: some View {
  24. Form {
  25. Section {
  26. Toggle("Change HbA1c Unit", isOn: $state.overrideHbA1cUnit)
  27. Toggle("Display Chart X - Grid lines", isOn: $state.xGridLines)
  28. Toggle("Display Chart Y - Grid lines", isOn: $state.yGridLines)
  29. Toggle("Display Chart Threshold lines for Low and High", isOn: $state.rulerMarks)
  30. HStack {
  31. Text("Hours X-Axis (6 default)")
  32. Spacer()
  33. DecimalTextField("6", value: $state.hours, formatter: carbsFormatter)
  34. Text("hours").foregroundColor(.secondary)
  35. }
  36. } header: { Text("Home Chart Settings") }
  37. Section {
  38. Toggle("Standing / Laying TIR Chart", isOn: $state.oneDimensionalGraph)
  39. HStack {
  40. Text("Low")
  41. Spacer()
  42. DecimalTextField("0", value: $state.low, formatter: glucoseFormatter)
  43. Text(state.units.rawValue).foregroundColor(.secondary)
  44. }
  45. HStack {
  46. Text("High")
  47. Spacer()
  48. DecimalTextField("0", value: $state.high, formatter: glucoseFormatter)
  49. Text(state.units.rawValue).foregroundColor(.secondary)
  50. }
  51. } header: { Text("Statistics") }
  52. Section {
  53. Picker(
  54. selection: $state.lockScreenView,
  55. label: Text("Lock screen widget")
  56. ) {
  57. ForEach(LockScreenView.allCases) { selection in
  58. Text(selection.displayName).tag(selection)
  59. }
  60. }
  61. } header: { Text("Lock screen widget") }
  62. }
  63. .onAppear(perform: configureView)
  64. .navigationBarTitle("UI/UX")
  65. .navigationBarTitleDisplayMode(.automatic)
  66. }
  67. }
  68. }