NotificationsConfigRootView.swift 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import SwiftUI
  2. import Swinject
  3. extension NotificationsConfig {
  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("Show glucose on the app badge", isOn: $state.glucoseBadge)
  27. Toggle("Hide glucose badge when older than 20 minutes", isOn: $state.tooOldGlucose)
  28. Toggle("Always Notify Glucose", isOn: $state.glucoseNotificationsAlways)
  29. Toggle("Also play alert sound", isOn: $state.useAlarmSound)
  30. Toggle("Also add source info", isOn: $state.addSourceInfoToGlucoseNotifications)
  31. HStack {
  32. Text("Low")
  33. Spacer()
  34. DecimalTextField("0", value: $state.lowGlucose, formatter: glucoseFormatter)
  35. Text(state.units.rawValue).foregroundColor(.secondary)
  36. }
  37. HStack {
  38. Text("High")
  39. Spacer()
  40. DecimalTextField("0", value: $state.highGlucose, formatter: glucoseFormatter)
  41. Text(state.units.rawValue).foregroundColor(.secondary)
  42. }
  43. }
  44. Section(header: Text("Other")) {
  45. HStack {
  46. Text("Carbs Required Threshold")
  47. Spacer()
  48. DecimalTextField("0", value: $state.carbsRequiredThreshold, formatter: carbsFormatter)
  49. Text("g").foregroundColor(.secondary)
  50. }
  51. }
  52. }
  53. .onAppear(perform: configureView)
  54. .navigationBarTitle("Notifications")
  55. .navigationBarTitleDisplayMode(.automatic)
  56. }
  57. }
  58. }