NotificationsConfigRootView.swift 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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("Always Notify Glucose", isOn: $state.glucoseNotificationsAlways)
  28. Toggle("Also play alert sound", isOn: $state.useAlarmSound)
  29. Toggle("Also add source info", isOn: $state.addSourceInfoToGlucoseNotifications)
  30. HStack {
  31. Text("Low")
  32. Spacer()
  33. DecimalTextField("0", value: $state.lowGlucose, formatter: glucoseFormatter)
  34. Text(state.units.rawValue).foregroundColor(.secondary)
  35. }
  36. HStack {
  37. Text("High")
  38. Spacer()
  39. DecimalTextField("0", value: $state.highGlucose, formatter: glucoseFormatter)
  40. Text(state.units.rawValue).foregroundColor(.secondary)
  41. }
  42. }
  43. Section(header: Text("Other")) {
  44. HStack {
  45. Text("Carbs Required Threshold")
  46. Spacer()
  47. DecimalTextField("0", value: $state.carbsRequiredThreshold, formatter: carbsFormatter)
  48. Text("g").foregroundColor(.secondary)
  49. }
  50. }
  51. if #available(iOS 16.2, *) {
  52. Section(
  53. header: Text("Live Activity"),
  54. footer: Text(
  55. "Live activity displays blood glucose live on the lock screen and on the dynamic island (if available)"
  56. )
  57. ) {
  58. Toggle("Show live activity", isOn: $state.useLiveActivity)
  59. Picker(
  60. selection: $state.lockScreenView,
  61. label: Text("Lock screen widget")
  62. ) {
  63. ForEach(LockScreenView.allCases) { selection in
  64. Text(selection.displayName).tag(selection)
  65. }
  66. }
  67. }
  68. }
  69. }
  70. .onAppear(perform: configureView)
  71. .navigationBarTitle("Notifications")
  72. .navigationBarTitleDisplayMode(.automatic)
  73. }
  74. }
  75. }