Replace “Mark Older as Read” actions with “Mark Above/Below as Read” actions

This commit is contained in:
Martin Hartl 2020-01-03 08:16:55 +01:00
parent e26a00ddfe
commit 5ee491ebee
5 changed files with 100 additions and 27 deletions

View File

@ -117,11 +117,11 @@ struct AppAssets {
return UIImage(systemName: "asterisk.circle")! return UIImage(systemName: "asterisk.circle")!
}() }()
static var markOlderAsReadDownImage: UIImage = { static var markBelowAsReadImage: UIImage = {
return UIImage(systemName: "arrowtriangle.down.circle")! return UIImage(systemName: "arrowtriangle.down.circle")!
}() }()
static var markOlderAsReadUpImage: UIImage = { static var markAboveAsReadImage: UIImage = {
return UIImage(systemName: "arrowtriangle.up.circle")! return UIImage(systemName: "arrowtriangle.up.circle")!
}() }()

View File

@ -168,8 +168,8 @@ private extension KeyboardManager {
let toggleReadTitle = NSLocalizedString("Toggle Read Status", comment: "Toggle Read Status") let toggleReadTitle = NSLocalizedString("Toggle Read Status", comment: "Toggle Read Status")
keys.append(KeyboardManager.createKeyCommand(title: toggleReadTitle, action: "toggleRead:", input: "u", modifiers: [.command, .shift])) keys.append(KeyboardManager.createKeyCommand(title: toggleReadTitle, action: "toggleRead:", input: "u", modifiers: [.command, .shift]))
let markOlderAsReadTitle = NSLocalizedString("Mark Older as Read", comment: "Mark Older as Read") let markOlderAsReadTitle = NSLocalizedString("Mark Below as Read", comment: "Mark Below as Read")
keys.append(KeyboardManager.createKeyCommand(title: markOlderAsReadTitle, action: "markOlderArticlesAsRead:", input: "k", modifiers: [.command, .shift])) keys.append(KeyboardManager.createKeyCommand(title: markOlderAsReadTitle, action: "markBelowAsRead:", input: "k", modifiers: [.command, .shift]))
let toggleStarredTitle = NSLocalizedString("Toggle Starred Status", comment: "Toggle Starred Status") let toggleStarredTitle = NSLocalizedString("Toggle Starred Status", comment: "Toggle Starred Status")
keys.append(KeyboardManager.createKeyCommand(title: toggleStarredTitle, action: "toggleStarred:", input: "l", modifiers: [.command, .shift])) keys.append(KeyboardManager.createKeyCommand(title: toggleStarredTitle, action: "toggleStarred:", input: "l", modifiers: [.command, .shift]))

View File

@ -246,7 +246,13 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
popoverController.sourceRect = CGRect(x: view.frame.size.width/2, y: view.frame.size.height/2, width: 1, height: 1) popoverController.sourceRect = CGRect(x: view.frame.size.width/2, y: view.frame.size.height/2, width: 1, height: 1)
} }
alert.addAction(self.markOlderAsReadAlertAction(article, completion: completion)) if let action = self.markAboveAsReadAlertAction(article, completion: completion) {
alert.addAction(action)
}
if let action = self.markBelowAsReadAlertAction(article, completion: completion) {
alert.addAction(action)
}
if let action = self.discloseFeedAlertAction(article, completion: completion) { if let action = self.discloseFeedAlertAction(article, completion: completion) {
alert.addAction(action) alert.addAction(action)
@ -293,7 +299,14 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
var actions = [UIAction]() var actions = [UIAction]()
actions.append(self.toggleArticleReadStatusAction(article)) actions.append(self.toggleArticleReadStatusAction(article))
actions.append(self.toggleArticleStarStatusAction(article)) actions.append(self.toggleArticleStarStatusAction(article))
actions.append(self.markOlderAsReadAction(article))
if let action = self.markAboveAsReadAction(article) {
actions.append(action)
}
if let action = self.markBelowAsReadAction(article) {
actions.append(action)
}
if let action = self.discloseFeedAction(article) { if let action = self.discloseFeedAction(article) {
actions.append(action) actions.append(action)
@ -637,19 +650,53 @@ private extension MasterTimelineViewController {
return action return action
} }
func markOlderAsReadAction(_ article: Article) -> UIAction { func markAboveAsReadAction(_ article: Article) -> UIAction? {
let title = NSLocalizedString("Mark Older as Read", comment: "Mark Older as Read") guard coordinator.canMarkAboveAsRead(for: article) else {
let image = coordinator.sortDirection == .orderedDescending ? AppAssets.markOlderAsReadDownImage : AppAssets.markOlderAsReadUpImage return nil
}
let title = NSLocalizedString("Mark Above as Read", comment: "Mark Above as Read")
let image = AppAssets.markAboveAsReadImage
let action = UIAction(title: title, image: image) { [weak self] action in let action = UIAction(title: title, image: image) { [weak self] action in
self?.coordinator.markAsReadOlderArticlesInTimeline(article) self?.coordinator.markAboveAsRead(article)
} }
return action return action
} }
func markOlderAsReadAlertAction(_ article: Article, completion: @escaping (Bool) -> Void) -> UIAlertAction { func markBelowAsReadAction(_ article: Article) -> UIAction? {
let title = NSLocalizedString("Mark Older as Read", comment: "Mark Older as Read") guard coordinator.canMarkBelowAsRead(for: article) else {
return nil
}
let title = NSLocalizedString("Mark Below as Read", comment: "Mark Below as Read")
let image = AppAssets.markBelowAsReadImage
let action = UIAction(title: title, image: image) { [weak self] action in
self?.coordinator.markBelowAsRead(article)
}
return action
}
func markAboveAsReadAlertAction(_ article: Article, completion: @escaping (Bool) -> Void) -> UIAlertAction? {
guard coordinator.canMarkAboveAsRead(for: article) else {
return nil
}
let title = NSLocalizedString("Mark Above as Read", comment: "Mark Above as Read")
let action = UIAlertAction(title: title, style: .default) { [weak self] action in let action = UIAlertAction(title: title, style: .default) { [weak self] action in
self?.coordinator.markAsReadOlderArticlesInTimeline(article) self?.coordinator.markAboveAsRead(article)
completion(true)
}
return action
}
func markBelowAsReadAlertAction(_ article: Article, completion: @escaping (Bool) -> Void) -> UIAlertAction? {
guard coordinator.canMarkBelowAsRead(for: article) else {
return nil
}
let title = NSLocalizedString("Mark Below as Read", comment: "Mark Below as Read")
let action = UIAlertAction(title: title, style: .default) { [weak self] action in
self?.coordinator.markBelowAsRead(article)
completion(true) completion(true)
} }
return action return action

View File

@ -54,8 +54,8 @@ class RootSplitViewController: UISplitViewController {
coordinator.selectNextUnread() coordinator.selectNextUnread()
} }
@objc func markOlderArticlesAsRead(_ sender: Any?) { @objc func markBelowAsRead(_ sender: Any?) {
coordinator.markAsReadOlderArticlesInTimeline() coordinator.markBelowAsRead()
} }
@objc func markUnread(_ sender: Any?) { @objc func markUnread(_ sender: Any?) {

View File

@ -871,18 +871,44 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
masterNavigationController.popViewController(animated: true) masterNavigationController.popViewController(animated: true)
} }
func markAsReadOlderArticlesInTimeline() { func canMarkAboveAsRead(for article: Article) -> Bool {
if let article = currentArticle { return articles.first != article
markAsReadOlderArticlesInTimeline(article)
}
} }
func markAsReadOlderArticlesInTimeline(_ article: Article) { func markAboveAsRead(_ article: Article) {
let articlesToMark = articles.filter { $0.logicalDatePublished < article.logicalDatePublished } guard let position = articles.firstIndex(of: article) else {
if articlesToMark.isEmpty {
return return
} }
markAllAsRead(articlesToMark)
let articlesAbove = articles[..<position]
markAllAsRead(Array(articlesAbove))
}
func canMarkBelowAsRead(for article: Article) -> Bool {
return articles.last != article
}
func markBelowAsRead() {
guard let currentArticle = currentArticle else {
return
}
markBelowAsRead(currentArticle)
}
func markBelowAsRead(_ article: Article) {
guard let position = articles.firstIndex(of: article) else {
return
}
var articlesBelow = Array(articles[position...])
guard !articlesBelow.isEmpty else {
return
}
articlesBelow.removeFirst()
markAllAsRead(articlesBelow)
} }
func markAsReadForCurrentArticle() { func markAsReadForCurrentArticle() {