Finish hiding the NavigationStateController internal structures.
This commit is contained in:
parent
4479d724ae
commit
5f653c7ba1
|
@ -137,11 +137,11 @@ class MasterViewController: UITableViewController, UndoableCommandRunner {
|
||||||
// MARK: Table View
|
// MARK: Table View
|
||||||
|
|
||||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
return navState.shadowTable.count
|
return navState.numberOfSections
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
return navState.shadowTable[section].count
|
return navState.rowsInSection(section)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
||||||
|
@ -168,7 +168,7 @@ class MasterViewController: UITableViewController, UndoableCommandRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
headerView.tag = section
|
headerView.tag = section
|
||||||
headerView.disclosureExpanded = navState.expandedNodes.contains(sectionNode)
|
headerView.disclosureExpanded = navState.isExpanded(sectionNode)
|
||||||
|
|
||||||
let tap = UITapGestureRecognizer(target: self, action:#selector(self.toggleSectionHeader(_:)))
|
let tap = UITapGestureRecognizer(target: self, action:#selector(self.toggleSectionHeader(_:)))
|
||||||
headerView.addGestureRecognizer(tap)
|
headerView.addGestureRecognizer(tap)
|
||||||
|
@ -275,7 +275,7 @@ class MasterViewController: UITableViewController, UndoableCommandRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is a folder and isn't expanded or doesn't have any entries, let the users drop on it
|
// If this is a folder and isn't expanded or doesn't have any entries, let the users drop on it
|
||||||
if destNode.representedObject is Folder && (destNode.numberOfChildNodes == 0 || !navState.expandedNodes.contains(destNode)) {
|
if destNode.representedObject is Folder && (destNode.numberOfChildNodes == 0 || !navState.isExpanded(destNode)) {
|
||||||
let movementAdjustment = sourceIndexPath > destIndexPath ? 1 : 0
|
let movementAdjustment = sourceIndexPath > destIndexPath ? 1 : 0
|
||||||
return IndexPath(row: destIndexPath.row + movementAdjustment, section: destIndexPath.section)
|
return IndexPath(row: destIndexPath.row + movementAdjustment, section: destIndexPath.section)
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ class MasterViewController: UITableViewController, UndoableCommandRunner {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if navState.expandedNodes.contains(sectionNode) {
|
if navState.isExpanded(sectionNode) {
|
||||||
headerView.disclosureExpanded = false
|
headerView.disclosureExpanded = false
|
||||||
navState.collapse(section: sectionIndex) { [weak self] indexPaths in
|
navState.collapse(section: sectionIndex) { [weak self] indexPaths in
|
||||||
self?.tableView.beginUpdates()
|
self?.tableView.beginUpdates()
|
||||||
|
@ -486,7 +486,7 @@ class MasterViewController: UITableViewController, UndoableCommandRunner {
|
||||||
} else {
|
} else {
|
||||||
cell.indentationLevel = 0
|
cell.indentationLevel = 0
|
||||||
}
|
}
|
||||||
cell.disclosureExpanded = navState.expandedNodes.contains(node)
|
cell.disclosureExpanded = navState.isExpanded(node)
|
||||||
cell.allowDisclosureSelection = node.canHaveChildNodes
|
cell.allowDisclosureSelection = node.canHaveChildNodes
|
||||||
|
|
||||||
cell.name = nameFor(node)
|
cell.name = nameFor(node)
|
||||||
|
@ -534,13 +534,13 @@ class MasterViewController: UITableViewController, UndoableCommandRunner {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
navState.animatingChanges = true
|
navState.beginUpdates()
|
||||||
|
|
||||||
runCommand(deleteCommand)
|
runCommand(deleteCommand)
|
||||||
navState.rebuildShadowTable()
|
navState.rebuildShadowTable()
|
||||||
tableView.deleteRows(at: [indexPath], with: .automatic)
|
tableView.deleteRows(at: [indexPath], with: .automatic)
|
||||||
|
|
||||||
navState.animatingChanges = false
|
navState.endUpdates()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,9 @@ class NavigationStateController {
|
||||||
|
|
||||||
private var articleRowMap = [String: Int]() // articleID: rowIndex
|
private var articleRowMap = [String: Int]() // articleID: rowIndex
|
||||||
|
|
||||||
// Eventually I want these to be private too -Maurice
|
private var animatingChanges = false
|
||||||
var animatingChanges = false
|
private var expandedNodes = [Node]()
|
||||||
var expandedNodes = [Node]()
|
private var shadowTable = [[Node]]()
|
||||||
var shadowTable = [[Node]]()
|
|
||||||
|
|
||||||
private var sortDirection = AppDefaults.timelineSortDirection {
|
private var sortDirection = AppDefaults.timelineSortDirection {
|
||||||
didSet {
|
didSet {
|
||||||
|
@ -49,6 +48,10 @@ class NavigationStateController {
|
||||||
return treeController.rootNode
|
return treeController.rootNode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var numberOfSections: Int {
|
||||||
|
return shadowTable.count
|
||||||
|
}
|
||||||
|
|
||||||
var showFeedNames = false {
|
var showFeedNames = false {
|
||||||
didSet {
|
didSet {
|
||||||
NotificationCenter.default.post(name: .ShowFeedNamesDidChange, object: self, userInfo: nil)
|
NotificationCenter.default.post(name: .ShowFeedNamesDidChange, object: self, userInfo: nil)
|
||||||
|
@ -179,6 +182,18 @@ class NavigationStateController {
|
||||||
|
|
||||||
// MARK: API
|
// MARK: API
|
||||||
|
|
||||||
|
func beginUpdates() {
|
||||||
|
animatingChanges = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func endUpdates() {
|
||||||
|
animatingChanges = false
|
||||||
|
}
|
||||||
|
|
||||||
|
func rowsInSection(_ section: Int) -> Int {
|
||||||
|
return shadowTable[section].count
|
||||||
|
}
|
||||||
|
|
||||||
func rebuildBackingStores() {
|
func rebuildBackingStores() {
|
||||||
if !animatingChanges && !BatchUpdate.shared.isPerforming {
|
if !animatingChanges && !BatchUpdate.shared.isPerforming {
|
||||||
treeController.rebuild()
|
treeController.rebuild()
|
||||||
|
@ -210,6 +225,10 @@ class NavigationStateController {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isExpanded(_ node: Node) -> Bool {
|
||||||
|
return expandedNodes.contains(node)
|
||||||
|
}
|
||||||
|
|
||||||
func nodeFor(_ indexPath: IndexPath) -> Node? {
|
func nodeFor(_ indexPath: IndexPath) -> Node? {
|
||||||
guard indexPath.section < shadowTable.count || indexPath.row < shadowTable[indexPath.section].count else {
|
guard indexPath.section < shadowTable.count || indexPath.row < shadowTable[indexPath.section].count else {
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue