From 38535910efb17ee8c929d5ded2efce09126af1a5 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Wed, 13 Nov 2019 15:22:22 -0600 Subject: [PATCH] Change Select Feed to Go to Feed. Issue #1240 --- iOS/MasterFeed/MasterFeedViewController.swift | 16 +++--- .../MasterTimelineViewController.swift | 10 ++-- iOS/SceneCoordinator.swift | 51 ++++++++++--------- 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index bdc953f6c..561a7ee20 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -65,11 +65,10 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { configureToolbar() becomeFirstResponder() + } override func viewWillAppear(_ animated: Bool) { - navigationController?.title = NSLocalizedString("Feeds", comment: "Feeds") - applyChanges(animate: false) updateUI() super.viewWillAppear(animated) } @@ -101,7 +100,10 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { } if let node = node, dataSource.indexPath(for: node) != nil { - reloadNode(node) + // This can stop the scrolling of the disclose function if we don't delay it enough to complete + DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) { + self.reloadNode(node) + } } } @@ -462,14 +464,14 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { } } - func updateFeedSelection() { + func updateFeedSelection(animated: Bool) { if dataSource.snapshot().numberOfItems > 0 { if let indexPath = coordinator.currentFeedIndexPath { if tableView.indexPathForSelectedRow != indexPath { - tableView.selectRowAndScrollIfNotVisible(at: indexPath, animated: true) + tableView.selectRowAndScrollIfNotVisible(at: indexPath, animated: animated) } } else { - tableView.selectRow(at: nil, animated: true, scrollPosition: .none) + tableView.selectRow(at: nil, animated: animated, scrollPosition: .none) } } } @@ -1022,7 +1024,7 @@ private extension MasterFeedViewController { deleteCommand.perform() if indexPath == coordinator.currentFeedIndexPath { - coordinator.selectFeed(nil) + coordinator.selectFeed(nil, animated: false) } } diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index 570f3bba4..6990a53a4 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -592,10 +592,9 @@ private extension MasterTimelineViewController { func discloseFeedAction(_ article: Article) -> UIAction? { guard let feed = article.feed else { return nil } - let title = NSLocalizedString("Select Feed", comment: "Select Feed") + let title = NSLocalizedString("Go to Feed", comment: "Go to Feed") let action = UIAction(title: title, image: AppAssets.openInSidebarImage) { [weak self] action in - self?.coordinator.selectFeed(nil, animated: true) - self?.coordinator.discloseFeed(feed, animated: true) + self?.coordinator.discloseFeed(feed, animated: false) } return action } @@ -603,10 +602,9 @@ private extension MasterTimelineViewController { func discloseFeedAlertAction(_ article: Article, completionHandler: @escaping (Bool) -> Void) -> UIAlertAction? { guard let feed = article.feed else { return nil } - let title = NSLocalizedString("Select Feed", comment: "Select Feed") + let title = NSLocalizedString("Go to Feed", comment: "Go to Feed") let action = UIAlertAction(title: title, style: .default) { [weak self] action in - self?.coordinator.selectFeed(nil, animated: true) - self?.coordinator.discloseFeed(feed, animated: true) + self?.coordinator.discloseFeed(feed, animated: false) completionHandler(true) } return action diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index e188f7370..5c9d46b61 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -89,9 +89,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { } private let treeControllerDelegate = FeedTreeControllerDelegate() - private lazy var treeController: TreeController = { - return TreeController(delegate: treeControllerDelegate) - }() + private let treeController: TreeController var stateRestorationActivity: NSUserActivity? { return activityManager.stateRestorationActivity @@ -280,6 +278,8 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { } override init() { + treeController = TreeController(delegate: treeControllerDelegate) + super.init() for section in treeController.rootNode.childNodes { @@ -315,6 +315,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { masterFeedViewController = UIStoryboard.main.instantiateController(ofType: MasterFeedViewController.self) masterFeedViewController.coordinator = self masterNavigationController.pushViewController(masterFeedViewController, animated: false) + masterFeedViewController.reloadFeeds() let articleViewController = UIStoryboard.main.instantiateController(ofType: ArticleViewController.self) articleViewController.coordinator = self @@ -327,7 +328,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { } func handle(_ activity: NSUserActivity) { - selectFeed(nil) + selectFeed(nil, animated: false) guard let activityType = ActivityType(rawValue: activity.activityType) else { return } switch activityType { @@ -371,12 +372,12 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { } func selectFirstUnreadInAllUnread() { - selectFeed(IndexPath(row: 1, section: 0)) + selectFeed(IndexPath(row: 1, section: 0), animated: false) selectFirstUnreadArticleInTimeline() } func showSearch() { - selectFeed(nil) + selectFeed(nil, animated: false) installTimelineControllerIfNecessary(animated: false) DispatchQueue.main.asyncAfter(deadline: .now()) { self.masterTimelineViewController!.showSearchAll() @@ -532,13 +533,13 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { return indexPathFor(node) } - func selectFeed(_ indexPath: IndexPath?, animated: Bool = false) { + func selectFeed(_ indexPath: IndexPath?, animated: Bool) { guard indexPath != currentFeedIndexPath else { return } selectArticle(nil) currentFeedIndexPath = indexPath - masterFeedViewController.updateFeedSelection() + masterFeedViewController.updateFeedSelection(animated: animated) if let ip = indexPath, let node = nodeFor(ip), let fetcher = node.representedObject as? ArticleFetcher { timelineFetcher = fetcher @@ -556,31 +557,31 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { func selectPrevFeed() { if let indexPath = prevFeedIndexPath { - selectFeed(indexPath) + selectFeed(indexPath, animated: true) } } func selectNextFeed() { if let indexPath = nextFeedIndexPath { - selectFeed(indexPath) + selectFeed(indexPath, animated: true) } } func selectTodayFeed() { masterFeedViewController?.ensureSectionIsExpanded(0) { - self.selectFeed(IndexPath(row: 0, section: 0)) + self.selectFeed(IndexPath(row: 0, section: 0), animated: true) } } func selectAllUnreadFeed() { masterFeedViewController?.ensureSectionIsExpanded(0) { - self.selectFeed(IndexPath(row: 1, section: 0)) + self.selectFeed(IndexPath(row: 1, section: 0), animated: true) } } func selectStarredFeed() { masterFeedViewController?.ensureSectionIsExpanded(0) { - self.selectFeed(IndexPath(row: 2, section: 0)) + self.selectFeed(IndexPath(row: 2, section: 0), animated: true) } } @@ -830,7 +831,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { } func showAdd(_ type: AddControllerType, initialFeed: String? = nil, initialFeedName: String? = nil) { - selectFeed(nil) + selectFeed(nil, animated: false) let addViewController = UIStoryboard.add.instantiateInitialViewController() as! UINavigationController @@ -969,7 +970,7 @@ extension SceneCoordinator: UINavigationControllerDelegate { // If we are showing the Feeds and only the feeds start clearing stuff if viewController === masterFeedViewController && !isThreePanelMode && !isTimelineViewControllerPending { activityManager.invalidateCurrentActivities() - selectFeed(nil) + selectFeed(nil, animated: true) return } @@ -1204,7 +1205,7 @@ private extension SceneCoordinator { } if unreadCountProvider.unreadCount > 0 { - selectFeed(prevIndexPath) + selectFeed(prevIndexPath, animated: true) return true } @@ -1310,7 +1311,7 @@ private extension SceneCoordinator { } if unreadCountProvider.unreadCount > 0 { - selectFeed(nextIndexPath) + selectFeed(nextIndexPath, animated: true) return true } @@ -1492,13 +1493,15 @@ private extension SceneCoordinator { // MARK: Double Split func installTimelineControllerIfNecessary(animated: Bool) { - - isTimelineViewControllerPending = true - if navControllerForTimeline().viewControllers.filter({ $0 is MasterTimelineViewController }).count < 1 { + + isTimelineViewControllerPending = true + masterTimelineViewController = UIStoryboard.main.instantiateController(ofType: MasterTimelineViewController.self) masterTimelineViewController!.coordinator = self navControllerForTimeline().pushViewController(masterTimelineViewController!, animated: animated) + + masterTimelineViewController?.reloadArticles(animate: false) } } @@ -1646,19 +1649,19 @@ private extension SceneCoordinator { func handleSelectToday() { if let indexPath = indexPathFor(SmartFeedsController.shared.todayFeed) { - selectFeed(indexPath) + selectFeed(indexPath, animated: false) } } func handleSelectAllUnread() { if let indexPath = indexPathFor(SmartFeedsController.shared.unreadFeed) { - selectFeed(indexPath) + selectFeed(indexPath, animated: false) } } func handleSelectStarred() { if let indexPath = indexPathFor(SmartFeedsController.shared.starredFeed) { - selectFeed(indexPath) + selectFeed(indexPath, animated: false) } } @@ -1667,7 +1670,7 @@ private extension SceneCoordinator { return } if let indexPath = indexPathFor(folderNode) { - selectFeed(indexPath) + selectFeed(indexPath, animated: false) } }