From 5d90bdf8f06590d1adb33d6887b80912c120657f Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Wed, 9 Feb 2022 19:49:12 +0800 Subject: [PATCH 1/5] 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 @@ - + From d4a669ba1e893be547635d1ce5fbd745bedc8a20 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Fri, 11 Feb 2022 06:30:04 +0800 Subject: [PATCH 2/5] Disables prefetching --- iOS/Settings/NotificationsTableViewCell.swift | 2 -- iOS/Settings/NotificationsViewController.swift | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/iOS/Settings/NotificationsTableViewCell.swift b/iOS/Settings/NotificationsTableViewCell.swift index be5abfab2..3e3683ccf 100644 --- a/iOS/Settings/NotificationsTableViewCell.swift +++ b/iOS/Settings/NotificationsTableViewCell.swift @@ -31,7 +31,6 @@ class NotificationsTableViewCell: VibrantBasicTableViewCell { } func configure(_ webFeed: WebFeed) { - print("NotificationTableView: configuring cell: \(webFeed.nameForDisplay)") self.feed = webFeed var isOn = false if webFeed.isNotifyAboutNewArticles == nil { @@ -44,7 +43,6 @@ 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 5392b9ef9..103f27ed2 100644 --- a/iOS/Settings/NotificationsViewController.swift +++ b/iOS/Settings/NotificationsViewController.swift @@ -47,6 +47,7 @@ class NotificationsViewController: UIViewController { menu: notificationFilterMenu()) navigationItem.rightBarButtonItem = filterButton + notificationsTableView.isPrefetchingEnabled = false reloadNotificationTableView() @@ -71,17 +72,13 @@ 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)") } } From 1ac432cc1725ac62e284aafac0a9b536b1db8b37 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Fri, 11 Feb 2022 07:06:59 +0800 Subject: [PATCH 3/5] Prefetching & FavIconDidLoad --- .../NotificationsViewController.swift | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/iOS/Settings/NotificationsViewController.swift b/iOS/Settings/NotificationsViewController.swift index 103f27ed2..265173567 100644 --- a/iOS/Settings/NotificationsViewController.swift +++ b/iOS/Settings/NotificationsViewController.swift @@ -33,6 +33,7 @@ class NotificationsViewController: UIViewController { } } private var filterButton: UIBarButtonItem! + private var prefetchedIndexPaths = Set() override func viewDidLoad() { super.viewDidLoad() @@ -47,11 +48,11 @@ class NotificationsViewController: UIViewController { menu: notificationFilterMenu()) navigationItem.rightBarButtonItem = filterButton - notificationsTableView.isPrefetchingEnabled = false reloadNotificationTableView() NotificationCenter.default.addObserver(self, selector: #selector(updateCellsFrom(_:)), name: .WebFeedIconDidBecomeAvailable, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(reloadNotificationTableView(_:)), name: .FaviconDidBecomeAvailable, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(reloadNotificationTableView(_:)), name: UIScene.willEnterForegroundNotification, object: nil) } @@ -73,13 +74,20 @@ class NotificationsViewController: UIViewController { private func updateCellsFrom(_ notification: Notification) { guard let webFeed = notification.userInfo?[UserInfoKey.webFeed] as? WebFeed else { return } - 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]) - return + if let visibleIndexPaths = notificationsTableView.indexPathsForVisibleRows { + prefetchedIndexPaths.formUnion(visibleIndexPaths) + } + let allIndexPaths = Array(prefetchedIndexPaths) + + for path in allIndexPaths { + if let cell = notificationsTableView.cellForRow(at: path) as? NotificationsTableViewCell { + if cell.feed! == webFeed { + notificationsTableView.reconfigureRows(at: [path]) + return + } } } + } private func notificationFilterMenu() -> UIMenu { @@ -212,16 +220,19 @@ extension NotificationsViewController: UITableViewDataSource { let cell = tableView.dequeueReusableCell(withIdentifier: "NotificationsCell") as! NotificationsTableViewCell let account = AccountManager.shared.sortedActiveAccounts[indexPath.section - 1] cell.configure(filteredWebFeeds(searchController.searchBar.text, account: account)[indexPath.row]) + prefetchedIndexPaths.insert(indexPath) return cell } else if newArticleNotificationFilter == true { let cell = tableView.dequeueReusableCell(withIdentifier: "NotificationsCell") as! NotificationsTableViewCell let account = AccountManager.shared.sortedActiveAccounts[indexPath.section - 1] cell.configure(feedsWithNotificationsEnabled(account)[indexPath.row]) + prefetchedIndexPaths.insert(indexPath) return cell } else { let cell = tableView.dequeueReusableCell(withIdentifier: "NotificationsCell") as! NotificationsTableViewCell let account = AccountManager.shared.sortedActiveAccounts[indexPath.section - 1] cell.configure(sortedWebFeedsForAccount(account)[indexPath.row]) + prefetchedIndexPaths.insert(indexPath) return cell } } From 8a6140e942bd865af5c637f0f416b6b576876462 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Fri, 11 Feb 2022 07:10:41 +0800 Subject: [PATCH 4/5] reloads visible cells for favicon notification --- iOS/Settings/NotificationsViewController.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/iOS/Settings/NotificationsViewController.swift b/iOS/Settings/NotificationsViewController.swift index 265173567..61034ba5c 100644 --- a/iOS/Settings/NotificationsViewController.swift +++ b/iOS/Settings/NotificationsViewController.swift @@ -52,7 +52,7 @@ class NotificationsViewController: UIViewController { reloadNotificationTableView() NotificationCenter.default.addObserver(self, selector: #selector(updateCellsFrom(_:)), name: .WebFeedIconDidBecomeAvailable, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(reloadNotificationTableView(_:)), name: .FaviconDidBecomeAvailable, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(reloadVisibleCells(_:)), name: .FaviconDidBecomeAvailable, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(reloadNotificationTableView(_:)), name: UIScene.willEnterForegroundNotification, object: nil) } @@ -87,9 +87,16 @@ class NotificationsViewController: UIViewController { } } } - } + @objc + private func reloadVisibleCells(_ notification: Notification) { + if let visibleIndexPaths = notificationsTableView.indexPathsForVisibleRows { + notificationsTableView.reconfigureRows(at: visibleIndexPaths) + } + } + + private func notificationFilterMenu() -> UIMenu { if filterButton != nil { From e67136f0266eca7ebad93bbcbe4e21368c4a9df4 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Fri, 11 Feb 2022 07:33:49 +0800 Subject: [PATCH 5/5] prefetching disabled --- .../NotificationsViewController.swift | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/iOS/Settings/NotificationsViewController.swift b/iOS/Settings/NotificationsViewController.swift index 61034ba5c..82f8d07db 100644 --- a/iOS/Settings/NotificationsViewController.swift +++ b/iOS/Settings/NotificationsViewController.swift @@ -40,6 +40,7 @@ class NotificationsViewController: UIViewController { title = NSLocalizedString("New Article Notifications", comment: "Notifications") navigationItem.searchController = searchController + notificationsTableView.isPrefetchingEnabled = false filterButton = UIBarButtonItem( title: nil, @@ -75,18 +76,18 @@ class NotificationsViewController: UIViewController { guard let webFeed = notification.userInfo?[UserInfoKey.webFeed] as? WebFeed else { return } if let visibleIndexPaths = notificationsTableView.indexPathsForVisibleRows { - prefetchedIndexPaths.formUnion(visibleIndexPaths) - } - let allIndexPaths = Array(prefetchedIndexPaths) - - for path in allIndexPaths { - if let cell = notificationsTableView.cellForRow(at: path) as? NotificationsTableViewCell { - if cell.feed! == webFeed { - notificationsTableView.reconfigureRows(at: [path]) - return + for path in visibleIndexPaths { + if let cell = notificationsTableView.cellForRow(at: path) as? NotificationsTableViewCell { + if cell.feed! == webFeed { + notificationsTableView.reconfigureRows(at: [path]) + + return + } } } } + + } @objc