Change AppCoordinator to directly call controller API's since that matches the Coordinator pattern better than sending them notifications

This commit is contained in:
Maurice Parker
2019-08-25 11:38:04 -05:00
parent 313518698c
commit 0b48c3893d
4 changed files with 54 additions and 69 deletions

View File

@@ -36,11 +36,6 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(articlesReinitialized(_:)), name: .ArticlesReinitialized, object: coordinator)
NotificationCenter.default.addObserver(self, selector: #selector(articleDataDidChange(_:)), name: .ArticleDataDidChange, object: coordinator)
NotificationCenter.default.addObserver(self, selector: #selector(articlesDidChange(_:)), name: .ArticlesDidChange, object: coordinator)
NotificationCenter.default.addObserver(self, selector: #selector(articleSelectionDidChange(_:)), name: .ArticleSelectionDidChange, object: coordinator)
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil)
refreshControl = UIRefreshControl()
@@ -109,6 +104,31 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
coordinator.selectNextUnread()
}
// MARK: API
func reinitializeArticles() {
resetUI()
}
func updateArticles() {
reloadAllVisibleCells()
}
func reloadArticles() {
performBlockAndRestoreSelection {
tableView.reloadData()
}
}
func updateArticleSelection() {
if let indexPath = coordinator.currentArticleIndexPath {
if tableView.indexPathForSelectedRow != indexPath {
tableView.selectRow(at: indexPath, animated: true, scrollPosition: .middle)
}
}
updateUI()
}
// MARK: - Table view
override func numberOfSections(in tableView: UITableView) -> Int {
@@ -320,32 +340,6 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
}
}
@objc func articlesReinitialized(_ note: Notification) {
resetUI()
}
@objc func articleDataDidChange(_ note: Notification) {
reloadAllVisibleCells()
}
@objc func articlesDidChange(_ note: Notification) {
performBlockAndRestoreSelection {
tableView.reloadData()
}
}
@objc func articleSelectionDidChange(_ note: Notification) {
if let indexPath = coordinator.currentArticleIndexPath {
if tableView.indexPathForSelectedRow != indexPath {
tableView.selectRow(at: indexPath, animated: true, scrollPosition: .middle)
}
}
updateUI()
}
@objc func contentSizeCategoryDidChange(_ note: Notification) {
tableView.reloadData()
}