NotificationsView.swift 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // FeatureSettingsView.swift
  3. // FreeAPS
  4. //
  5. // Created by Deniz Cengiz on 26.07.24.
  6. //
  7. import Foundation
  8. import LoopKitUI
  9. import SwiftUI
  10. import Swinject
  11. struct NotificationsView: BaseView {
  12. let resolver: Resolver
  13. @ObservedObject var state: Settings.StateModel
  14. @State var notificationsDisabled = false
  15. @Environment(\.appName) private var appName
  16. @Environment(\.colorScheme) var colorScheme
  17. var color: LinearGradient {
  18. colorScheme == .dark ? LinearGradient(
  19. gradient: Gradient(colors: [
  20. Color.bgDarkBlue,
  21. Color.bgDarkerDarkBlue
  22. ]),
  23. startPoint: .top,
  24. endPoint: .bottom
  25. )
  26. :
  27. LinearGradient(
  28. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  29. startPoint: .top,
  30. endPoint: .bottom
  31. )
  32. }
  33. var body: some View {
  34. Form {
  35. Section(
  36. header: Text("Notification Center"),
  37. content: {
  38. Section(footer: DescriptiveText(label: String(format: NSLocalizedString("""
  39. Notifications give you important %1$@ app information without requiring you to open the app.
  40. Keep these turned ON in your phone’s settings to ensure you receive %1$@ Notifications, Critical Alerts, and Time Sensitive Notifications.
  41. """, comment: "Alert Permissions descriptive text (1: app name)"), appName)))
  42. {
  43. manageNotifications
  44. notificationsEnabledStatus
  45. }
  46. Text("Glucose Notifications").navigationLink(to: .glucoseNotificationSettings, from: self)
  47. if #available(iOS 16.2, *) {
  48. Text("Live Activity").navigationLink(to: .liveActivitySettings, from: self)
  49. }
  50. Text("Calendar Events").navigationLink(to: .calendarEventSettings, from: self)
  51. }
  52. )
  53. .listRowBackground(Color.chart)
  54. }
  55. .onReceive(resolver.resolve(AlertPermissionsChecker.self)!.$notificationsDisabled, perform: {
  56. notificationsDisabled = $0
  57. })
  58. .scrollContentBackground(.hidden).background(color)
  59. .navigationTitle("Notifications")
  60. .navigationBarTitleDisplayMode(.automatic)
  61. }
  62. }
  63. extension NotificationsView {
  64. @ViewBuilder private func onOff(_ val: Bool) -> some View {
  65. if val {
  66. Text(NSLocalizedString("On", comment: "Notification Setting Status is On"))
  67. } else {
  68. HStack {
  69. Image(systemName: "exclamationmark.triangle.fill").foregroundColor(.critical)
  70. Text(NSLocalizedString("Off", comment: "Notification Setting Status is Off"))
  71. }
  72. }
  73. }
  74. private var manageNotifications: some View {
  75. Button(action: { UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!) }) {
  76. HStack {
  77. Text(NSLocalizedString("Manage Permissions in Settings", comment: "Manage Permissions in Settings button text"))
  78. Spacer()
  79. Image(systemName: "chevron.right").foregroundColor(.gray).font(.footnote)
  80. }
  81. }
  82. .accentColor(.primary)
  83. }
  84. private var notificationsEnabledStatus: some View {
  85. HStack {
  86. Text(NSLocalizedString("Notifications", comment: "Notifications Status text"))
  87. Spacer()
  88. onOff(!notificationsDisabled)
  89. }
  90. }
  91. }