Add mark all as read for feed functionality
This commit is contained in:
parent
40a80356f1
commit
de7970314d
|
@ -52,6 +52,10 @@ struct AppAssets {
|
|||
return RSImage(named: "feedImage")!
|
||||
}()
|
||||
|
||||
static var markAllInFeedAsReadImage: UIImage = {
|
||||
return UIImage(systemName: "asterisk.circle")!
|
||||
}()
|
||||
|
||||
static var markOlderAsReadDownImage: UIImage = {
|
||||
return UIImage(systemName: "arrowtriangle.down.circle")!
|
||||
}()
|
||||
|
|
|
@ -531,27 +531,24 @@ class AppCoordinator: NSObject, UndoableCommandRunner {
|
|||
|
||||
}
|
||||
|
||||
func markAllAsRead(_ articles: [Article]) {
|
||||
guard let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: articles, markingRead: true, undoManager: undoManager) else {
|
||||
return
|
||||
}
|
||||
runCommand(markReadCommand)
|
||||
}
|
||||
|
||||
func markAllAsRead() {
|
||||
let accounts = AccountManager.shared.activeAccounts
|
||||
var articles = Set<Article>()
|
||||
accounts.forEach { account in
|
||||
articles.formUnion(account.fetchArticles(.unread))
|
||||
}
|
||||
|
||||
guard let undoManager = undoManager,
|
||||
let markReadCommand = MarkStatusCommand(initialArticles: Array(articles), markingRead: true, undoManager: undoManager) else {
|
||||
return
|
||||
}
|
||||
|
||||
runCommand(markReadCommand)
|
||||
markAllAsRead(Array(articles))
|
||||
}
|
||||
|
||||
|
||||
func markAllAsReadInTimeline() {
|
||||
guard let undoManager = undoManager,
|
||||
let markReadCommand = MarkStatusCommand(initialArticles: articles, markingRead: true, undoManager: undoManager) else {
|
||||
return
|
||||
}
|
||||
runCommand(markReadCommand)
|
||||
markAllAsRead(articles)
|
||||
masterNavigationController.popViewController(animated: true)
|
||||
}
|
||||
|
||||
|
@ -561,11 +558,7 @@ class AppCoordinator: NSObject, UndoableCommandRunner {
|
|||
if articlesToMark.isEmpty {
|
||||
return
|
||||
}
|
||||
|
||||
guard let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: articlesToMark, markingRead: true, undoManager: undoManager) else {
|
||||
return
|
||||
}
|
||||
runCommand(markReadCommand)
|
||||
markAllAsRead(articles)
|
||||
}
|
||||
|
||||
func toggleReadForCurrentArticle() {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue