NotificationsConfigRootView.swift 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. @Environment(\.colorScheme) var colorScheme
  24. var color: LinearGradient {
  25. colorScheme == .dark ? LinearGradient(
  26. gradient: Gradient(colors: [
  27. Color("Background_1"),
  28. Color("Background_1"),
  29. Color("Background_2")
  30. // Color("Background_1")
  31. ]),
  32. startPoint: .top,
  33. endPoint: .bottom
  34. )
  35. :
  36. LinearGradient(
  37. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  38. startPoint: .top,
  39. endPoint: .bottom
  40. )
  41. }
  42. var body: some View {
  43. Form {
  44. Section(header: Text("Glucose")) {
  45. Toggle("Show glucose on the app badge", isOn: $state.glucoseBadge)
  46. Toggle("Always Notify Glucose", isOn: $state.glucoseNotificationsAlways)
  47. Toggle("Also play alert sound", isOn: $state.useAlarmSound)
  48. Toggle("Also add source info", isOn: $state.addSourceInfoToGlucoseNotifications)
  49. HStack {
  50. Text("Low")
  51. Spacer()
  52. DecimalTextField("0", value: $state.lowGlucose, formatter: glucoseFormatter)
  53. Text(state.units.rawValue).foregroundColor(.secondary)
  54. }
  55. HStack {
  56. Text("High")
  57. Spacer()
  58. DecimalTextField("0", value: $state.highGlucose, formatter: glucoseFormatter)
  59. Text(state.units.rawValue).foregroundColor(.secondary)
  60. }
  61. }
  62. Section(header: Text("Other")) {
  63. HStack {
  64. Text("Carbs Required Threshold")
  65. Spacer()
  66. DecimalTextField("0", value: $state.carbsRequiredThreshold, formatter: carbsFormatter)
  67. Text("g").foregroundColor(.secondary)
  68. }
  69. }
  70. if #available(iOS 16.2, *) {
  71. Section(
  72. header: Text("Live Activity"),
  73. footer: Text(
  74. "Live activity displays blood glucose live on the lock screen and on the dynamic island (if available)"
  75. )
  76. ) {
  77. Toggle("Show live activity", isOn: $state.useLiveActivity)
  78. }
  79. }
  80. }.scrollContentBackground(.hidden).background(color)
  81. .onAppear(perform: configureView)
  82. .navigationBarTitle("Notifications")
  83. .navigationBarTitleDisplayMode(.automatic)
  84. }
  85. }
  86. }