Change AppCoordinator to directly call controller API's since that matches the Coordinator pattern better than sending them notifications
This commit is contained in:
parent
313518698c
commit
0b48c3893d
@ -12,15 +12,6 @@ import Articles
|
|||||||
import RSCore
|
import RSCore
|
||||||
import RSTree
|
import RSTree
|
||||||
|
|
||||||
public extension Notification.Name {
|
|
||||||
static let MasterSelectionDidChange = Notification.Name(rawValue: "MasterSelectionDidChange")
|
|
||||||
static let BackingStoresDidRebuild = Notification.Name(rawValue: "BackingStoresDidRebuild")
|
|
||||||
static let ArticlesReinitialized = Notification.Name(rawValue: "ArticlesReinitialized")
|
|
||||||
static let ArticleDataDidChange = Notification.Name(rawValue: "ArticleDataDidChange")
|
|
||||||
static let ArticlesDidChange = Notification.Name(rawValue: "ArticlesDidChange")
|
|
||||||
static let ArticleSelectionDidChange = Notification.Name(rawValue: "ArticleSelectionDidChange")
|
|
||||||
}
|
|
||||||
|
|
||||||
class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||||
|
|
||||||
var undoableCommands = [UndoableCommand]()
|
var undoableCommands = [UndoableCommand]()
|
||||||
@ -98,7 +89,7 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
|||||||
if let fetcher = node.representedObject as? ArticleFetcher {
|
if let fetcher = node.representedObject as? ArticleFetcher {
|
||||||
timelineFetcher = fetcher
|
timelineFetcher = fetcher
|
||||||
}
|
}
|
||||||
NotificationCenter.default.post(name: .MasterSelectionDidChange, object: self, userInfo: nil)
|
masterFeedViewController.updateFeedSelection()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +106,7 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
|||||||
showFeedNames = true
|
showFeedNames = true
|
||||||
}
|
}
|
||||||
fetchAndReplaceArticlesSync()
|
fetchAndReplaceArticlesSync()
|
||||||
NotificationCenter.default.post(name: .ArticlesReinitialized, object: self, userInfo: nil)
|
masterTimelineViewController?.reinitializeArticles()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +160,8 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
|||||||
private(set) var currentArticleIndexPath: IndexPath? {
|
private(set) var currentArticleIndexPath: IndexPath? {
|
||||||
didSet {
|
didSet {
|
||||||
if currentArticleIndexPath != oldValue {
|
if currentArticleIndexPath != oldValue {
|
||||||
NotificationCenter.default.post(name: .ArticleSelectionDidChange, object: self, userInfo: nil)
|
masterTimelineViewController?.updateArticleSelection()
|
||||||
|
detailViewController?.updateArticleSelection()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,13 +173,13 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
|||||||
}
|
}
|
||||||
if articles.representSameArticlesInSameOrder(as: oldValue) {
|
if articles.representSameArticlesInSameOrder(as: oldValue) {
|
||||||
articleRowMap = [String: Int]()
|
articleRowMap = [String: Int]()
|
||||||
NotificationCenter.default.post(name: .ArticleDataDidChange, object: self, userInfo: nil)
|
masterTimelineViewController?.updateArticles()
|
||||||
updateUnreadCount()
|
updateUnreadCount()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
updateShowAvatars()
|
updateShowAvatars()
|
||||||
articleRowMap = [String: Int]()
|
articleRowMap = [String: Int]()
|
||||||
NotificationCenter.default.post(name: .ArticlesDidChange, object: self, userInfo: nil)
|
masterTimelineViewController?.reloadArticles()
|
||||||
updateUnreadCount()
|
updateUnreadCount()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -772,7 +764,7 @@ private extension AppCoordinator {
|
|||||||
if !animatingChanges && !BatchUpdate.shared.isPerforming {
|
if !animatingChanges && !BatchUpdate.shared.isPerforming {
|
||||||
treeController.rebuild()
|
treeController.rebuild()
|
||||||
rebuildShadowTable()
|
rebuildShadowTable()
|
||||||
NotificationCenter.default.post(name: .BackingStoresDidRebuild, object: self, userInfo: nil)
|
masterFeedViewController.reloadFeeds()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@ class DetailViewController: UIViewController {
|
|||||||
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(articleSelectionDidChange(_:)), name: .ArticleSelectionDidChange, object: coordinator)
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange(_:)), name: UIContentSizeCategory.didChangeNotification, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange(_:)), name: UIContentSizeCategory.didChangeNotification, object: nil)
|
||||||
}
|
}
|
||||||
@ -109,12 +108,6 @@ class DetailViewController: UIViewController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func articleSelectionDidChange(_ note: Notification) {
|
|
||||||
markAsRead()
|
|
||||||
updateUI()
|
|
||||||
reloadHTML()
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc func progressDidChange(_ note: Notification) {
|
@objc func progressDidChange(_ note: Notification) {
|
||||||
updateProgressIndicatorIfNeeded()
|
updateProgressIndicatorIfNeeded()
|
||||||
}
|
}
|
||||||
@ -159,6 +152,15 @@ class DetailViewController: UIViewController {
|
|||||||
activityViewController.popoverPresentationController?.barButtonItem = actionBarButtonItem
|
activityViewController.popoverPresentationController?.barButtonItem = actionBarButtonItem
|
||||||
present(activityViewController, animated: true)
|
present(activityViewController, animated: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: API
|
||||||
|
func updateArticleSelection() {
|
||||||
|
markAsRead()
|
||||||
|
updateUI()
|
||||||
|
reloadHTML()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ArticleActivityItemSource: NSObject, UIActivityItemSource {
|
class ArticleActivityItemSource: NSObject, UIActivityItemSource {
|
||||||
|
@ -42,9 +42,6 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
|
|||||||
NotificationCenter.default.addObserver(self, selector: #selector(feedSettingDidChange(_:)), name: .FeedSettingDidChange, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(feedSettingDidChange(_:)), name: .FeedSettingDidChange, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(userDidAddFeed(_:)), name: .UserDidAddFeed, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(userDidAddFeed(_:)), name: .UserDidAddFeed, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(backingStoresDidRebuild(_:)), name: .BackingStoresDidRebuild, object: coordinator)
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(masterSelectionDidChange(_:)), name: .MasterSelectionDidChange, object: coordinator)
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil)
|
||||||
|
|
||||||
refreshControl = UIRefreshControl()
|
refreshControl = UIRefreshControl()
|
||||||
@ -73,11 +70,6 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
|
|||||||
|
|
||||||
// MARK: Notifications
|
// MARK: Notifications
|
||||||
|
|
||||||
@objc dynamic func backingStoresDidRebuild(_ notification: Notification) {
|
|
||||||
updateUI()
|
|
||||||
tableView.reloadData()
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc func unreadCountDidChange(_ note: Notification) {
|
@objc func unreadCountDidChange(_ note: Notification) {
|
||||||
|
|
||||||
updateUI()
|
updateUI()
|
||||||
@ -140,14 +132,6 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
|
|||||||
navigationController?.updateAccountRefreshProgressIndicator()
|
navigationController?.updateAccountRefreshProgressIndicator()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func masterSelectionDidChange(_ note: Notification) {
|
|
||||||
if let indexPath = coordinator.currentMasterIndexPath {
|
|
||||||
if tableView.indexPathForSelectedRow != indexPath {
|
|
||||||
tableView.selectRow(at: indexPath, animated: true, scrollPosition: .middle)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc func contentSizeCategoryDidChange(_ note: Notification) {
|
@objc func contentSizeCategoryDidChange(_ note: Notification) {
|
||||||
tableView.reloadData()
|
tableView.reloadData()
|
||||||
}
|
}
|
||||||
@ -492,6 +476,19 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
|
|||||||
|
|
||||||
// MARK: API
|
// MARK: API
|
||||||
|
|
||||||
|
func updateFeedSelection() {
|
||||||
|
if let indexPath = coordinator.currentMasterIndexPath {
|
||||||
|
if tableView.indexPathForSelectedRow != indexPath {
|
||||||
|
tableView.selectRow(at: indexPath, animated: true, scrollPosition: .middle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func reloadFeeds() {
|
||||||
|
updateUI()
|
||||||
|
tableView.reloadData()
|
||||||
|
}
|
||||||
|
|
||||||
func discloseFeed(_ feed: Feed) {
|
func discloseFeed(_ feed: Feed) {
|
||||||
|
|
||||||
guard let node = coordinator.rootNode.descendantNodeRepresentingObject(feed as AnyObject) else {
|
guard let node = coordinator.rootNode.descendantNodeRepresentingObject(feed as AnyObject) else {
|
||||||
|
@ -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(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, 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(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)
|
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil)
|
||||||
|
|
||||||
refreshControl = UIRefreshControl()
|
refreshControl = UIRefreshControl()
|
||||||
@ -109,6 +104,31 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
|||||||
coordinator.selectNextUnread()
|
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
|
// MARK: - Table view
|
||||||
|
|
||||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
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) {
|
@objc func contentSizeCategoryDidChange(_ note: Notification) {
|
||||||
tableView.reloadData()
|
tableView.reloadData()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user