From 54835c9e1f3c5c592d1768bb0f1b574fb08163c4 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Thu, 23 Jan 2025 16:22:44 +0100 Subject: [PATCH] fix(SubscriptionsFragment): update last feed time to last video time With the introduction of the local feed extraction, which only refreshes the feed naturally once a day, it is possible for the user to update the `lastFeedWatchedTime`, but not fetch the feed itself, leading to a disconnect between both values. When the feed is then later on refreshed, the caught-up-indicator is only displayed for the videos since the last app open, and not all new videos since the last refresh. --- .../java/com/github/libretube/helpers/PreferenceHelper.kt | 5 ++--- .../github/libretube/ui/fragments/SubscriptionsFragment.kt | 6 ++++-- 2 files changed, 6 insertions(+), 5 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 9527030b4..54e66bc70 100644 --- a/app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt @@ -5,7 +5,6 @@ import android.content.SharedPreferences import androidx.core.content.edit import androidx.preference.PreferenceManager import com.github.libretube.constants.PreferenceKeys -import java.time.Instant object PreferenceHelper { /** @@ -105,8 +104,8 @@ object PreferenceHelper { return getString(PreferenceKeys.LAST_STREAM_VIDEO_ID, "") } - fun updateLastFeedWatchedTime() { - putLong(PreferenceKeys.LAST_WATCHED_FEED_TIME, Instant.now().epochSecond) + fun setLastFeedWatchedTime(time: Long) { + 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 47c96d1be..4fc80b767 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 @@ -358,7 +358,7 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment(R.layout.fragment_sub // add an "all caught up item" if (selectedSortOrder == 0) { val lastCheckedFeedTime = PreferenceHelper.getLastCheckedFeedTime() - val caughtUpIndex = feed.indexOfFirst { it.uploaded / 1000 < lastCheckedFeedTime && !it.isUpcoming } + val caughtUpIndex = feed.indexOfFirst { it.uploaded <= lastCheckedFeedTime && !it.isUpcoming } if (caughtUpIndex > 0) { sortedFeed.add( caughtUpIndex, @@ -380,7 +380,9 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment(R.layout.fragment_sub binding.subFeed.adapter = feedAdapter binding.toggleSubs.text = getString(R.string.subscriptions) - PreferenceHelper.updateLastFeedWatchedTime() + feed.firstOrNull { !it.isUpcoming }?.uploaded?.let { + PreferenceHelper.setLastFeedWatchedTime(it) + }; } @SuppressLint("SetTextI18n")