Merge branch 'mark-as-read-on-scroll' into super-cut

This commit is contained in:
Maurice Parker
2023-03-10 15:37:07 -06:00
9 changed files with 254 additions and 104 deletions

View File

@@ -35,7 +35,6 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
weak var coordinator: SceneCoordinator!
var undoableCommands = [UndoableCommand]()
let scrollPositionQueue = CoalescingQueue(name: "Timeline Scroll Position", interval: 0.3, maxInterval: 1.0)
private let keyboardManager = KeyboardManager(type: .timeline)
override var keyCommands: [UIKeyCommand]? {
@@ -434,7 +433,25 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
}
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
scrollPositionQueue.add(self, #selector(scrollPositionDidChange))
coordinator.timelineMiddleIndexPath = tableView.middleVisibleRow()
// Implement Mark As Read on Scroll where we mark after the leading edge goes a little beyond the safe area inset
guard AppDefaults.shared.markArticlesAsReadOnScroll,
let firstVisibleindexPath = tableView.indexPathsForVisibleRows?.first else { return }
var articles = [Article]()
for i in firstVisibleindexPath.row..<tableView.numberOfRows(inSection: firstVisibleindexPath.section) {
let indexPath = IndexPath(row: i, section: firstVisibleindexPath.section)
let cellRect = tableView.rectForRow(at: indexPath)
guard tableView.convert(cellRect, to: nil).origin.y < tableView.safeAreaInsets.top - 40 else { break }
if let article = dataSource.itemIdentifier(for: indexPath), article.status.read == false {
articles.append(article)
}
}
coordinator.markAllAsRead(articles)
}
// MARK: Notifications
@@ -530,10 +547,6 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
updateUI()
}
@objc func scrollPositionDidChange() {
coordinator.timelineMiddleIndexPath = tableView.middleVisibleRow()
}
// MARK: Reloading
func queueReloadAvailableCells() {
@@ -723,7 +736,6 @@ private extension MasterTimelineViewController {
}
func configure(_ cell: MasterTimelineTableViewCell, article: Article, indexPath: IndexPath) {
let iconImage = iconImageFor(article)
let featuredImage = featuredImageFor(article)