From 8645bfce29656259a1a58124ea3f220b87556ac6 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Sun, 20 Apr 2025 21:16:14 +0200 Subject: [PATCH] fix(Feed): only update `LastFeedWatchedTime` when update time is newer Fixes an issue, where if the user switches between channel group, already seen videos could be marked as new. This was caused by the channel group having only older videos, which resetted the last watched time to an older timepoint. To fix this, the last watched time is only updated, when the new watched time is newer than the previous watched time. --- .../java/com/github/libretube/helpers/PreferenceHelper.kt | 8 ++++++-- .../libretube/ui/fragments/SubscriptionsFragment.kt | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt b/app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt index 54e66bc70..eb797cc8b 100644 --- a/app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt @@ -104,8 +104,12 @@ object PreferenceHelper { return getString(PreferenceKeys.LAST_STREAM_VIDEO_ID, "") } - fun setLastFeedWatchedTime(time: Long) { - putLong(PreferenceKeys.LAST_WATCHED_FEED_TIME, time) + fun updateLastFeedWatchedTime(time: Long) { + // only update the time if the time is newer + // this avoids cases, where the user last saw an older video, which had already been seen, + // causing all following video to be incorrectly marked as unseen again + if (getLastCheckedFeedTime() < time) + putLong(PreferenceKeys.LAST_WATCHED_FEED_TIME, time) } fun getLastCheckedFeedTime(): Long { diff --git a/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt index 3ce5703c6..ed98fb1fc 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt @@ -398,7 +398,7 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment(R.layout.fragment_sub binding.toggleSubs.text = getString(R.string.subscriptions) feed.firstOrNull { !it.isUpcoming }?.uploaded?.let { - PreferenceHelper.setLastFeedWatchedTime(it) + PreferenceHelper.updateLastFeedWatchedTime(it) } binding.subRefresh.isRefreshing = false