mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-27 15:54:30 +00:00
120 lines
3.4 KiB
Swift
120 lines
3.4 KiB
Swift
//
|
|
// AccountNotificationInspectorView.swift
|
|
// NetNewsWire-iOS
|
|
//
|
|
// Created by Stuart Breckenridge on 07/02/2026.
|
|
// Copyright © 2026 Ranchero Software. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import UserNotifications
|
|
import Account
|
|
import Images
|
|
|
|
struct AccountNotificationInspectorView: View {
|
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
@State private var uuid = UUID()
|
|
@State private var authorisationStatus: UNAuthorizationStatus = .notDetermined
|
|
|
|
var account: Account!
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
if authorisationStatus == .notDetermined || authorisationStatus == .denied {
|
|
VStack {
|
|
ContentUnavailableView("Notifications Disabled",
|
|
systemImage: "bell.slash",
|
|
description: Text("Enable Notifications in Settings", comment: "Enable Notifications in Settings"))
|
|
|
|
Button {
|
|
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
|
|
} label: {
|
|
Text("Open Settings", comment: "Open Settings button")
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
.tint(.accentColor)
|
|
}
|
|
.navigationTitle(Text("New Article Notifications", comment: "New Article Notifications"))
|
|
.navigationSubtitleIfAvailable(account.nameForDisplay)
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .topBarTrailing) {
|
|
closeButton
|
|
}
|
|
}
|
|
} else {
|
|
List(account.flattenedFeeds().sorted(by: { a, b in
|
|
a.nameForDisplay.localizedCaseInsensitiveCompare(b.nameForDisplay) == .orderedAscending
|
|
}), id: \.feedID) { feed in
|
|
Toggle(isOn: Binding(get: { feed.newArticleNotificationsEnabled }, set: { feed.newArticleNotificationsEnabled = $0 })) {
|
|
HStack {
|
|
if let img = IconImageCache.shared.imageFor(feed.sidebarItemID!) {
|
|
IconImageView(icon: img)
|
|
.id(uuid)
|
|
} else if let img = feed.smallIcon {
|
|
IconImageView(icon: img)
|
|
.id(uuid)
|
|
}
|
|
Text(verbatim: feed.nameForDisplay)
|
|
Spacer()
|
|
}
|
|
}
|
|
.tint(.accentColor)
|
|
}
|
|
.navigationTitle(Text("New Article Notifications", comment: "New Article Notifications"))
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.navigationSubtitleIfAvailable(account.nameForDisplay)
|
|
.toolbar {
|
|
ToolbarItem(placement: .topBarTrailing) {
|
|
closeButton
|
|
}
|
|
}
|
|
.onReceive(NotificationCenter.default.publisher(for: Notification.Name.feedIconImageDidChange)) { notification in
|
|
guard let feed = notification.userInfo?[UserInfoKey.feed] as? Feed, feed.account === account else {
|
|
return
|
|
}
|
|
uuid = UUID()
|
|
}
|
|
}
|
|
}
|
|
.task {
|
|
let settings = await UNUserNotificationCenter.current().notificationSettings()
|
|
self.authorisationStatus = settings.authorizationStatus
|
|
}
|
|
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification), perform: { _ in
|
|
Task {
|
|
let settings = await UNUserNotificationCenter.current().notificationSettings()
|
|
self.authorisationStatus = settings.authorizationStatus
|
|
}
|
|
})
|
|
}
|
|
|
|
@ViewBuilder
|
|
private var closeButton: some View {
|
|
if #available(iOS 26, *) {
|
|
Button(role: .close) {
|
|
dismiss()
|
|
}
|
|
} else {
|
|
Button {
|
|
dismiss()
|
|
} label: {
|
|
Text("Close", comment: "Close")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private extension View {
|
|
|
|
@ViewBuilder
|
|
func navigationSubtitleIfAvailable(_ subtitle: String) -> some View {
|
|
if #available(iOS 26, *) {
|
|
self.navigationSubtitle(Text(verbatim: subtitle))
|
|
} else {
|
|
self
|
|
}
|
|
}
|
|
}
|