diff --git a/iOS/Settings/NotificationsTableViewCell.swift b/iOS/Settings/NotificationsTableViewCell.swift index cf0c66beb..3e3683ccf 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() { diff --git a/iOS/Settings/NotificationsViewController.swift b/iOS/Settings/NotificationsViewController.swift index 61b4ed398..82f8d07db 100644 --- a/iOS/Settings/NotificationsViewController.swift +++ b/iOS/Settings/NotificationsViewController.swift @@ -33,13 +33,14 @@ class NotificationsViewController: UIViewController { } } private var filterButton: UIBarButtonItem! + private var prefetchedIndexPaths = Set() override func viewDidLoad() { super.viewDidLoad() title = NSLocalizedString("New Article Notifications", comment: "Notifications") - notificationsTableView.prefetchDataSource = self navigationItem.searchController = searchController + notificationsTableView.isPrefetchingEnabled = false filterButton = UIBarButtonItem( title: nil, @@ -51,6 +52,8 @@ class NotificationsViewController: UIViewController { reloadNotificationTableView() + NotificationCenter.default.addObserver(self, selector: #selector(updateCellsFrom(_:)), name: .WebFeedIconDidBecomeAvailable, 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) } @@ -68,6 +71,33 @@ class NotificationsViewController: UIViewController { } } + @objc + private func updateCellsFrom(_ notification: Notification) { + guard let webFeed = notification.userInfo?[UserInfoKey.webFeed] as? WebFeed else { return } + + if let visibleIndexPaths = notificationsTableView.indexPathsForVisibleRows { + for path in visibleIndexPaths { + if let cell = notificationsTableView.cellForRow(at: path) as? NotificationsTableViewCell { + if cell.feed! == webFeed { + notificationsTableView.reconfigureRows(at: [path]) + + return + } + } + } + } + + + } + + @objc + private func reloadVisibleCells(_ notification: Notification) { + if let visibleIndexPaths = notificationsTableView.indexPathsForVisibleRows { + notificationsTableView.reconfigureRows(at: visibleIndexPaths) + } + } + + private func notificationFilterMenu() -> UIMenu { if filterButton != nil { @@ -198,16 +228,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 } } @@ -242,19 +275,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 b6cf12d35..b9515ae5e 100644 --- a/iOS/Settings/Settings.storyboard +++ b/iOS/Settings/Settings.storyboard @@ -1152,7 +1152,7 @@ - +