diff --git a/iOS/Settings/NotificationsTableViewCell.swift b/iOS/Settings/NotificationsTableViewCell.swift index 1058687ec..cf0c66beb 100644 --- a/iOS/Settings/NotificationsTableViewCell.swift +++ b/iOS/Settings/NotificationsTableViewCell.swift @@ -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) - } - } - - } diff --git a/iOS/Settings/NotificationsViewController.swift b/iOS/Settings/NotificationsViewController.swift index f72e76567..557ef9f1a 100644 --- a/iOS/Settings/NotificationsViewController.swift +++ b/iOS/Settings/NotificationsViewController.swift @@ -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!) + } + } } diff --git a/iOS/Settings/Settings.storyboard b/iOS/Settings/Settings.storyboard index 385a825db..811612d5f 100644 --- a/iOS/Settings/Settings.storyboard +++ b/iOS/Settings/Settings.storyboard @@ -1110,7 +1110,7 @@ - + @@ -1194,7 +1194,7 @@ - + diff --git a/iOS/Settings/SettingsViewController.swift b/iOS/Settings/SettingsViewController.swift index ef845f19e..043f8505f 100644 --- a/iOS/Settings/SettingsViewController.swift +++ b/iOS/Settings/SettingsViewController.swift @@ -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