From 5d90bdf8f06590d1adb33d6887b80912c120657f Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Wed, 9 Feb 2022 19:49:12 +0800 Subject: [PATCH] notifications --- iOS/Settings/NotificationsTableViewCell.swift | 4 ++- .../NotificationsViewController.swift | 32 +++++++++++-------- iOS/Settings/Settings.storyboard | 2 +- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/iOS/Settings/NotificationsTableViewCell.swift b/iOS/Settings/NotificationsTableViewCell.swift index cf0c66beb..be5abfab2 100644 --- a/iOS/Settings/NotificationsTableViewCell.swift +++ b/iOS/Settings/NotificationsTableViewCell.swift @@ -16,7 +16,7 @@ class NotificationsTableViewCell: VibrantBasicTableViewCell { @IBOutlet weak var notificationsSwitch: UISwitch! @IBOutlet weak var notificationsLabel: UILabel! @IBOutlet weak var notificationsImageView: UIImageView! - var feed: WebFeed? + weak var feed: WebFeed? override func awakeFromNib() { @@ -31,6 +31,7 @@ class NotificationsTableViewCell: VibrantBasicTableViewCell { } func configure(_ webFeed: WebFeed) { + print("NotificationTableView: configuring cell: \(webFeed.nameForDisplay)") self.feed = webFeed var isOn = false if webFeed.isNotifyAboutNewArticles == nil { @@ -43,6 +44,7 @@ class NotificationsTableViewCell: VibrantBasicTableViewCell { notificationsLabel.text = webFeed.nameForDisplay notificationsImageView.image = IconImageCache.shared.imageFor(webFeed.feedID!)?.image notificationsImageView.layer.cornerRadius = 4 + print("NotificationTableView: configured cell: \(webFeed.nameForDisplay)") } @objc diff --git a/iOS/Settings/NotificationsViewController.swift b/iOS/Settings/NotificationsViewController.swift index 61b4ed398..5392b9ef9 100644 --- a/iOS/Settings/NotificationsViewController.swift +++ b/iOS/Settings/NotificationsViewController.swift @@ -38,7 +38,6 @@ class NotificationsViewController: UIViewController { super.viewDidLoad() title = NSLocalizedString("New Article Notifications", comment: "Notifications") - notificationsTableView.prefetchDataSource = self navigationItem.searchController = searchController filterButton = UIBarButtonItem( @@ -51,6 +50,7 @@ class NotificationsViewController: UIViewController { reloadNotificationTableView() + NotificationCenter.default.addObserver(self, selector: #selector(updateCellsFrom(_:)), name: .WebFeedIconDidBecomeAvailable, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(reloadNotificationTableView(_:)), name: UIScene.willEnterForegroundNotification, object: nil) } @@ -68,6 +68,23 @@ class NotificationsViewController: UIViewController { } } + @objc + private func updateCellsFrom(_ notification: Notification) { + guard let webFeed = notification.userInfo?[UserInfoKey.webFeed] as? WebFeed else { return } + print("NotificationTableView: Received WebFeedIcon for \(webFeed.nameForDisplay)") + + let cell = notificationsTableView.visibleCells.filter({ ($0 as? NotificationsTableViewCell)?.feed == webFeed }).first as? NotificationsTableViewCell + if cell != nil { + if let indexPath = notificationsTableView.indexPath(for: cell!) { + notificationsTableView.reconfigureRows(at: [indexPath]) + print("NotificationTableView: Reconfigured cell for \(webFeed.nameForDisplay)") + return + } + } else { + print("NotificationTableView: Cannot find cell for \(webFeed.nameForDisplay)") + } + } + private func notificationFilterMenu() -> UIMenu { if filterButton != nil { @@ -242,19 +259,6 @@ extension NotificationsViewController: UITableViewDelegate { } -extension NotificationsViewController: UITableViewDataSourcePrefetching { - - func tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath]) { - for path in indexPaths { - let account = AccountManager.shared.sortedActiveAccounts[path.section - 1] - let feed = sortedWebFeedsForAccount(account)[path.row] - let _ = IconImageCache.shared.imageFor(feed.feedID!) - } - } - -} - - // MARK: - UISearchControllerDelegate extension NotificationsViewController: UISearchControllerDelegate { diff --git a/iOS/Settings/Settings.storyboard b/iOS/Settings/Settings.storyboard index 5d8a05ff4..485e8fe4b 100644 --- a/iOS/Settings/Settings.storyboard +++ b/iOS/Settings/Settings.storyboard @@ -1194,7 +1194,7 @@ - +