fix mark all as read context menu on Accounts

This commit is contained in:
Rizwan Mohamed Ibrahim 2020-07-01 12:30:39 +05:30
parent 4ed6ccd52b
commit 687b454cd7
No known key found for this signature in database
GPG Key ID: D5BEE468D448BCC5
1 changed files with 13 additions and 5 deletions

View File

@ -547,7 +547,7 @@ extension MasterFeedViewController: UIContextMenuInteractionDelegate {
var actions = [accountInfoAction, deactivateAction]
if let markAllAction = self.markAllAsReadAction(account: account) {
if let markAllAction = self.markAllAsReadAction(account: account, contentView: interaction.view) {
actions.insert(markAllAction, at: 1)
}
@ -1064,23 +1064,31 @@ private extension MasterFeedViewController {
return markAllAsReadAction(articles: articles, nameForDisplay: articleFetcher.nameForDisplay, indexPath: indexPath)
}
func markAllAsReadAction(account: Account) -> UIAction? {
func markAllAsReadAction(account: Account, contentView: UIView?) -> UIAction? {
guard let fetchedArticles = try? account.fetchArticles(FetchType.unread) else {
return nil
}
let articles = Array(fetchedArticles)
return markAllAsReadAction(articles: articles, nameForDisplay: account.nameForDisplay)
return markAllAsReadAction(articles: articles, nameForDisplay: account.nameForDisplay, contentView: contentView)
}
func markAllAsReadAction(articles: [Article], nameForDisplay: String, indexPath: IndexPath? = nil) -> UIAction? {
guard articles.canMarkAllAsRead(), let indexPath = indexPath, let contentView = self.tableView.cellForRow(at: indexPath)?.contentView else {
guard let indexPath = indexPath,
let contentView = self.tableView.cellForRow(at: indexPath)?.contentView else {
return nil
}
return markAllAsReadAction(articles: articles, nameForDisplay: nameForDisplay, contentView: contentView)
}
func markAllAsReadAction(articles: [Article], nameForDisplay: String, contentView: UIView?) -> UIAction? {
guard articles.canMarkAllAsRead(), let contentView = contentView else {
return nil
}
let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Command")
let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, nameForDisplay) as String
let action = UIAction(title: title, image: AppAssets.markAllAsReadImage) { [weak self] action in
MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in
self?.coordinator.markAllAsRead(articles)