From a19154ac734bc133e451f217e451dec907ba85f0 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sat, 5 Feb 2022 10:22:49 +0800 Subject: [PATCH] Adds account-wide to notifications manager --- iOS/AppAssets.swift | 4 ++ .../NotificationsViewController.swift | 65 ++++++++++++++++--- iOS/Settings/Settings.storyboard | 2 +- 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/iOS/AppAssets.swift b/iOS/AppAssets.swift index 26ee3be0f..79b34c712 100644 --- a/iOS/AppAssets.swift +++ b/iOS/AppAssets.swift @@ -185,6 +185,10 @@ struct AppAssets { return UIImage(systemName: "ellipsis.circle")! }() + static var moreImageFill: UIImage = { + return UIImage(systemName: "ellipsis.circle.fill")! + }() + static var nextArticleImage: UIImage = { return UIImage(systemName: "chevron.down")! }() diff --git a/iOS/Settings/NotificationsViewController.swift b/iOS/Settings/NotificationsViewController.swift index c7366ec22..61b4ed398 100644 --- a/iOS/Settings/NotificationsViewController.swift +++ b/iOS/Settings/NotificationsViewController.swift @@ -43,7 +43,7 @@ class NotificationsViewController: UIViewController { filterButton = UIBarButtonItem( title: nil, - image: AppAssets.filterInactiveImage, + image: AppAssets.moreImage, primaryAction: nil, menu: notificationFilterMenu()) @@ -70,22 +70,23 @@ class NotificationsViewController: UIViewController { private func notificationFilterMenu() -> UIMenu { - if let filterButton = filterButton { - if newArticleNotificationFilter == true { - filterButton.image = AppAssets.filterActiveImage + if filterButton != nil { + if newArticleNotificationFilter { + filterButton.image = AppAssets.moreImageFill } else { - filterButton.image = AppAssets.filterInactiveImage + filterButton.image = AppAssets.moreImage } } - let menu = UIMenu(title: "", + + let filterMenu = UIMenu(title: "", image: nil, identifier: nil, options: [.displayInline], children: [ UIAction( title: NSLocalizedString("Show Feeds with Notifications Enabled", comment: "Feeds with Notifications"), - image: AppAssets.appBadgeImage, + image: nil, identifier: nil, discoverabilityTitle: nil, attributes: [], @@ -94,7 +95,55 @@ class NotificationsViewController: UIViewController { self?.newArticleNotificationFilter.toggle() self?.notificationsTableView.reloadData() })]) - return menu + + + var menus = [UIMenuElement]() + menus.append(filterMenu) + + for account in AccountManager.shared.sortedActiveAccounts { + let accountMenu = UIMenu(title: account.nameForDisplay, image: nil, identifier: nil, options: .singleSelection, children: [enableAllAction(for: account), disableAllAction(for: account)]) + menus.append(accountMenu) + } + + let combinedMenu = UIMenu(title: "", + image: nil, + identifier: nil, + options: .displayInline, + children: menus) + + return combinedMenu + } + + private func enableAllAction(for account: Account) -> UIAction { + let action = UIAction(title: NSLocalizedString("Enable All Notifications", comment: "Enable All"), + image: nil, + identifier: nil, + discoverabilityTitle: nil, + attributes: [], + state: .off) { [weak self] _ in + for feed in account.flattenedWebFeeds() { + feed.isNotifyAboutNewArticles = true + } + self?.notificationsTableView.reloadData() + self?.filterButton.menu = self?.notificationFilterMenu() + } + return action + } + + private func disableAllAction(for account: Account) -> UIAction { + let action = UIAction(title: NSLocalizedString("Disable All Notifications", comment: "Disable All"), + image: nil, + identifier: nil, + discoverabilityTitle: nil, + attributes: [], + state: .off) { [weak self] _ in + for feed in account.flattenedWebFeeds() { + feed.isNotifyAboutNewArticles = false + } + self?.notificationsTableView.reloadData() + self?.filterButton.menu = self?.notificationFilterMenu() + } + return action } // MARK: - Feed Filtering diff --git a/iOS/Settings/Settings.storyboard b/iOS/Settings/Settings.storyboard index 1885b1634..5d8a05ff4 100644 --- a/iOS/Settings/Settings.storyboard +++ b/iOS/Settings/Settings.storyboard @@ -43,7 +43,7 @@ -