Mark bottom items in feed as read after 2 seconds on iOS

In case markArticlesAsReadOnScroll is set
This commit is contained in:
everhardt 2021-10-30 11:17:59 +02:00
parent 5364b4f384
commit 8e53768033
2 changed files with 24 additions and 0 deletions

View File

@ -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 {

View File

@ -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)