StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.
Kotlin iptv-player
Fix browse pagination for GROUPED mode: cursor, totalCount, added_at filter
disclosureza8760b643d1a
diff --git a/data/src/main/java/com/streamvault/data/local/dao/Daos.kt b/data/src/main/java/com/streamvault/data/local/dao/Daos.ktindex 2972b039..2e18052e 100644--- a/data/src/main/java/com/streamvault/data/local/dao/Daos.kt+++ b/data/src/main/java/com/streamvault/data/local/dao/Daos.kt@@ -1394,7 +1394,7 @@ interface MovieDao {limit: Int): List<MovieBrowseEntity>- @Query("SELECT * FROM movies WHERE provider_id = :providerId AND added_at > 0 ORDER BY added_at DESC, name ASC, id ASC LIMIT :limit")+ @Query("SELECT * FROM movies WHERE provider_id = :providerId ORDER BY added_at DESC, name ASC, id ASC LIMIT :limit")fun getFreshPreview(providerId: Long, limit: Int): Flow<List<MovieBrowseEntity>>@Query(@@ -1425,14 +1425,13 @@ interface MovieDao {)fun getFreshCountByProvider(providerId: Long): Flow<Int>- @Query("SELECT * FROM movies WHERE provider_id = :providerId AND added_at > 0 ORDER BY added_at DESC, name ASC, id ASC LIMIT :limit")+ @Query("SELECT * FROM movies WHERE provider_id = :providerId ORDER BY added_at DESC, name ASC, id ASC LIMIT :limit")suspend fun getFreshCursorPage(providerId: Long, limit: Int): List<MovieBrowseEntity>@Query("""SELECT * FROM moviesWHERE provider_id = :providerId- AND added_at > 0AND (added_at < :lastAddedAtOR (@@ -1452,7 +1451,7 @@ interface MovieDao {limit: Int): List<MovieBrowseEntity>- @Query("SELECT * FROM movies WHERE provider_id = :providerId AND category_id = :categoryId AND added_at > 0 ORDER BY added_at DESC, name ASC, id ASC LIMIT :limit")+ @Query("SELECT * FROM movies WHERE provider_id = :providerId AND category_id = :categoryId ORDER BY added_at DESC, name ASC, id ASC LIMIT :limit")fun getFreshByCategoryPreview(providerId: Long, categoryId: Long, limit: Int): Flow<List<MovieBrowseEntity>>@Query(@@ -1485,7 +1484,7 @@ interface MovieDao {)fun getFreshCountByCategory(providerId: Long, categoryId: Long): Flow<Int>- @Query("SELECT * FROM movies WHERE provider_id = :providerId AND category_id = :categoryId AND added_at > 0 ORDER BY added_at DESC, name ASC, id ASC LIMIT :limit")+ @Query("SELECT * FROM movies WHERE provider_id = :providerId AND category_id = :categoryId ORDER BY added_at DESC, name ASC, id ASC LIMIT :limit")suspend fun getFreshByCategoryCursorPage(providerId: Long, categoryId: Long, limit: Int): List<MovieBrowseEntity>@Query(@@ -1493,7 +1492,6 @@ interface MovieDao {SELECT * FROM moviesWHERE provider_id = :providerIdAND category_id = :categoryId- AND added_at > 0AND (added_at < :lastAddedAtOR (diff --git a/data/src/main/java/com/streamvault/data/repository/MovieRepositoryImpl.kt b/data/src/main/java/com/streamvault/data/repository/MovieRepositoryImpl.ktindex 75350f15..795bc17c 100644--- a/data/src/main/java/com/streamvault/data/repository/MovieRepositoryImpl.kt+++ b/data/src/main/java/com/streamvault/data/repository/MovieRepositoryImpl.kt@@ -1219,7 +1219,7 @@ class MovieRepositoryImpl @Inject constructor(.map { it.contentId }.toSet()- val canUseCursorWindow = presentationSettings.duplicateHandlingMode == VodDuplicateHandlingMode.SHOW_ALL && supportsCursorBrowse(query)+ val canUseCursorWindow = supportsCursorBrowse(query)val items = if (canUseCursorWindow) {fetchMovieCursorWindow(query, favoriteIds)} else {@@ -1247,32 +1247,7 @@ class MovieRepositoryImpl @Inject constructor(.take(query.limit)}- val totalCount = if (presentationSettings.duplicateHandlingMode == VodDuplicateHandlingMode.SHOW_ALL) {- rawTotalCount- } else {- val movies = movieBrowseSource(query).first()- val history = playbackHistoryDao.getByProvider(query.providerId).first()- val inProgressIds = history- .asSequence()- .filter { it.contentType == ContentType.MOVIE }- .filter { it.resumePositionMs > 0L && (it.totalDurationMs <= 0L || !moviePlaybackComplete(it.resumePositionMs, it.totalDurationMs)) }- .map { it.contentId }- .toSet()- val watchCounts = history- .asSequence()- .filter { it.contentType == ContentType.MOVIE }- .associate { it.contentId to it.watchCount }- buildPresentedMovies(- applyMovieBrowseQuery(- movies = movies,- query = query,- favoriteIds = favoriteIds,- inProgressIds = inProgressIds,- watchCounts = watchCounts- ),- presentationSettings- ).size- }+ val totalCount = rawTotalCountval hasMoreRemote = query.categoryId?.let { categoryId ->val provider = loadCompatibilityProvider(query.providerId)diff --git a/data/src/main/java/com/streamvault/data/repository/SeriesRepositoryImpl.kt b/data/src/main/java/com/streamvault/data/repository/SeriesRepositoryImpl.ktindex d3b5a8ab..14362de2 100644--- a/data/src/main/java/com/streamvault/data/repository/SeriesRepositoryImpl.kt+++ b/data/src/main/java/com/streamvault/data/repository/SeriesRepositoryImpl.kt@@ -1159,8 +1159,7 @@ class SeriesRepositoryImpl @Inject constructor(.map { it.contentId }.toSet()- val canUseCursorWindow = presentationSettings.duplicateHandlingMode == VodDuplicateHandlingMode.SHOW_ALL &&- supportsCursorBrowse(query)+ val canUseCursorWindow = supportsCursorBrowse(query)val items = if (canUseCursorWindow) {fetchSeriesCursorWindow(query, favoriteIds)} else {@@ -1201,45 +1200,7 @@ class SeriesRepositoryImpl @Inject constructor(.take(query.limit)}- val totalCount = if (presentationSettings.duplicateHandlingMode == VodDuplicateHandlingMode.SHOW_ALL) {- rawTotalCount- } else {- val series = seriesBrowseSource(query).first()- val history = playbackHistoryDao.getByProvider(query.providerId).first()- val inProgressIds = history- .asSequence()- .filter { it.contentType == ContentType.SERIES || it.contentType == ContentType.SERIES_EPISODE }- .filter {- it.resumePositionMs > 0L && (- it.totalDurationMs <= 0L ||- it.resumePositionMs < (it.totalDurationMs * 0.95f).toLong()- )- }- .mapNotNull { it.seriesId ?: it.contentId }- .toSet()- val completedSeriesIds = history- .asSequence()- .filter { it.contentType == ContentType.SERIES_EPISODE }- .filter { it.totalDurationMs > 0L && it.resumePositionMs >= (it.totalDurationMs * 0.95f).toLong() }- .mapNotNull { it.seriesId }- .toSet()- val watchCounts = history- .asSequence()- .filter { it.contentType == ContentType.SERIES || it.contentType == ContentType.SERIES_EPISODE }- .groupBy { it.seriesId ?: it.contentId }- .mapValues { (_, entries) -> entries.maxOf { it.watchCount } }- buildPresentedSeries(- applySeriesBrowseQuery(- series = series,- query = query,- favoriteIds = favoriteIds,- inProgressIds = inProgressIds,- completedSeriesIds = completedSeriesIds,- watchCounts = watchCounts- ),- presentationSettings- ).size- }+ val totalCount = rawTotalCountval hasMoreRemote = query.categoryId?.let { categoryId ->val provider = loadCompatibilityProvider(query.providerId)