Merge pull request #1553 from hartlco/1548-mark-above-below-as-read-should-not-appear-if-nothing-to-mark
Only show mark unread above/below actions if articles above/below contain unread items
This commit is contained in:
commit
92cfbc767b
|
@ -109,5 +109,30 @@ extension Array where Element == Article {
|
|||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -872,7 +872,8 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
|||
}
|
||||
|
||||
func canMarkAboveAsRead(for article: Article) -> Bool {
|
||||
return articles.first != article
|
||||
let articlesAboveArray = articles.articlesAbove(article: article)
|
||||
return articlesAboveArray.canMarkAllAsRead()
|
||||
}
|
||||
|
||||
func markAboveAsRead() {
|
||||
|
@ -884,16 +885,13 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
|||
}
|
||||
|
||||
func markAboveAsRead(_ article: Article) {
|
||||
guard let position = articles.firstIndex(of: article) else {
|
||||
return
|
||||
}
|
||||
|
||||
let articlesAbove = articles[..<position]
|
||||
markAllAsRead(Array(articlesAbove))
|
||||
let articlesAboveArray = articles.articlesAbove(article: article)
|
||||
markAllAsRead(articlesAboveArray)
|
||||
}
|
||||
|
||||
func canMarkBelowAsRead(for article: Article) -> Bool {
|
||||
return articles.last != article
|
||||
let articleBelowArray = articles.articlesBelow(article: article)
|
||||
return articleBelowArray.canMarkAllAsRead()
|
||||
}
|
||||
|
||||
func markBelowAsRead() {
|
||||
|
@ -905,18 +903,8 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
|||
}
|
||||
|
||||
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)
|
||||
let articleBelowArray = articles.articlesBelow(article: article)
|
||||
markAllAsRead(articleBelowArray)
|
||||
}
|
||||
|
||||
func markAsReadForCurrentArticle() {
|
||||
|
|
Loading…
Reference in New Issue