Add mark all as read for feed functionality

This commit is contained in:
Maurice Parker
2019-08-19 17:26:09 -05:00
parent 40a80356f1
commit de7970314d
3 changed files with 62 additions and 18 deletions

View File

@@ -168,6 +168,10 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
alert.addAction(action)
}
if let action = self.markAllInFeedAsReadAlertAction(indexPath: indexPath, completionHandler: completionHandler) {
alert.addAction(action)
}
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
alert.addAction(UIAlertAction(title: cancelTitle, style: .cancel) { _ in
completionHandler(true)
@@ -202,6 +206,10 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
actions.append(action)
}
if let action = self.markAllInFeedAsReadAction(indexPath: indexPath) {
actions.append(action)
}
return UIMenu(title: "", children: actions)
})
@@ -562,4 +570,43 @@ private extension MasterTimelineViewController {
return action
}
func markAllInFeedAsReadAction(indexPath: IndexPath) -> UIAction? {
guard let feed = coordinator.articles[indexPath.row].feed else {
return nil
}
let articles = Array(feed.fetchArticles())
guard articles.canMarkAllAsRead() else {
return nil
}
let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Command")
let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) as String
let action = UIAction(title: title, image: AppAssets.markAllInFeedAsReadImage) { [weak self] action in
self?.coordinator.markAllAsRead(articles)
}
return action
}
func markAllInFeedAsReadAlertAction(indexPath: IndexPath, completionHandler: @escaping (Bool) -> Void) -> UIAlertAction? {
guard let feed = coordinator.articles[indexPath.row].feed else {
return nil
}
let articles = Array(feed.fetchArticles())
guard articles.canMarkAllAsRead() else {
return nil
}
let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Command")
let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) as String
let action = UIAlertAction(title: title, style: .default) { [weak self] action in
self?.coordinator.markAllAsRead(articles)
completionHandler(true)
}
return action
}
}