Remove Mark Read on Scroll code

This commit is contained in:
Maurice Parker
2021-12-29 14:44:40 -08:00
parent bb120b5e3c
commit 09652bff81
6 changed files with 1 additions and 175 deletions

View File

@@ -46,7 +46,6 @@ final class AppDefaults {
static let firstRunDate = "firstRunDate"
static let timelineGroupByFeed = "timelineGroupByFeed"
static let refreshClearsReadArticles = "refreshClearsReadArticles"
static let markArticlesAsReadOnScroll = "markArticlesAsReadOnScroll"
static let timelineNumberOfLines = "timelineNumberOfLines"
static let timelineIconDimension = "timelineIconSize"
static let timelineSortDirection = "timelineSortDirection"
@@ -160,15 +159,6 @@ final class AppDefaults {
}
}
var markArticlesAsReadOnScroll: Bool {
get {
return AppDefaults.bool(for: Key.markArticlesAsReadOnScroll)
}
set {
AppDefaults.setBool(for: Key.markArticlesAsReadOnScroll, newValue)
}
}
var timelineSortDirection: ComparisonResult {
get {
return AppDefaults.sortDirection(for: Key.timelineSortDirection)
@@ -246,7 +236,6 @@ final class AppDefaults {
let defaults: [String : Any] = [Key.userInterfaceColorPalette: UserInterfaceColorPalette.automatic.rawValue,
Key.timelineGroupByFeed: false,
Key.refreshClearsReadArticles: false,
Key.markArticlesAsReadOnScroll: false,
Key.timelineNumberOfLines: 2,
Key.timelineIconDimension: IconSize.medium.rawValue,
Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,

View File

@@ -418,9 +418,7 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
}
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.isTracking {
scrollPositionQueue.add(self, #selector(scrollPositionDidChange))
}
scrollPositionQueue.add(self, #selector(scrollPositionDidChange))
}
// MARK: Notifications
@@ -518,54 +516,6 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
@objc func scrollPositionDidChange() {
coordinator.timelineMiddleIndexPath = tableView.middleVisibleRow()
if !AppDefaults.shared.markArticlesAsReadOnScroll {
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 visibleRowIndexPaths = tableView.indexPathsForVisibleRows, visibleRowIndexPaths.count > 0 else { return }
let firstVisibleRowIndexPath = visibleRowIndexPaths[0]
guard let firstVisibleArticle = dataSource.itemIdentifier(for: firstVisibleRowIndexPath) else {
return
}
guard let unreadArticlesScrolledAway = coordinator.articles
.articlesAbove(article: firstVisibleArticle)
.filter({ !coordinator.articlesWithManuallyChangedReadStatus.contains($0) })
.unreadArticles() else { return }
coordinator.markAllAsRead(unreadArticlesScrolledAway)
for article in unreadArticlesScrolledAway {
if let indexPath = dataSource.indexPath(for: article) {
if let cell = tableView.cellForRow(at: indexPath) as? MasterTimelineTableViewCell {
configure(cell, article: article)
}
}
}
}
// MARK: Reloading

View File

@@ -182,9 +182,6 @@ class SceneCoordinator: NSObject, UndoableCommandRunner {
private(set) var showFeedNames = ShowFeedName.none
private(set) var showIcons = false
var articlesWithManuallyChangedReadStatus: Set<Article> = Set()
var markBottomArticlesAsReadWorkItem: DispatchWorkItem?
var prevFeedIndexPath: IndexPath? {
guard let indexPath = currentFeedIndexPath else {
return nil
@@ -786,9 +783,6 @@ class SceneCoordinator: NSObject, UndoableCommandRunner {
return
}
articlesWithManuallyChangedReadStatus.removeAll()
markBottomArticlesAsReadWorkItem?.cancel()
currentFeedIndexPath = indexPath
masterFeedViewController.updateFeedSelection(animations: animations)
@@ -1079,28 +1073,24 @@ class SceneCoordinator: NSObject, UndoableCommandRunner {
func markAsReadForCurrentArticle() {
if let article = currentArticle {
markArticlesWithUndo([article], statusKey: .read, flag: true)
articlesWithManuallyChangedReadStatus.insert(article)
}
}
func markAsUnreadForCurrentArticle() {
if let article = currentArticle {
markArticlesWithUndo([article], statusKey: .read, flag: false)
articlesWithManuallyChangedReadStatus.insert(article)
}
}
func toggleReadForCurrentArticle() {
if let article = currentArticle {
toggleRead(article)
articlesWithManuallyChangedReadStatus.insert(article)
}
}
func toggleRead(_ article: Article) {
guard !article.status.read || article.isAvailableToMarkUnread else { return }
markArticlesWithUndo([article], statusKey: .read, flag: !article.status.read)
articlesWithManuallyChangedReadStatus.insert(article)
}
func toggleStarredForCurrentArticle() {