Merge pull request #3455 from stuartbreckenridge/ios-ui-notifications

iOS UI Notifications
This commit is contained in:
Maurice Parker
2022-02-10 15:37:01 -08:00
committed by GitHub
3 changed files with 36 additions and 16 deletions

View File

@@ -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() {

View File

@@ -33,13 +33,14 @@ class NotificationsViewController: UIViewController {
}
}
private var filterButton: UIBarButtonItem!
private var prefetchedIndexPaths = Set<IndexPath>()
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 {

View File

@@ -1152,7 +1152,7 @@
<constraint firstItem="dsQ-vy-iVG" firstAttribute="top" secondItem="2EC-mY-aSE" secondAttribute="top" id="3o7-Oa-Qhq"/>
<constraint firstItem="dsQ-vy-iVG" firstAttribute="leading" secondItem="32c-qn-nBM" secondAttribute="leading" id="V01-Fb-OvO"/>
<constraint firstItem="32c-qn-nBM" firstAttribute="trailing" secondItem="dsQ-vy-iVG" secondAttribute="trailing" id="WTV-jU-eAU"/>
<constraint firstItem="dsQ-vy-iVG" firstAttribute="bottom" secondItem="32c-qn-nBM" secondAttribute="bottom" constant="34" id="nQh-bT-XE2"/>
<constraint firstItem="dsQ-vy-iVG" firstAttribute="bottom" secondItem="2EC-mY-aSE" secondAttribute="bottom" id="nQh-bT-XE2"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="sdU-Jy-5dq"/>