Consider sort direction when sorting the Article array for the timeline.

This commit is contained in:
Brent Simmons 2018-01-28 11:33:04 -08:00
parent 6e63ce5968
commit 28c4ea82e5

View File

@ -64,9 +64,16 @@ extension Array where Element == Article {
return indexes
}
func sortedByDate() -> ArticleArray {
func sortedByDate(_ sortDirection: ComparisonResult) -> ArticleArray {
return sorted(by: articleComparator)
let articles = sorted { (article1, article2) -> Bool in
if sortDirection == .orderedDescending {
return article1.logicalDatePublished > article2.logicalDatePublished
}
return article1.logicalDatePublished < article2.logicalDatePublished
}
return articles
}
func canMarkAllAsRead() -> Bool {
@ -95,12 +102,4 @@ private extension Array where Element == Article {
return rowForArticleID(article.articleID)
}
// MARK: Sorting
func articleComparator(_ article1: Article, article2: Article) -> Bool {
return article1.logicalDatePublished > article2.logicalDatePublished
}
}