mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Notifications Manager Perf Improvements
Adopts prefetch for smooth scrolling
This commit is contained in:
@@ -10,11 +10,8 @@ import UIKit
|
||||
import Account
|
||||
import UserNotifications
|
||||
|
||||
extension Notification.Name {
|
||||
static let NotificationPreferencesDidUpdate = Notification.Name("NotificationPreferencesDidUpdate")
|
||||
}
|
||||
|
||||
class NotificationsTableViewCell: UITableViewCell {
|
||||
class NotificationsTableViewCell: VibrantBasicTableViewCell {
|
||||
|
||||
@IBOutlet weak var notificationsSwitch: UISwitch!
|
||||
@IBOutlet weak var notificationsLabel: UILabel!
|
||||
@@ -33,7 +30,7 @@ class NotificationsTableViewCell: UITableViewCell {
|
||||
// Configure the view for the selected state
|
||||
}
|
||||
|
||||
func configure(_ webFeed: WebFeed, _ status: UNAuthorizationStatus) {
|
||||
func configure(_ webFeed: WebFeed) {
|
||||
self.feed = webFeed
|
||||
var isOn = false
|
||||
if webFeed.isNotifyAboutNewArticles == nil {
|
||||
@@ -43,9 +40,8 @@ class NotificationsTableViewCell: UITableViewCell {
|
||||
}
|
||||
notificationsSwitch.isOn = isOn
|
||||
notificationsSwitch.addTarget(self, action: #selector(toggleWebFeedNotification(_:)), for: .touchUpInside)
|
||||
if status == .denied { notificationsSwitch.isEnabled = false }
|
||||
notificationsLabel.text = webFeed.nameForDisplay
|
||||
notificationsImageView.image = webFeed.smallIcon?.image
|
||||
notificationsImageView.image = IconImageCache.shared.imageFor(webFeed.feedID!)?.image
|
||||
notificationsImageView.layer.cornerRadius = 4
|
||||
}
|
||||
|
||||
@@ -61,14 +57,5 @@ class NotificationsTableViewCell: UITableViewCell {
|
||||
feed.isNotifyAboutNewArticles!.toggle()
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
private func requestNotificationPermissions(_ sender: Any) {
|
||||
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in
|
||||
NotificationCenter.default.post(name: .NotificationPreferencesDidUpdate, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -18,15 +18,10 @@ class NotificationsViewController: UIViewController {
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
notificationsTableView.prefetchDataSource = self
|
||||
self.title = NSLocalizedString("New Article Notifications", comment: "Notifications")
|
||||
notificationsTableView.sectionHeaderTopPadding = 25
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(reloadNotificationTableView(_:)), name: .FaviconDidBecomeAvailable, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(reloadNotificationTableView(_:)), name: .WebFeedIconDidBecomeAvailable, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(reloadNotificationTableView(_:)), name: .NotificationPreferencesDidUpdate, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(reloadNotificationTableView(_:)), name: UIScene.willEnterForegroundNotification, object: nil)
|
||||
|
||||
reloadNotificationTableView()
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(reloadNotificationTableView(_:)), name: UIScene.willEnterForegroundNotification, object: nil)
|
||||
}
|
||||
|
||||
@objc
|
||||
@@ -62,16 +57,13 @@ extension NotificationsViewController: UITableViewDataSource {
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
|
||||
|
||||
if indexPath.section == 0 {
|
||||
let openSettingsCell = tableView.dequeueReusableCell(withIdentifier: "OpenSettingsCell") as! VibrantBasicTableViewCell
|
||||
return openSettingsCell
|
||||
} else {
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "NotificationsCell") as! NotificationsTableViewCell
|
||||
let account = AccountManager.shared.sortedActiveAccounts[indexPath.section - 1]
|
||||
let feed = sortedWebFeedsForAccount(account)[indexPath.row]
|
||||
cell.configure(feed, status)
|
||||
cell.configure(sortedWebFeedsForAccount(account)[indexPath.row])
|
||||
return cell
|
||||
}
|
||||
}
|
||||
@@ -96,8 +88,22 @@ extension NotificationsViewController: UITableViewDelegate {
|
||||
|
||||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
UIApplication.shared.open(URL(string: "\(UIApplication.openSettingsURLString)")!)
|
||||
if indexPath.section == 0 {
|
||||
UIApplication.shared.open(URL(string: "\(UIApplication.openSettingsURLString)")!)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
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!)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1110,7 +1110,7 @@
|
||||
<!--Notifications View Controller-->
|
||||
<scene sceneID="Brh-C7-mfB">
|
||||
<objects>
|
||||
<viewController storyboardIdentifier="NotificationsViewController" id="vak-Sx-5aB" customClass="NotificationsViewController" customModule="NetNewsWire" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<viewController storyboardIdentifier="NotificationsViewController" extendedLayoutIncludesOpaqueBars="YES" id="vak-Sx-5aB" customClass="NotificationsViewController" customModule="NetNewsWire" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="2EC-mY-aSE">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
@@ -1194,7 +1194,7 @@
|
||||
<constraint firstItem="dsQ-vy-iVG" firstAttribute="top" secondItem="32c-qn-nBM" secondAttribute="top" constant="-88" 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>
|
||||
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/>
|
||||
|
||||
@@ -47,6 +47,8 @@ class SettingsViewController: UITableViewController {
|
||||
tableView.register(UINib(nibName: "SettingsComboTableViewCell", bundle: nil), forCellReuseIdentifier: "SettingsComboTableViewCell")
|
||||
tableView.register(UINib(nibName: "SettingsTableViewCell", bundle: nil), forCellReuseIdentifier: "SettingsTableViewCell")
|
||||
|
||||
refreshNotificationStatus()
|
||||
|
||||
tableView.rowHeight = UITableView.automaticDimension
|
||||
tableView.estimatedRowHeight = 44
|
||||
}
|
||||
@@ -72,7 +74,6 @@ class SettingsViewController: UITableViewController {
|
||||
refreshClearsReadArticlesSwitch.isOn = false
|
||||
}
|
||||
|
||||
|
||||
articleThemeDetailLabel.text = ArticleThemesManager.shared.currentTheme.name
|
||||
|
||||
if AppDefaults.shared.confirmMarkAllAsRead {
|
||||
@@ -112,7 +113,6 @@ class SettingsViewController: UITableViewController {
|
||||
tableView.scrollToRow(at: IndexPath(row: 0, section: 4), at: .top, animated: true)
|
||||
scrollToArticlesSection = false
|
||||
}
|
||||
refreshNotificationStatus()
|
||||
}
|
||||
|
||||
@objc
|
||||
|
||||
Reference in New Issue
Block a user