Only show mark unread above/below actions if articles above/below contained unread items

This commit is contained in:
Martin Hartl 2020-01-07 21:54:21 +01:00
parent 97b188bac3
commit 02ab44c3eb
2 changed files with 33 additions and 20 deletions

View File

@ -109,5 +109,30 @@ extension Array where Element == Article {
} }
return true return true
} }
func articlesAbove(article: Article) -> [Article] {
guard let position = firstIndex(of: article) else {
return []
}
let articlesAbove = self[..<position]
return Array(articlesAbove)
}
func articlesBelow(article: Article) -> [Article] {
guard let position = firstIndex(of: article) else {
return []
}
var articlesBelow = Array(self[position...])
guard !articlesBelow.isEmpty else {
return []
}
articlesBelow.removeFirst()
return articlesBelow
}
} }

View File

@ -872,7 +872,8 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
} }
func canMarkAboveAsRead(for article: Article) -> Bool { func canMarkAboveAsRead(for article: Article) -> Bool {
return articles.first != article let articlesAboveArray = articles.articlesAbove(article: article)
return articlesAboveArray.canMarkAllAsRead()
} }
func markAboveAsRead() { func markAboveAsRead() {
@ -884,16 +885,13 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
} }
func markAboveAsRead(_ article: Article) { func markAboveAsRead(_ article: Article) {
guard let position = articles.firstIndex(of: article) else { let articlesAboveArray = articles.articlesAbove(article: article)
return markAllAsRead(articlesAboveArray)
}
let articlesAbove = articles[..<position]
markAllAsRead(Array(articlesAbove))
} }
func canMarkBelowAsRead(for article: Article) -> Bool { func canMarkBelowAsRead(for article: Article) -> Bool {
return articles.last != article let articleBelowArray = articles.articlesBelow(article: article)
return articleBelowArray.canMarkAllAsRead()
} }
func markBelowAsRead() { func markBelowAsRead() {
@ -905,18 +903,8 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
} }
func markBelowAsRead(_ article: Article) { func markBelowAsRead(_ article: Article) {
guard let position = articles.firstIndex(of: article) else { let articleBelowArray = articles.articlesBelow(article: article)
return markAllAsRead(articleBelowArray)
}
var articlesBelow = Array(articles[position...])
guard !articlesBelow.isEmpty else {
return
}
articlesBelow.removeFirst()
markAllAsRead(articlesBelow)
} }
func markAsReadForCurrentArticle() { func markAsReadForCurrentArticle() {