From 7e14f8bcd346e65118895fbeb688387d2f2302c5 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Wed, 17 Apr 2019 13:35:16 -0500 Subject: [PATCH] Reduced the Master (feeds) controller down to one controller. --- NetNewsWire.xcodeproj/project.pbxproj | 8 -- iOS/Base.lproj/Main.storyboard | 61 ++------------- iOS/Master/MasterPrimaryViewController.swift | 64 ---------------- .../MasterSecondaryViewController.swift | 74 ------------------- iOS/Master/MasterViewController.swift | 59 ++++++++++++--- 5 files changed, 55 insertions(+), 211 deletions(-) delete mode 100644 iOS/Master/MasterPrimaryViewController.swift delete mode 100644 iOS/Master/MasterSecondaryViewController.swift diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 53042c792..9dfcc4ec9 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -40,8 +40,6 @@ 51C4525A226508D600C03939 /* UIStoryboard-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51C4524E226506F400C03939 /* UIStoryboard-Extensions.swift */; }; 51C4525B226508DA00C03939 /* UIImage-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51C4524F226506F400C03939 /* UIImage-Extensions.swift */; }; 51C4525C226508DF00C03939 /* String-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51C45250226506F400C03939 /* String-Extensions.swift */; }; - 51C45266226508F600C03939 /* MasterSecondaryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51C4525E226508F600C03939 /* MasterSecondaryViewController.swift */; }; - 51C45267226508F600C03939 /* MasterPrimaryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51C4525F226508F600C03939 /* MasterPrimaryViewController.swift */; }; 51C45268226508F600C03939 /* MasterUnreadCountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51C45261226508F600C03939 /* MasterUnreadCountView.swift */; }; 51C45269226508F600C03939 /* MasterTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51C45262226508F600C03939 /* MasterTableViewCell.swift */; }; 51C4526A226508F600C03939 /* MasterTableViewCellLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51C45263226508F600C03939 /* MasterTableViewCellLayout.swift */; }; @@ -610,8 +608,6 @@ 51C45250226506F400C03939 /* String-Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String-Extensions.swift"; sourceTree = ""; }; 51C45254226507D200C03939 /* AppAssets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppAssets.swift; sourceTree = ""; }; 51C45255226507D200C03939 /* AppDefaults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDefaults.swift; sourceTree = ""; }; - 51C4525E226508F600C03939 /* MasterSecondaryViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MasterSecondaryViewController.swift; sourceTree = ""; }; - 51C4525F226508F600C03939 /* MasterPrimaryViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MasterPrimaryViewController.swift; sourceTree = ""; }; 51C45261226508F600C03939 /* MasterUnreadCountView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MasterUnreadCountView.swift; sourceTree = ""; }; 51C45262226508F600C03939 /* MasterTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MasterTableViewCell.swift; sourceTree = ""; }; 51C45263226508F600C03939 /* MasterTableViewCellLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MasterTableViewCellLayout.swift; sourceTree = ""; }; @@ -904,8 +900,6 @@ 51C4525D226508F600C03939 /* Master */ = { isa = PBXGroup; children = ( - 51C4525E226508F600C03939 /* MasterSecondaryViewController.swift */, - 51C4525F226508F600C03939 /* MasterPrimaryViewController.swift */, 51C45264226508F600C03939 /* MasterViewController.swift */, 51C45265226508F600C03939 /* MasterTreeControllerDelegate.swift */, 51C45260226508F600C03939 /* Cell */, @@ -2155,7 +2149,6 @@ 51C45258226508CF00C03939 /* AppAssets.swift in Sources */, 51C4527C2265091600C03939 /* MasterTimelineCellLayout.swift in Sources */, 51C4529A22650A0400C03939 /* ArticleStyle.swift in Sources */, - 51C45267226508F600C03939 /* MasterPrimaryViewController.swift in Sources */, 51C4527F2265092C00C03939 /* DetailViewController.swift in Sources */, 51C4526A226508F600C03939 /* MasterTableViewCellLayout.swift in Sources */, 51C452AE2265104D00C03939 /* TimelineStringFormatter.swift in Sources */, @@ -2181,7 +2174,6 @@ 51C452782265091600C03939 /* MasterTimelineCellData.swift in Sources */, 51C45259226508D300C03939 /* AppDefaults.swift in Sources */, 51C45293226509C800C03939 /* StarredFeedDelegate.swift in Sources */, - 51C45266226508F600C03939 /* MasterSecondaryViewController.swift in Sources */, 51C45298226509E600C03939 /* OPMLImporter.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/iOS/Base.lproj/Main.storyboard b/iOS/Base.lproj/Main.storyboard index 2b4a9e2e9..6509a672f 100644 --- a/iOS/Base.lproj/Main.storyboard +++ b/iOS/Base.lproj/Main.storyboard @@ -13,7 +13,7 @@ - + @@ -28,7 +28,7 @@ - + @@ -91,7 +91,7 @@ - + @@ -131,7 +131,7 @@ - + @@ -151,7 +151,7 @@ - + @@ -170,7 +170,7 @@ - + @@ -215,52 +215,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -276,7 +231,7 @@ - + diff --git a/iOS/Master/MasterPrimaryViewController.swift b/iOS/Master/MasterPrimaryViewController.swift deleted file mode 100644 index 23b78396b..000000000 --- a/iOS/Master/MasterPrimaryViewController.swift +++ /dev/null @@ -1,64 +0,0 @@ -// -// MasterPrimaryViewController.swift -// NetNewsWire -// -// Created by Maurice Parker on 4/8/19. -// Copyright © 2019 Ranchero Software. All rights reserved. -// - -import UIKit -import Account -import RSCore -import RSTree - -class MasterPrimaryViewController: MasterViewController { - - // MARK: - Table View - - override func numberOfSections(in tableView: UITableView) -> Int { - return treeController.rootNode.numberOfChildNodes - } - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return treeController.rootNode.childAtIndex(section)?.numberOfChildNodes ?? 0 - } - - override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { - guard let nameProvider = treeController.rootNode.childAtIndex(section)?.representedObject as? DisplayNameProvider else { - return nil - } - return nameProvider.nameForDisplay - } - - // MARK: API - - override func delete(indexPath: IndexPath) { - - guard let containerNode = treeController.rootNode.childAtIndex(indexPath.section), - let deleteNode = containerNode.childAtIndex(indexPath.row), - let container = containerNode.representedObject as? Container else { - return - } - - animatingChanges = true - - if let feed = deleteNode.representedObject as? Feed { - container.deleteFeed(feed) - } - - if let folder = deleteNode.representedObject as? Folder { - container.deleteFolder(folder) - } - - treeController.rebuild() - tableView.deleteRows(at: [indexPath], with: .automatic) - - animatingChanges = false - - } - - override func nodeFor(indexPath: IndexPath) -> Node? { - return treeController.rootNode.childAtIndex(indexPath.section)?.childAtIndex(indexPath.row) - } - -} diff --git a/iOS/Master/MasterSecondaryViewController.swift b/iOS/Master/MasterSecondaryViewController.swift deleted file mode 100644 index 59cbebabb..000000000 --- a/iOS/Master/MasterSecondaryViewController.swift +++ /dev/null @@ -1,74 +0,0 @@ -// -// MasterSecondaryViewController.swift -// NetNewsWire -// -// Created by Maurice Parker on 4/8/19. -// Copyright © 2019 Ranchero Software. All rights reserved. -// - -import UIKit -import Account -import RSCore -import RSTree - -class MasterSecondaryViewController: MasterViewController { - - var viewRootNode: Node? - - // MARK: - Table View - - override func numberOfSections(in tableView: UITableView) -> Int { - return 1 - } - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return viewRootNode?.numberOfChildNodes ?? 0 - } - - override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { - - if editingStyle == .delete { - - guard let containerNode = viewRootNode, - let deleteNode = containerNode.childAtIndex(indexPath.row), - let container = containerNode.representedObject as? Container, - let feed = deleteNode.representedObject as? Feed else { - return - } - - animatingChanges = true - container.deleteFeed(feed) - treeController.rebuild() - tableView.deleteRows(at: [indexPath], with: .fade) - animatingChanges = false - - } else if editingStyle == .insert { - // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. - } - - } - - // MARK: API - - override func delete(indexPath: IndexPath) { - - guard let containerNode = viewRootNode, - let deleteNode = containerNode.childAtIndex(indexPath.row), - let container = containerNode.representedObject as? Container, - let feed = deleteNode.representedObject as? Feed else { - return - } - - animatingChanges = true - container.deleteFeed(feed) - treeController.rebuild() - tableView.deleteRows(at: [indexPath], with: .fade) - animatingChanges = false - - } - - override func nodeFor(indexPath: IndexPath) -> Node? { - return viewRootNode?.childAtIndex(indexPath.row) - } - -} diff --git a/iOS/Master/MasterViewController.swift b/iOS/Master/MasterViewController.swift index 6984457bf..ee276c2b5 100644 --- a/iOS/Master/MasterViewController.swift +++ b/iOS/Master/MasterViewController.swift @@ -60,6 +60,8 @@ class MasterViewController: UITableViewController, UndoableCommandRunner { super.viewWillDisappear(animated) resignFirstResponder() } + + // MARK: Notifications @objc private func refreshAccounts(_ sender: Any) { AccountManager.shared.refreshAll() @@ -117,6 +119,21 @@ class MasterViewController: UITableViewController, UndoableCommandRunner { // MARK: Table View + override func numberOfSections(in tableView: UITableView) -> Int { + return treeController.rootNode.numberOfChildNodes + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return treeController.rootNode.childAtIndex(section)?.numberOfChildNodes ?? 0 + } + + override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + guard let nameProvider = treeController.rootNode.childAtIndex(section)?.representedObject as? DisplayNameProvider else { + return nil + } + return nameProvider.nameForDisplay + } + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! MasterTableViewCell @@ -168,27 +185,25 @@ class MasterViewController: UITableViewController, UndoableCommandRunner { return } + let timeline = UIStoryboard.main.instantiateController(ofType: MasterTimelineViewController.self) + if let pseudoFeed = node.representedObject as? PseudoFeed { - let timeline = UIStoryboard.main.instantiateController(ofType: MasterTimelineViewController.self) timeline.title = pseudoFeed.nameForDisplay timeline.representedObjects = [pseudoFeed] - self.navigationController?.pushViewController(timeline, animated: true) } if let folder = node.representedObject as? Folder { - let secondary = UIStoryboard.main.instantiateController(ofType: MasterSecondaryViewController.self) - secondary.title = folder.nameForDisplay - secondary.viewRootNode = node - self.navigationController?.pushViewController(secondary, animated: true) + timeline.title = folder.nameForDisplay + timeline.representedObjects = [folder] } if let feed = node.representedObject as? Feed { - let timeline = UIStoryboard.main.instantiateController(ofType: MasterTimelineViewController.self) timeline.title = feed.nameForDisplay timeline.representedObjects = [feed] - self.navigationController?.pushViewController(timeline, animated: true) } + self.navigationController?.pushViewController(timeline, animated: true) + } // MARK: Actions @@ -324,9 +339,30 @@ class MasterViewController: UITableViewController, UndoableCommandRunner { } func delete(indexPath: IndexPath) { - assertionFailure() + + guard let containerNode = treeController.rootNode.childAtIndex(indexPath.section), + let deleteNode = containerNode.childAtIndex(indexPath.row), + let container = containerNode.representedObject as? Container else { + return + } + + animatingChanges = true + + if let feed = deleteNode.representedObject as? Feed { + container.deleteFeed(feed) + } + + if let folder = deleteNode.representedObject as? Folder { + container.deleteFolder(folder) + } + + treeController.rebuild() + tableView.deleteRows(at: [indexPath], with: .automatic) + + animatingChanges = false + } - + func rename(indexPath: IndexPath) { let name = (nodeFor(indexPath: indexPath)?.representedObject as? DisplayNameProvider)?.nameForDisplay ?? "" @@ -368,8 +404,7 @@ class MasterViewController: UITableViewController, UndoableCommandRunner { } func nodeFor(indexPath: IndexPath) -> Node? { - assertionFailure() - return nil + return treeController.rootNode.childAtIndex(indexPath.section)?.childAtIndex(indexPath.row) } }