Add Select Feed context menu

This commit is contained in:
Maurice Parker 2019-08-19 15:45:52 -05:00
parent 2cc5e20fad
commit 3245223b24
4 changed files with 89 additions and 27 deletions

View File

@ -64,10 +64,18 @@ struct AppAssets {
return UIImage(systemName: "folder.fill")! return UIImage(systemName: "folder.fill")!
}() }()
static var moreImage: UIImage = {
return UIImage(systemName: "ellipsis.circle")!
}()
static var netNewsWireBlueColor: UIColor = { static var netNewsWireBlueColor: UIColor = {
return UIColor(named: "netNewsWireBlueColor")! return UIColor(named: "netNewsWireBlueColor")!
}() }()
static var openInSidebarImage: UIImage = {
return UIImage(systemName: "arrow.turn.down.left")!
}()
static var safariImage: UIImage = { static var safariImage: UIImage = {
return UIImage(systemName: "safari")! return UIImage(systemName: "safari")!
}() }()

View File

@ -567,6 +567,11 @@ class AppCoordinator: NSObject, UndoableCommandRunner {
} }
} }
func discloseFeed(_ feed: Feed) {
masterNavigationController.popViewController(animated: true)
masterFeedViewController.discloseFeed(feed)
}
func showSettings() { func showSettings() {
let settingsNavViewController = UIStoryboard.settings.instantiateInitialViewController() as! UINavigationController let settingsNavViewController = UIStoryboard.settings.instantiateInitialViewController() as! UINavigationController
settingsNavViewController.modalPresentationStyle = .formSheet settingsNavViewController.modalPresentationStyle = .formSheet

View File

@ -121,32 +121,10 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
} }
@objc func userDidAddFeed(_ notification: Notification) { @objc func userDidAddFeed(_ notification: Notification) {
guard let feed = notification.userInfo?[UserInfoKey.feed] as? Feed else {
guard let feed = notification.userInfo?[UserInfoKey.feed],
let node = coordinator.rootNode.descendantNodeRepresentingObject(feed as AnyObject) else {
return return
} }
discloseFeed(feed)
if let indexPath = coordinator.indexPathFor(node) {
tableView.scrollToRow(at: indexPath, at: .middle, animated: true)
return
}
// It wasn't already visable, so expand its folder and try again
guard let parent = node.parent, let indexPath = coordinator.indexPathFor(parent) else {
return
}
coordinator.expand(indexPath) { [weak self] indexPaths in
self?.tableView.beginUpdates()
self?.tableView.insertRows(at: indexPaths, with: .automatic)
self?.tableView.endUpdates()
}
if let indexPath = coordinator.indexPathFor(node) {
tableView.scrollToRow(at: indexPath, at: .middle, animated: true)
}
} }
@objc func accountsDidChange(_ notification: Notification) { @objc func accountsDidChange(_ notification: Notification) {
@ -511,6 +489,39 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
} }
} }
// MARK: API
func discloseFeed(_ feed: Feed) {
guard let node = coordinator.rootNode.descendantNodeRepresentingObject(feed as AnyObject) else {
return
}
if let indexPath = coordinator.indexPathFor(node) {
tableView.scrollToRow(at: indexPath, at: .middle, animated: true)
coordinator.selectFeed(indexPath)
return
}
// It wasn't already visable, so expand its folder and try again
guard let parent = node.parent, let indexPath = coordinator.indexPathFor(parent) else {
return
}
coordinator.expand(indexPath) { [weak self] indexPaths in
self?.tableView.beginUpdates()
tableView.reloadRows(at: [indexPath], with: .automatic)
self?.tableView.insertRows(at: indexPaths, with: .automatic)
self?.tableView.endUpdates()
}
if let indexPath = coordinator.indexPathFor(node) {
tableView.scrollToRow(at: indexPath, at: .middle, animated: true)
coordinator.selectFeed(indexPath)
}
}
} }
// MARK: MasterTableViewCellDelegate // MARK: MasterTableViewCellDelegate
@ -644,7 +655,9 @@ private extension MasterFeedViewController {
} }
func makeFeedContextMenu(indexPath: IndexPath, includeDeleteRename: Bool) -> UIContextMenuConfiguration { func makeFeedContextMenu(indexPath: IndexPath, includeDeleteRename: Bool) -> UIContextMenuConfiguration {
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: { suggestedActions in return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: { [ weak self] suggestedActions in
guard let self = self else { return nil }
var actions = [UIAction]() var actions = [UIAction]()
@ -673,7 +686,9 @@ private extension MasterFeedViewController {
} }
func makeFolderContextMenu(indexPath: IndexPath) -> UIContextMenuConfiguration { func makeFolderContextMenu(indexPath: IndexPath) -> UIContextMenuConfiguration {
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: { suggestedActions in return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: { [weak self] suggestedActions in
guard let self = self else { return nil }
var actions = [UIAction]() var actions = [UIAction]()
actions.append(self.deleteAction(indexPath: indexPath)) actions.append(self.deleteAction(indexPath: indexPath))

View File

@ -164,6 +164,10 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
alert.addAction(self.markOlderAsReadAlertAction(indexPath: indexPath, completionHandler: completionHandler)) alert.addAction(self.markOlderAsReadAlertAction(indexPath: indexPath, completionHandler: completionHandler))
if let action = self.discloseFeedAlertAction(indexPath: indexPath, completionHandler: completionHandler) {
alert.addAction(action)
}
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel") let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
alert.addAction(UIAlertAction(title: cancelTitle, style: .cancel) { _ in alert.addAction(UIAlertAction(title: cancelTitle, style: .cancel) { _ in
completionHandler(true) completionHandler(true)
@ -175,6 +179,7 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
} }
moreAction.image = AppAssets.moreImage
moreAction.backgroundColor = UIColor.systemGray moreAction.backgroundColor = UIColor.systemGray
let configuration = UISwipeActionsConfiguration(actions: [readAction, starAction, moreAction]) let configuration = UISwipeActionsConfiguration(actions: [readAction, starAction, moreAction])
@ -184,13 +189,19 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? { override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: { suggestedActions in return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: { [weak self] suggestedActions in
guard let self = self else { return nil }
var actions = [UIAction]() var actions = [UIAction]()
actions.append(self.toggleArticleReadStatusAction(indexPath: indexPath)) actions.append(self.toggleArticleReadStatusAction(indexPath: indexPath))
actions.append(self.toggleArticleStarStatusAction(indexPath: indexPath)) actions.append(self.toggleArticleStarStatusAction(indexPath: indexPath))
actions.append(self.markOlderAsReadAction(indexPath: indexPath)) actions.append(self.markOlderAsReadAction(indexPath: indexPath))
if let action = self.discloseFeedAction(indexPath: indexPath) {
actions.append(action)
}
let title = NSLocalizedString("Timeline Menu", comment: "Timeline Menu") let title = NSLocalizedString("Timeline Menu", comment: "Timeline Menu")
return UIMenu(title: title, children: actions) return UIMenu(title: title, children: actions)
@ -559,4 +570,27 @@ private extension MasterTimelineViewController {
return action return action
} }
func discloseFeedAction(indexPath: IndexPath) -> UIAction? {
guard let feed = coordinator.articles[indexPath.row].feed else {
return nil
}
let title = NSLocalizedString("Select Feed", comment: "Select Feed")
let action = UIAction(title: title, image: AppAssets.openInSidebarImage) { [weak self] action in
self?.coordinator.discloseFeed(feed)
}
return action
}
func discloseFeedAlertAction(indexPath: IndexPath, completionHandler: @escaping (Bool) -> Void) -> UIAlertAction? {
guard let feed = coordinator.articles[indexPath.row].feed else {
return nil
}
let title = NSLocalizedString("Select Feed", comment: "Select Feed")
let action = UIAlertAction(title: title, style: .default) { [weak self] action in
self?.coordinator.discloseFeed(feed)
completionHandler(true)
}
return action
}
} }