From 4103a450d4bb55cd3bd29f44dbfcd508d72e5f32 Mon Sep 17 00:00:00 2001 From: skoruppa Date: Wed, 8 Apr 2026 14:18:17 +0200 Subject: [PATCH] If same timestamp, order latestEpisodeByContent by season/episode & change next up to use watched items instead of watch progress --- .../tv/core/sync/WatchProgressSyncService.kt | 6 ++- .../repository/WatchProgressRepositoryImpl.kt | 45 +++++++++++++++---- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/nuvio/tv/core/sync/WatchProgressSyncService.kt b/app/src/main/java/com/nuvio/tv/core/sync/WatchProgressSyncService.kt index f1c69a83..6431ebfe 100644 --- a/app/src/main/java/com/nuvio/tv/core/sync/WatchProgressSyncService.kt +++ b/app/src/main/java/com/nuvio/tv/core/sync/WatchProgressSyncService.kt @@ -286,7 +286,11 @@ class WatchProgressSyncService @Inject constructor( } } .groupBy { it.contentId } - .mapValues { (_, episodes) -> episodes.maxByOrNull { it.lastWatched } } + .mapValues { (_, episodes) -> episodes.maxWithOrNull( + compareBy { it.lastWatched } + .thenBy { it.season ?: 0 } + .thenBy { it.episode ?: 0 } + ) } latestEpisodeByContent.forEach { (contentId, latestEpisode) -> val latest = latestEpisode ?: return@forEach diff --git a/app/src/main/java/com/nuvio/tv/data/repository/WatchProgressRepositoryImpl.kt b/app/src/main/java/com/nuvio/tv/data/repository/WatchProgressRepositoryImpl.kt index 6fd73200..14c460d3 100644 --- a/app/src/main/java/com/nuvio/tv/data/repository/WatchProgressRepositoryImpl.kt +++ b/app/src/main/java/com/nuvio/tv/data/repository/WatchProgressRepositoryImpl.kt @@ -345,15 +345,42 @@ class WatchProgressRepositoryImpl @Inject constructor( mergeNextUpSeeds(canonicalSeeds, optimisticSeeds) } } else { - watchProgressPreferences.allProgress.map { items -> - items.filter { progress -> - progress.isCompleted() && - progress.contentType.equals("series", ignoreCase = true) && - progress.season != null && - progress.episode != null && - progress.season != 0 && - !isMalformedNextUpSeedContentId(progress.contentId) - } + // Use watched items (fully synced with pagination) to build seeds + // instead of watch progress (limited to 1000 entries). + watchedItemsPreferences.allItems.map { items -> + items + .filter { item -> + (item.contentType.equals("series", ignoreCase = true) || + item.contentType.equals("tv", ignoreCase = true)) && + item.season != null && + item.episode != null && + item.season != 0 && + !isMalformedNextUpSeedContentId(item.contentId) + } + .groupBy { it.contentId } + .mapNotNull { (_, episodes) -> + val latest = episodes.maxWithOrNull( + compareBy { it.watchedAt } + .thenBy { it.season ?: 0 } + .thenBy { it.episode ?: 0 } + ) ?: return@mapNotNull null + WatchProgress( + contentId = latest.contentId, + contentType = latest.contentType, + name = latest.title, + poster = null, + backdrop = null, + logo = null, + videoId = latest.contentId, + season = latest.season, + episode = latest.episode, + episodeTitle = null, + position = 1L, + duration = 1L, + lastWatched = latest.watchedAt, + progressPercent = 100f + ) + } } } }