Mark bottom items in feed as read after 2 seconds on iOS
In case markArticlesAsReadOnScroll is set
This commit is contained in:
parent
5364b4f384
commit
8e53768033
|
@ -521,6 +521,28 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark all articles as read when the bottom of the feed is reached
|
||||||
|
if let lastVisibleRowIndexPath = tableView.indexPathsForVisibleRows?.last {
|
||||||
|
let atBottom = dataSource.itemIdentifier(for: lastVisibleRowIndexPath) == coordinator.articles.last
|
||||||
|
|
||||||
|
if atBottom && coordinator.markBottomArticlesAsReadWorkItem == nil {
|
||||||
|
let task = DispatchWorkItem {
|
||||||
|
let articlesToMarkAsRead = self.coordinator.articles.filter { !$0.status.read && !self.coordinator.articlesWithManuallyChangedReadStatus.contains($0) }
|
||||||
|
|
||||||
|
if articlesToMarkAsRead.isEmpty { return }
|
||||||
|
self.coordinator.markAllAsRead(articlesToMarkAsRead)
|
||||||
|
self.coordinator.markBottomArticlesAsReadWorkItem = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
coordinator.markBottomArticlesAsReadWorkItem = task
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: task)
|
||||||
|
} else if !atBottom, let task = coordinator.markBottomArticlesAsReadWorkItem {
|
||||||
|
task.cancel()
|
||||||
|
coordinator.markBottomArticlesAsReadWorkItem = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark articles scrolled out of sight at the top as read
|
||||||
guard let firstVisibleRowIndexPath = tableView.indexPathsForVisibleRows?[0] else { return }
|
guard let firstVisibleRowIndexPath = tableView.indexPathsForVisibleRows?[0] else { return }
|
||||||
|
|
||||||
guard let firstVisibleArticle = dataSource.itemIdentifier(for: firstVisibleRowIndexPath) else {
|
guard let firstVisibleArticle = dataSource.itemIdentifier(for: firstVisibleRowIndexPath) else {
|
||||||
|
|
|
@ -183,6 +183,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner {
|
||||||
private(set) var showIcons = false
|
private(set) var showIcons = false
|
||||||
|
|
||||||
var articlesWithManuallyChangedReadStatus: Set<Article> = Set()
|
var articlesWithManuallyChangedReadStatus: Set<Article> = Set()
|
||||||
|
var markBottomArticlesAsReadWorkItem: DispatchWorkItem?
|
||||||
|
|
||||||
var prevFeedIndexPath: IndexPath? {
|
var prevFeedIndexPath: IndexPath? {
|
||||||
guard let indexPath = currentFeedIndexPath else {
|
guard let indexPath = currentFeedIndexPath else {
|
||||||
|
@ -786,6 +787,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
articlesWithManuallyChangedReadStatus.removeAll()
|
articlesWithManuallyChangedReadStatus.removeAll()
|
||||||
|
markBottomArticlesAsReadWorkItem?.cancel()
|
||||||
|
|
||||||
currentFeedIndexPath = indexPath
|
currentFeedIndexPath = indexPath
|
||||||
masterFeedViewController.updateFeedSelection(animations: animations)
|
masterFeedViewController.updateFeedSelection(animations: animations)
|
||||||
|
|
Loading…
Reference in New Issue