Encapsulate more of the AppCoordinate API

This commit is contained in:
Maurice Parker 2019-07-06 11:32:19 -05:00
parent 15754684a4
commit 4884aebbfd
4 changed files with 44 additions and 28 deletions

View File

@ -45,7 +45,7 @@ class AppCoordinator {
} }
private let treeControllerDelegate = FeedTreeControllerDelegate() private let treeControllerDelegate = FeedTreeControllerDelegate()
lazy var treeController: TreeController = { private(set) lazy var treeController: TreeController = {
return TreeController(delegate: treeControllerDelegate) return TreeController(delegate: treeControllerDelegate)
}() }()
@ -57,7 +57,7 @@ class AppCoordinator {
return shadowTable.count return shadowTable.count
} }
var currentMasterIndexPath: IndexPath? { private(set) var currentMasterIndexPath: IndexPath? {
didSet { didSet {
guard let ip = currentMasterIndexPath, let node = nodeFor(ip) else { guard let ip = currentMasterIndexPath, let node = nodeFor(ip) else {
assertionFailure() assertionFailure()
@ -88,8 +88,8 @@ class AppCoordinator {
} }
var showFeedNames = false private(set) var showFeedNames = false
var showAvatars = false private(set) var showAvatars = false
var isPrevArticleAvailable: Bool { var isPrevArticleAvailable: Bool {
guard let indexPath = currentArticleIndexPath else { guard let indexPath = currentArticleIndexPath else {
@ -135,7 +135,7 @@ class AppCoordinator {
return nil return nil
} }
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) NotificationCenter.default.post(name: .ArticleSelectionDidChange, object: self, userInfo: nil)
@ -143,7 +143,7 @@ class AppCoordinator {
} }
} }
var articles = ArticleArray() { private(set) var articles = ArticleArray() {
didSet { didSet {
if articles == oldValue { if articles == oldValue {
return return
@ -246,24 +246,6 @@ class AppCoordinator {
// MARK: API // MARK: API
func didSelectFeed(_ indexPath: IndexPath) {
masterTimelineViewController = UIStoryboard.main.instantiateController(ofType: MasterTimelineViewController.self)
masterTimelineViewController!.coordinator = self
currentMasterIndexPath = indexPath
masterNavigationController.pushViewController(masterTimelineViewController!, animated: true)
}
func didSelectArticle(_ indexPath: IndexPath) {
let detailViewController = UIStoryboard.main.instantiateController(ofType: DetailViewController.self)
detailViewController.coordinator = self
detailViewController.navigationItem.leftBarButtonItem = rootSplitViewController.displayModeButtonItem
detailViewController.navigationItem.leftItemsSupplementBackButton = true
currentArticleIndexPath = indexPath
// rootSplitViewController.toggleMasterView()
rootSplitViewController.showDetailViewController(detailViewController, sender: self)
}
func beginUpdates() { func beginUpdates() {
animatingChanges = true animatingChanges = true
} }
@ -445,6 +427,40 @@ class AppCoordinator {
return indexes return indexes
} }
func selectFeed(_ indexPath: IndexPath) {
masterTimelineViewController = UIStoryboard.main.instantiateController(ofType: MasterTimelineViewController.self)
masterTimelineViewController!.coordinator = self
currentMasterIndexPath = indexPath
masterNavigationController.pushViewController(masterTimelineViewController!, animated: true)
}
func selectArticle(_ indexPath: IndexPath) {
if let detailNavController = rootSplitViewController.viewControllers.last as? UINavigationController,
let _ = detailNavController.topViewController as? DetailViewController {
currentArticleIndexPath = indexPath
} else {
let detailViewController = UIStoryboard.main.instantiateController(ofType: DetailViewController.self)
detailViewController.coordinator = self
detailViewController.navigationItem.leftBarButtonItem = rootSplitViewController.displayModeButtonItem
detailViewController.navigationItem.leftItemsSupplementBackButton = true
currentArticleIndexPath = indexPath
// rootSplitViewController.toggleMasterView()
rootSplitViewController.showDetailViewController(detailViewController, sender: self)
}
}
func selectPrevArticle() {
if let indexPath = prevArticleIndexPath {
selectArticle(indexPath)
}
}
func selectNextArticle() {
if let indexPath = nextArticleIndexPath {
selectArticle(indexPath)
}
}
func selectNextUnread() { func selectNextUnread() {
// This should never happen, but I don't want to risk throwing us // This should never happen, but I don't want to risk throwing us

View File

@ -136,11 +136,11 @@ class DetailViewController: UIViewController {
} }
@IBAction func prevArticle(_ sender: Any) { @IBAction func prevArticle(_ sender: Any) {
coordinator.currentArticleIndexPath = coordinator.prevArticleIndexPath coordinator.selectPrevArticle()
} }
@IBAction func nextArticle(_ sender: Any) { @IBAction func nextArticle(_ sender: Any) {
coordinator.currentArticleIndexPath = coordinator.nextArticleIndexPath coordinator.selectNextArticle()
} }
@IBAction func toggleRead(_ sender: Any) { @IBAction func toggleRead(_ sender: Any) {

View File

@ -276,7 +276,7 @@ class MasterFeedViewController: ProgressTableViewController, UndoableCommandRunn
} }
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
coordinator.didSelectFeed(indexPath) coordinator.selectFeed(indexPath)
} }
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {

View File

@ -175,7 +175,7 @@ class MasterTimelineViewController: ProgressTableViewController, UndoableCommand
} }
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
coordinator.didSelectArticle(indexPath) coordinator.selectArticle(indexPath)
} }
// MARK: Notifications // MARK: Notifications