Skip to content

StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.

Fix VOD filter sort semantics

David Nashashf8758ac76568
diff --git a/app/src/main/java/com/streamvault/app/ui/components/shell/VodChrome.kt b/app/src/main/java/com/streamvault/app/ui/components/shell/VodChrome.kt
index ba0795d9..f8106b6f 100644
--- a/app/src/main/java/com/streamvault/app/ui/components/shell/VodChrome.kt
+++ b/app/src/main/java/com/streamvault/app/ui/components/shell/VodChrome.kt
@@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
@@ -325,21 +326,21 @@ fun VodBrowseOptionsDialog(
PremiumDialog(
title = title,
onDismissRequest = onDismiss,
- widthFraction = 0.56f,
+ widthFraction = 0.6f,
+ heightFraction = null,
+ bodyHeightFraction = 0.44f,
content = {
- SelectionChipRow(
+ VodBrowseOptionsSection(
title = filterTitle,
chips = filterChips,
selectedKey = selectedFilterKey,
- onChipSelected = onFilterSelected,
- contentPadding = PaddingValues(horizontal = 0.dp)
+ onChipSelected = onFilterSelected
)
- SelectionChipRow(
+ VodBrowseOptionsSection(
title = sortTitle,
chips = sortChips,
selectedKey = selectedSortKey,
- onChipSelected = onSortSelected,
- contentPadding = PaddingValues(horizontal = 0.dp)
+ onChipSelected = onSortSelected
)
},
footer = {
@@ -350,3 +351,83 @@ fun VodBrowseOptionsDialog(
}
)
}
+
+@Composable
+private fun VodBrowseOptionsSection(
+ title: String,
+ chips: List<SelectionChip>,
+ selectedKey: String,
+ onChipSelected: (String) -> Unit
+) {
+ Column(
+ modifier = Modifier.fillMaxWidth(),
+ verticalArrangement = Arrangement.spacedBy(12.dp)
+ ) {
+ Text(
+ text = title,
+ style = MaterialTheme.typography.labelMedium,
+ color = AppColors.TextTertiary
+ )
+ FlowRow(
+ modifier = Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.spacedBy(10.dp),
+ verticalArrangement = Arrangement.spacedBy(10.dp)
+ ) {
+ chips.forEach { chip ->
+ VodBrowseOptionChip(
+ label = chip.label,
+ supportingText = chip.supportingText,
+ selected = chip.key == selectedKey,
+ onClick = { onChipSelected(chip.key) }
+ )
+ }
+ }
+ }
+}
+
+@Composable
+private fun VodBrowseOptionChip(
+ label: String,
+ supportingText: String?,
+ selected: Boolean,
+ onClick: () -> Unit
+) {
+ Surface(
+ onClick = onClick,
+ colors = ClickableSurfaceDefaults.colors(
+ containerColor = if (selected) Primary.copy(alpha = 0.18f) else SurfaceElevated,
+ focusedContainerColor = if (selected) Primary.copy(alpha = 0.28f) else SurfaceHighlight,
+ contentColor = if (selected) Primary else TextPrimary,
+ focusedContentColor = TextPrimary
+ ),
+ shape = ClickableSurfaceDefaults.shape(RoundedCornerShape(999.dp)),
+ border = ClickableSurfaceDefaults.border(
+ focusedBorder = Border(
+ border = BorderStroke(2.dp, FocusBorder),
+ shape = RoundedCornerShape(999.dp)
+ )
+ ),
+ scale = ClickableSurfaceDefaults.scale(focusedScale = 1f)
+ ) {
+ Column(
+ modifier = Modifier.padding(horizontal = 18.dp, vertical = 11.dp),
+ verticalArrangement = Arrangement.spacedBy(2.dp)
+ ) {
+ Text(
+ text = label,
+ style = MaterialTheme.typography.labelLarge,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis
+ )
+ supportingText?.takeIf { it.isNotBlank() }?.let { detail ->
+ Text(
+ text = detail,
+ style = MaterialTheme.typography.bodySmall,
+ color = AppColors.TextTertiary,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis
+ )
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/movies/MoviesViewModel.kt b/app/src/main/java/com/streamvault/app/ui/screens/movies/MoviesViewModel.kt
index e5527572..9adb16b5 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/movies/MoviesViewModel.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/movies/MoviesViewModel.kt
@@ -1178,13 +1178,19 @@ class MoviesViewModel @Inject constructor(
return when (sortBy) {
LibrarySortBy.LIBRARY -> filtered
LibrarySortBy.TITLE -> filtered.sortedBy { it.name.lowercase() }
- LibrarySortBy.RELEASE -> filtered.sortedByDescending(::movieAddedScore)
+ LibrarySortBy.RELEASE -> filtered.sortedByDescending(::movieReleaseScore)
LibrarySortBy.UPDATED -> filtered.sortedByDescending(::movieAddedScore)
LibrarySortBy.RATING -> filtered.sortedByDescending { it.rating }
LibrarySortBy.WATCH_COUNT -> filtered.sortedByDescending { it.lastWatchedAt }
}
}
+ private fun movieReleaseScore(movie: Movie): Long =
+ movie.releaseDate?.filter { it.isDigit() }?.take(8)?.toLongOrNull()
+ ?: movie.year?.toLongOrNull()
+ ?: movie.addedAt.takeIf { it > 0L }
+ ?: 0L
+
private fun movieAddedScore(movie: Movie): Long = movie.addedAt.takeIf { it > 0L } ?: 0L
}
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/series/SeriesViewModel.kt b/app/src/main/java/com/streamvault/app/ui/screens/series/SeriesViewModel.kt
index b56a0aa9..5aa7d510 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/series/SeriesViewModel.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/series/SeriesViewModel.kt
@@ -1184,28 +1184,28 @@ class SeriesViewModel @Inject constructor(
LibraryFilterType.FAVORITES -> searched.filter { it.isFavorite }
LibraryFilterType.IN_PROGRESS -> searched.filter { it.id in historyKeys }
LibraryFilterType.UNWATCHED -> searched.filter { it.id !in completedSeriesIds }
- LibraryFilterType.RECENTLY_UPDATED -> searched.filter { seriesFreshnessScore(it) > 0L }
+ LibraryFilterType.RECENTLY_UPDATED -> searched.filter { seriesUpdatedScore(it) > 0L }
LibraryFilterType.TOP_RATED -> searched.filter { it.rating > 0f }
}
return when (sortBy) {
LibrarySortBy.LIBRARY -> filtered
LibrarySortBy.TITLE -> filtered.sortedBy { it.name.lowercase() }
- LibrarySortBy.RELEASE -> filtered.sortedByDescending(::seriesFreshnessScore)
- LibrarySortBy.UPDATED -> filtered.sortedByDescending(::seriesFreshnessScore)
+ LibrarySortBy.RELEASE -> filtered.sortedByDescending(::seriesReleaseScore)
+ LibrarySortBy.UPDATED -> filtered.sortedByDescending(::seriesUpdatedScore)
LibrarySortBy.RATING -> filtered.sortedByDescending { it.rating }
LibrarySortBy.WATCH_COUNT -> filtered.sortedByDescending { series -> watchCounts[series.id] ?: 0 }
}
}
- private fun seriesFreshnessScore(series: Series): Long {
- return series.lastModified
- .takeIf { it > 0L }
- ?: series.releaseDate
- ?.filter { it.isDigit() }
- ?.take(8)
- ?.toLongOrNull()
- ?: 0L
- }
+ private fun seriesReleaseScore(series: Series): Long =
+ series.releaseDate
+ ?.filter { it.isDigit() }
+ ?.take(8)
+ ?.toLongOrNull()
+ ?: seriesUpdatedScore(series)
+
+ private fun seriesUpdatedScore(series: Series): Long =
+ series.lastModified.takeIf { it > 0L } ?: 0L
}
private data class SeriesCatalogParams(
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.kt
index ab4b4098..78cd9f27 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
@@ -1189,6 +1189,23 @@ interface MovieDao {
@Query("SELECT * FROM movies WHERE provider_id = :providerId AND added_at > 0 ORDER BY added_at DESC, name ASC, id ASC LIMIT :limit")
fun getFreshPreview(providerId: Long, limit: Int): Flow<List<MovieBrowseEntity>>
+ @Query(
+ """
+ SELECT * FROM movies
+ WHERE provider_id = :providerId
+ ORDER BY
+ CASE WHEN COALESCE(release_date, '') != '' THEN 1 ELSE 0 END DESC,
+ release_date DESC,
+ CASE WHEN COALESCE(year, '') != '' THEN 1 ELSE 0 END DESC,
+ year DESC,
+ added_at DESC,
+ name ASC,
+ id ASC
+ LIMIT :limit
+ """
+ )
+ fun getReleasedPreview(providerId: Long, limit: Int): Flow<List<MovieBrowseEntity>>
+
@Query(
"""
SELECT COUNT(*) FROM movies
@@ -1230,6 +1247,24 @@ interface MovieDao {
@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")
fun getFreshByCategoryPreview(providerId: Long, categoryId: Long, limit: Int): Flow<List<MovieBrowseEntity>>
+ @Query(
+ """
+ SELECT * FROM movies
+ WHERE provider_id = :providerId
+ AND category_id = :categoryId
+ ORDER BY
+ CASE WHEN COALESCE(release_date, '') != '' THEN 1 ELSE 0 END DESC,
+ release_date DESC,
+ CASE WHEN COALESCE(year, '') != '' THEN 1 ELSE 0 END DESC,
+ year DESC,
+ added_at DESC,
+ name ASC,
+ id ASC
+ LIMIT :limit
+ """
+ )
+ fun getReleasedByCategoryPreview(providerId: Long, categoryId: Long, limit: Int): Flow<List<MovieBrowseEntity>>
+
@Query(
"""
SELECT COUNT(*) FROM movies
@@ -2159,28 +2194,41 @@ interface SeriesDao {
limit: Int
): List<SeriesBrowseEntity>
- @Query("SELECT * FROM series WHERE provider_id = :providerId ORDER BY last_modified DESC, name ASC LIMIT :limit")
+ @Query("SELECT * FROM series WHERE provider_id = :providerId AND last_modified > 0 ORDER BY last_modified DESC, name ASC LIMIT :limit")
fun getFreshPreview(providerId: Long, limit: Int): Flow<List<SeriesBrowseEntity>>
@Query(
"""
- SELECT COUNT(*) FROM series
+ SELECT * FROM series
WHERE provider_id = :providerId
- AND (
- last_modified > 0
- OR COALESCE(release_date, '') != ''
- )
+ ORDER BY
+ CASE WHEN COALESCE(release_date, '') != '' THEN 1 ELSE 0 END DESC,
+ release_date DESC,
+ last_modified DESC,
+ name ASC,
+ id ASC
+ LIMIT :limit
+ """
+ )
+ fun getReleasedPreview(providerId: Long, limit: Int): Flow<List<SeriesBrowseEntity>>
+
+ @Query(
+ """
+ SELECT COUNT(*) FROM series
+ WHERE provider_id = :providerId
+ AND last_modified > 0
"""
)
fun getFreshCountByProvider(providerId: Long): Flow<Int>
- @Query("SELECT * FROM series WHERE provider_id = :providerId ORDER BY last_modified DESC, name ASC, id ASC LIMIT :limit")
+ @Query("SELECT * FROM series WHERE provider_id = :providerId AND last_modified > 0 ORDER BY last_modified DESC, name ASC, id ASC LIMIT :limit")
suspend fun getFreshCursorPage(providerId: Long, limit: Int): List<SeriesBrowseEntity>
@Query(
"""
SELECT * FROM series
WHERE provider_id = :providerId
+ AND last_modified > 0
AND (
last_modified < :lastModified
OR (last_modified = :lastModified AND (name > :lastName OR (name = :lastName AND id > :lastId)))
@@ -2197,23 +2245,36 @@ interface SeriesDao {
limit: Int
): List<SeriesBrowseEntity>
- @Query("SELECT * FROM series WHERE provider_id = :providerId AND category_id = :categoryId ORDER BY last_modified DESC, name ASC LIMIT :limit")
+ @Query("SELECT * FROM series WHERE provider_id = :providerId AND category_id = :categoryId AND last_modified > 0 ORDER BY last_modified DESC, name ASC LIMIT :limit")
fun getFreshByCategoryPreview(providerId: Long, categoryId: Long, limit: Int): Flow<List<SeriesBrowseEntity>>
@Query(
"""
- SELECT COUNT(*) FROM series
+ SELECT * FROM series
WHERE provider_id = :providerId
AND category_id = :categoryId
- AND (
- last_modified > 0
- OR COALESCE(release_date, '') != ''
- )
+ ORDER BY
+ CASE WHEN COALESCE(release_date, '') != '' THEN 1 ELSE 0 END DESC,
+ release_date DESC,
+ last_modified DESC,
+ name ASC,
+ id ASC
+ LIMIT :limit
+ """
+ )
+ fun getReleasedByCategoryPreview(providerId: Long, categoryId: Long, limit: Int): Flow<List<SeriesBrowseEntity>>
+
+ @Query(
+ """
+ SELECT COUNT(*) FROM series
+ WHERE provider_id = :providerId
+ AND category_id = :categoryId
+ AND last_modified > 0
"""
)
fun getFreshCountByCategory(providerId: Long, categoryId: Long): Flow<Int>
- @Query("SELECT * FROM series WHERE provider_id = :providerId AND category_id = :categoryId ORDER BY last_modified DESC, name ASC, id ASC LIMIT :limit")
+ @Query("SELECT * FROM series WHERE provider_id = :providerId AND category_id = :categoryId AND last_modified > 0 ORDER BY last_modified DESC, name ASC, id ASC LIMIT :limit")
suspend fun getFreshByCategoryCursorPage(providerId: Long, categoryId: Long, limit: Int): List<SeriesBrowseEntity>
@Query(
@@ -2221,6 +2282,7 @@ interface SeriesDao {
SELECT * FROM series
WHERE provider_id = :providerId
AND category_id = :categoryId
+ AND last_modified > 0
AND (
last_modified < :lastModified
OR (last_modified = :lastModified AND (name > :lastName OR (name = :lastName AND id > :lastId)))
diff --git a/data/src/main/java/com/streamvault/data/repository/MovieRepositoryImpl.kt b/data/src/main/java/com/streamvault/data/repository/MovieRepositoryImpl.kt
index 277c9229..2dba0009 100644
--- a/data/src/main/java/com/streamvault/data/repository/MovieRepositoryImpl.kt
+++ b/data/src/main/java/com/streamvault/data/repository/MovieRepositoryImpl.kt
@@ -636,7 +636,27 @@ class MovieRepositoryImpl @Inject constructor(
}
} ?: getTopRatedPreview(query.providerId, fetchLimit)
}
- query.sortBy == LibrarySortBy.RELEASE || query.sortBy == LibrarySortBy.UPDATED || query.filterBy.type == LibraryFilterType.RECENTLY_UPDATED -> {
+ query.sortBy == LibrarySortBy.RELEASE -> {
+ query.categoryId?.let { categoryId ->
+ flow {
+ ensureXtreamCategoryLoaded(query.providerId, categoryId, fetchIfMissing = true, refreshStaleInBackground = true, requiredCount = fetchLimit)
+ emitAll(
+ combine(
+ movieDao.getReleasedByCategoryPreview(query.providerId, categoryId, fetchLimit),
+ preferencesRepository.parentalControlLevel
+ ) { entities, level ->
+ if (level >= 3) entities.filter { !it.isUserProtected } else entities
+ }.map { entities -> entities.map { it.toDomain() } }
+ )
+ }
+ } ?: combine(
+ movieDao.getReleasedPreview(query.providerId, fetchLimit),
+ preferencesRepository.parentalControlLevel
+ ) { entities, level ->
+ if (level >= 3) entities.filter { !it.isUserProtected } else entities
+ }.map { entities -> entities.map { it.toDomain() } }
+ }
+ query.sortBy == LibrarySortBy.UPDATED || query.filterBy.type == LibraryFilterType.RECENTLY_UPDATED -> {
query.categoryId?.let { categoryId ->
flow {
ensureXtreamCategoryLoaded(query.providerId, categoryId, fetchIfMissing = true, refreshStaleInBackground = true, requiredCount = fetchLimit)
@@ -1017,11 +1037,8 @@ class MovieRepositoryImpl @Inject constructor(
loadMovieRatingPage(query, limit, cursor)
}
}
- (
- query.sortBy == LibrarySortBy.RELEASE ||
- query.sortBy == LibrarySortBy.UPDATED ||
- query.filterBy.type == LibraryFilterType.RECENTLY_UPDATED
- ) -> {
+ query.sortBy == LibrarySortBy.UPDATED ||
+ query.filterBy.type == LibraryFilterType.RECENTLY_UPDATED -> {
collectMoviePages<FreshCursor>(query, parentalLevel, collected, favoriteIds,
extractCursor = { FreshCursor(it.addedAt, it.name, it.id) }
) { limit, cursor ->
@@ -1111,7 +1128,6 @@ class MovieRepositoryImpl @Inject constructor(
query.sortBy in setOf(
LibrarySortBy.LIBRARY,
LibrarySortBy.TITLE,
- LibrarySortBy.RELEASE,
LibrarySortBy.UPDATED,
LibrarySortBy.RATING
) -> query.categoryId == null || query.sortBy != LibrarySortBy.LIBRARY
@@ -1136,7 +1152,8 @@ class MovieRepositoryImpl @Inject constructor(
val sorted = when (query.sortBy) {
LibrarySortBy.LIBRARY -> filtered
LibrarySortBy.TITLE -> filtered.sortedBy { it.name.lowercase() }
- LibrarySortBy.RELEASE, LibrarySortBy.UPDATED -> filtered.sortedByDescending(::movieReleaseScore)
+ LibrarySortBy.RELEASE -> filtered.sortedByDescending(::movieReleaseScore)
+ LibrarySortBy.UPDATED -> filtered.sortedByDescending(::movieAddedScore)
LibrarySortBy.RATING -> filtered.sortedByDescending { it.rating }
LibrarySortBy.WATCH_COUNT -> filtered.sortedByDescending { watchCounts[it.id] ?: 0 }
}
@@ -1440,9 +1457,9 @@ class MovieRepositoryImpl @Inject constructor(
}
private fun movieReleaseScore(movie: Movie): Long =
- movie.addedAt.takeIf { it > 0L }
- ?: movie.releaseDate?.filter { it.isDigit() }?.toLongOrNull()
+ movie.releaseDate?.filter { it.isDigit() }?.take(8)?.toLongOrNull()
?: movie.year?.toLongOrNull()
+ ?: movie.addedAt.takeIf { it > 0L }
?: 0L
private fun movieAddedScore(movie: Movie): Long =
diff --git a/data/src/main/java/com/streamvault/data/repository/SeriesRepositoryImpl.kt b/data/src/main/java/com/streamvault/data/repository/SeriesRepositoryImpl.kt
index 00dd9b3d..3deb07ee 100644
--- a/data/src/main/java/com/streamvault/data/repository/SeriesRepositoryImpl.kt
+++ b/data/src/main/java/com/streamvault/data/repository/SeriesRepositoryImpl.kt
@@ -595,7 +595,27 @@ class SeriesRepositoryImpl @Inject constructor(
}
} ?: getTopRatedPreview(query.providerId, fetchLimit)
}
- query.sortBy == LibrarySortBy.RELEASE || query.sortBy == LibrarySortBy.UPDATED || query.filterBy.type == LibraryFilterType.RECENTLY_UPDATED -> {
+ query.sortBy == LibrarySortBy.RELEASE -> {
+ query.categoryId?.let { categoryId ->
+ flow {
+ ensureXtreamCategoryLoaded(query.providerId, categoryId, fetchLimit)
+ emitAll(
+ combine(
+ seriesDao.getReleasedByCategoryPreview(query.providerId, categoryId, fetchLimit),
+ preferencesRepository.parentalControlLevel
+ ) { entities, level ->
+ if (level >= 3) entities.filter { !it.isUserProtected } else entities
+ }.map { entities -> entities.map { it.toDomain() } }
+ )
+ }
+ } ?: combine(
+ seriesDao.getReleasedPreview(query.providerId, fetchLimit),
+ preferencesRepository.parentalControlLevel
+ ) { entities, level ->
+ if (level >= 3) entities.filter { !it.isUserProtected } else entities
+ }.map { entities -> entities.map { it.toDomain() } }
+ }
+ query.sortBy == LibrarySortBy.UPDATED || query.filterBy.type == LibraryFilterType.RECENTLY_UPDATED -> {
query.categoryId?.let { categoryId ->
flow {
ensureXtreamCategoryLoaded(query.providerId, categoryId, fetchLimit)
@@ -994,8 +1014,7 @@ class SeriesRepositoryImpl @Inject constructor(
loadSeriesRatingPage(query, limit, cursor)
}
}
- query.sortBy == LibrarySortBy.RELEASE ||
- query.sortBy == LibrarySortBy.UPDATED ||
+ query.sortBy == LibrarySortBy.UPDATED ||
query.filterBy.type == LibraryFilterType.RECENTLY_UPDATED -> {
collectSeriesPages<FreshCursor>(query, parentalLevel, collected, favoriteIds,
extractCursor = { FreshCursor(it.lastModified, it.name, it.id) }
@@ -1079,7 +1098,6 @@ class SeriesRepositoryImpl @Inject constructor(
query.sortBy in setOf(
LibrarySortBy.LIBRARY,
LibrarySortBy.TITLE,
- LibrarySortBy.RELEASE,
LibrarySortBy.UPDATED,
LibrarySortBy.RATING
) -> true
@@ -1103,7 +1121,8 @@ class SeriesRepositoryImpl @Inject constructor(
val sorted = when (query.sortBy) {
LibrarySortBy.LIBRARY -> filtered
LibrarySortBy.TITLE -> filtered.sortedBy { it.name.lowercase() }
- LibrarySortBy.RELEASE, LibrarySortBy.UPDATED -> filtered.sortedByDescending(::seriesFreshnessScore)
+ LibrarySortBy.RELEASE -> filtered.sortedByDescending(::seriesReleaseScore)
+ LibrarySortBy.UPDATED -> filtered.sortedByDescending(::seriesUpdatedScore)
LibrarySortBy.RATING -> filtered.sortedByDescending { it.rating }
LibrarySortBy.WATCH_COUNT -> filtered.sortedByDescending { watchCounts[it.id] ?: 0 }
}
@@ -1130,7 +1149,7 @@ class SeriesRepositoryImpl @Inject constructor(
LibraryFilterType.IN_PROGRESS -> series.id in inProgressIds
LibraryFilterType.UNWATCHED -> series.id !in completedSeriesIds
LibraryFilterType.TOP_RATED -> series.rating > 0f
- LibraryFilterType.RECENTLY_UPDATED -> seriesFreshnessScore(series) > 0L
+ LibraryFilterType.RECENTLY_UPDATED -> seriesUpdatedScore(series) > 0L
}
private fun seriesMatchesSearch(series: Series, searchQuery: String): Boolean {
@@ -1395,14 +1414,15 @@ class SeriesRepositoryImpl @Inject constructor(
return true
}
- private fun seriesFreshnessScore(series: Series): Long =
- series.lastModified
- .takeIf { it > 0L }
- ?: series.releaseDate
- ?.filter { it.isDigit() }
- ?.take(8)
- ?.toLongOrNull()
- ?: 0L
+ private fun seriesReleaseScore(series: Series): Long =
+ series.releaseDate
+ ?.filter { it.isDigit() }
+ ?.take(8)
+ ?.toLongOrNull()
+ ?: seriesUpdatedScore(series)
+
+ private fun seriesUpdatedScore(series: Series): Long =
+ series.lastModified.takeIf { it > 0L } ?: 0L
private suspend fun getOrCreateXtreamProvider(providerId: Long, provider: ProviderEntity): XtreamProvider {
val enableBase64TextCompatibility = preferencesRepository.xtreamBase64TextCompatibility.first()
diff --git a/data/src/test/java/com/streamvault/data/repository/MovieRepositoryImplTest.kt b/data/src/test/java/com/streamvault/data/repository/MovieRepositoryImplTest.kt
index 34c55886..77fa1a92 100644
--- a/data/src/test/java/com/streamvault/data/repository/MovieRepositoryImplTest.kt
+++ b/data/src/test/java/com/streamvault/data/repository/MovieRepositoryImplTest.kt
@@ -598,6 +598,57 @@ class MovieRepositoryImplTest {
assertThat(result.items.map { it.name }).containsExactly("Rated Movie")
}
+ @Test
+ fun `browseMovies release uses release ordering instead of added order`() = runTest {
+ whenever(preferencesRepository.parentalControlLevel).thenReturn(flowOf(0))
+ whenever(preferencesRepository.xtreamBase64TextCompatibility).thenReturn(flowOf(false))
+ whenever(movieDao.getCount(7L)).thenReturn(flowOf(2))
+ whenever(movieDao.getReleasedPreview(7L, 100)).thenReturn(
+ flowOf(
+ listOf(
+ MovieBrowseEntity(
+ id = 1L,
+ streamId = 1L,
+ name = "Added Later",
+ providerId = 7L,
+ categoryId = 10L,
+ releaseDate = "2020-01-01",
+ addedAt = 20_000L,
+ streamUrl = "https://example.com/1.m3u8"
+ ),
+ MovieBrowseEntity(
+ id = 2L,
+ streamId = 2L,
+ name = "Released Later",
+ providerId = 7L,
+ categoryId = 10L,
+ releaseDate = "2024-01-01",
+ addedAt = 10_000L,
+ streamUrl = "https://example.com/2.m3u8"
+ )
+ )
+ )
+ )
+ whenever(favoriteDao.getAllByType(7L, ContentType.MOVIE.name)).thenReturn(flowOf(emptyList()))
+ whenever(playbackHistoryDao.getByProvider(7L)).thenReturn(flowOf(emptyList()))
+
+ val repository = createRepository()
+
+ val result = repository.browseMovies(
+ LibraryBrowseQuery(
+ providerId = 7L,
+ sortBy = LibrarySortBy.RELEASE,
+ offset = 0,
+ limit = 20
+ )
+ ).first()
+
+ assertThat(result.totalCount).isEqualTo(2)
+ assertThat(result.items.map { it.name }).containsExactly("Released Later", "Added Later").inOrder()
+ verify(movieDao).getReleasedPreview(7L, 100)
+ verify(movieDao, never()).getFreshPreview(7L, 100)
+ }
+
private fun createRepository() = MovieRepositoryImpl(
movieDao = movieDao,
categoryDao = categoryDao,
diff --git a/data/src/test/java/com/streamvault/data/repository/SeriesRepositoryImplTest.kt b/data/src/test/java/com/streamvault/data/repository/SeriesRepositoryImplTest.kt
index 6966fcbc..ce16513a 100644
--- a/data/src/test/java/com/streamvault/data/repository/SeriesRepositoryImplTest.kt
+++ b/data/src/test/java/com/streamvault/data/repository/SeriesRepositoryImplTest.kt
@@ -263,7 +263,7 @@ class SeriesRepositoryImplTest {
flowOf(
listOf(
SeriesBrowseEntity(id = 1L, seriesId = 101L, name = "Fresh Series", providerId = 7L, lastModified = 10_000L),
- SeriesBrowseEntity(id = 2L, seriesId = 102L, name = "Stale Series", providerId = 7L, lastModified = 0L)
+ SeriesBrowseEntity(id = 2L, seriesId = 102L, name = "Stale Series", providerId = 7L, lastModified = 0L, releaseDate = "2025-01-01")
)
)
)
@@ -286,6 +286,53 @@ class SeriesRepositoryImplTest {
assertThat(result.items.map { it.name }).containsExactly("Fresh Series")
}
+ @Test
+ fun `browseSeries release uses release ordering while updated remains last modified`() = runTest {
+ whenever(preferencesRepository.parentalControlLevel).thenReturn(flowOf(0))
+ whenever(preferencesRepository.xtreamBase64TextCompatibility).thenReturn(flowOf(false))
+ whenever(seriesDao.getCount(7L)).thenReturn(flowOf(2))
+ whenever(seriesDao.getReleasedPreview(7L, 100)).thenReturn(
+ flowOf(
+ listOf(
+ SeriesBrowseEntity(
+ id = 1L,
+ seriesId = 101L,
+ name = "Updated Later",
+ providerId = 7L,
+ releaseDate = "2020-01-01",
+ lastModified = 20_000L
+ ),
+ SeriesBrowseEntity(
+ id = 2L,
+ seriesId = 102L,
+ name = "Released Later",
+ providerId = 7L,
+ releaseDate = "2024-01-01",
+ lastModified = 10_000L
+ )
+ )
+ )
+ )
+ whenever(favoriteDao.getAllByType(7L, ContentType.SERIES.name)).thenReturn(flowOf(emptyList()))
+ whenever(playbackHistoryDao.getByProvider(7L)).thenReturn(flowOf(emptyList()))
+
+ val repository = createRepository()
+
+ val result = repository.browseSeries(
+ LibraryBrowseQuery(
+ providerId = 7L,
+ sortBy = LibrarySortBy.RELEASE,
+ offset = 0,
+ limit = 20
+ )
+ ).first()
+
+ assertThat(result.totalCount).isEqualTo(2)
+ assertThat(result.items.map { it.name }).containsExactly("Released Later", "Updated Later").inOrder()
+ verify(seriesDao).getReleasedPreview(7L, 100)
+ verify(seriesDao, never()).getFreshPreview(7L, 100)
+ }
+
@Test
fun `getSeriesByCategory skips legacy xtream empty retry hydration`() = runTest {
whenever(preferencesRepository.parentalControlLevel).thenReturn(flowOf(0))
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 72bcd82f..0ba9824b 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -27,6 +27,7 @@ All notable product changes are recorded in this document.
- Fixed Stalker temp-link and backend-family failures being reported too generically by surfacing clearer empty-link and session-rejection diagnostics, including HTTP `204` cases.
- Fixed Stalker indexing and hydration reliability on large or unstable portals with persisted cursors, retries, cooldowns, and safer stale-data pruning.
- Fixed Stalker setup and sync edge cases around wildcard categories, stale progress, provider diagnostics, explicit MAG identity overrides, and per-provider EPG counts.
+- Fixed Stalker series detail season selection when some portals returned season-shell rows again for per-season requests, which could make multiple seasons show the same pseudo-episode list instead of that season's episodes.
## [1.0.11] - 2026-05-13