NotificationsConfigRootView.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. var body: some View {
  18. Form {
  19. Section(header: Text("Glucose")) {
  20. Toggle("Show glucose on the app badge", isOn: $state.glucoseBadge)
  21. Toggle("Always Notify Glucose", isOn: $state.glucoseNotificationsAlways)
  22. Toggle("Also play alert sound", isOn: $state.useAlarmSound)
  23. Toggle("Also add source info", isOn: $state.addSourceInfoToGlucoseNotifications)
  24. HStack {
  25. Text("Low")
  26. Spacer()
  27. DecimalTextField("0", value: $state.lowGlucose, formatter: glucoseFormatter)
  28. Text(state.units.rawValue).foregroundColor(.secondary)
  29. }
  30. HStack {
  31. Text("High")
  32. Spacer()
  33. DecimalTextField("0", value: $state.highGlucose, formatter: glucoseFormatter)
  34. Text(state.units.rawValue).foregroundColor(.secondary)
  35. }
  36. }
  37. }
  38. .onAppear(perform: configureView)
  39. .navigationBarTitle("Notifications")
  40. .navigationBarTitleDisplayMode(.automatic)
  41. }
  42. }
  43. }