From 73500e024403a12616267d35bcdc64c01d4936dd Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 21 Apr 2019 15:26:37 -0500 Subject: [PATCH] Encapsulate more of the NavigationModelController structures. --- iOS/Master/MasterViewController.swift | 14 +++++++------- iOS/NavigationModelController.swift | 4 ++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/iOS/Master/MasterViewController.swift b/iOS/Master/MasterViewController.swift index 59af27fe1..162bff11e 100644 --- a/iOS/Master/MasterViewController.swift +++ b/iOS/Master/MasterViewController.swift @@ -77,8 +77,8 @@ class MasterViewController: UITableViewController, UndoableCommandRunner { } if let account = representedObject as? Account { - if let node = nmc.treeController.rootNode.childNodeRepresentingObject(account) { - let sectionIndex = nmc.treeController.rootNode.indexOfChild(node)! + if let node = nmc.rootNode.childNodeRepresentingObject(account) { + let sectionIndex = nmc.rootNode.indexOfChild(node)! let headerView = tableView.headerView(forSection: sectionIndex) as! MasterTableViewSectionHeader headerView.unreadCount = account.unreadCount } @@ -108,7 +108,7 @@ class MasterViewController: UITableViewController, UndoableCommandRunner { @objc func userDidAddFeed(_ notification: Notification) { guard let feed = notification.userInfo?[UserInfoKey.feed], - let node = nmc.treeController.rootNode.descendantNodeRepresentingObject(feed as AnyObject) else { + let node = nmc.rootNode.descendantNodeRepresentingObject(feed as AnyObject) else { return } @@ -150,14 +150,14 @@ class MasterViewController: UITableViewController, UndoableCommandRunner { override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { - guard let nameProvider = nmc.treeController.rootNode.childAtIndex(section)?.representedObject as? DisplayNameProvider else { + guard let nameProvider = nmc.rootNode.childAtIndex(section)?.representedObject as? DisplayNameProvider else { return nil } let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as! MasterTableViewSectionHeader headerView.name = nameProvider.nameForDisplay - guard let sectionNode = nmc.treeController.rootNode.childAtIndex(section) else { + guard let sectionNode = nmc.rootNode.childAtIndex(section) else { return headerView } @@ -325,7 +325,7 @@ class MasterViewController: UITableViewController, UndoableCommandRunner { // Based on the drop we have to determine a node to start looking for a parent container. let destNode: Node = { if destinationIndexPath.row == 0 { - return nmc.treeController.rootNode.childAtIndex(destinationIndexPath.section)! + return nmc.rootNode.childAtIndex(destinationIndexPath.section)! } else { let movementAdjustment = sourceIndexPath > destinationIndexPath ? 1 : 0 let adjustedDestIndexPath = IndexPath(row: destinationIndexPath.row - movementAdjustment, section: destinationIndexPath.section) @@ -452,7 +452,7 @@ class MasterViewController: UITableViewController, UndoableCommandRunner { @objc func toggleSectionHeader(_ sender: UITapGestureRecognizer) { guard let sectionIndex = sender.view?.tag, - let sectionNode = nmc.treeController.rootNode.childAtIndex(sectionIndex), + let sectionNode = nmc.rootNode.childAtIndex(sectionIndex), let headerView = sender.view as? MasterTableViewSectionHeader else { return diff --git a/iOS/NavigationModelController.swift b/iOS/NavigationModelController.swift index 2ac1d53a3..d024d23ea 100644 --- a/iOS/NavigationModelController.swift +++ b/iOS/NavigationModelController.swift @@ -33,6 +33,10 @@ class NavigationModelController { return TreeController(delegate: treeControllerDelegate) }() + var rootNode: Node { + return treeController.rootNode + } + private var sortDirection = AppDefaults.timelineSortDirection { didSet { if sortDirection != oldValue {