StatConfigRootView.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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(header: Text("Glucose")) {
  26. Toggle("Change HbA1c Unit", isOn: $state.overrideHbA1cUnit)
  27. Toggle("Allow Upload of Statistics to NS", isOn: $state.uploadStats)
  28. HStack {
  29. Text("Low")
  30. Spacer()
  31. DecimalTextField("0", value: $state.low, formatter: glucoseFormatter)
  32. Text(state.units.rawValue).foregroundColor(.secondary)
  33. }
  34. HStack {
  35. Text("High")
  36. Spacer()
  37. DecimalTextField("0", value: $state.high, formatter: glucoseFormatter)
  38. Text(state.units.rawValue).foregroundColor(.secondary)
  39. }
  40. }
  41. }
  42. .onAppear(perform: configureView)
  43. .navigationBarTitle("Statistics")
  44. .navigationBarTitleDisplayMode(.automatic)
  45. }
  46. }
  47. }