StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.
Kotlin iptv-player
Harden VOD pinned category integration
David Nashash047e41eebfa9
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardViewModel.kt b/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardViewModel.ktindex 17a2b1f5..2a019206 100644--- a/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardViewModel.kt+++ b/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardViewModel.kt@@ -167,14 +167,27 @@ class DashboardViewModel @Inject constructor(if (pinnedIds.isEmpty()) {flowOf(emptyMap())} else {- movieRepository.getCategories(providerId).flatMapLatest { categories ->- val pinned = categories.filter { it.id in pinnedIds }+ combine(+ movieRepository.getCategories(providerId),+ preferencesRepository.getHiddenCategoryIds(providerId, ContentType.MOVIE),+ preferencesRepository.parentalControlLevel+ ) { categories, hiddenCategoryIds, level ->+ categories.filter { category ->+ category.id in pinnedIds &&+ category.id !in hiddenCategoryIds &&+ !shouldHideVodCategoryFromHome(category, level)+ }+ }.flatMapLatest { pinned ->if (pinned.isEmpty()) {flowOf(emptyMap())} else {val flows = pinned.map { category ->movieRepository.getMoviesByCategoryPreview(providerId, category.id, MOVIE_SHELF_LIMIT)- .map { movies -> category.name to movies }+ .combine(preferencesRepository.parentalControlLevel) { movies, level ->+ category.name to movies+ .filter { !shouldHideVodFromHome(it, level) }+ .take(MOVIE_SHELF_LIMIT)+ }}combine(flows) { results -> results.toMap() }}@@ -188,14 +201,27 @@ class DashboardViewModel @Inject constructor(if (pinnedIds.isEmpty()) {flowOf(emptyMap())} else {- seriesRepository.getCategories(providerId).flatMapLatest { categories ->- val pinned = categories.filter { it.id in pinnedIds }+ combine(+ seriesRepository.getCategories(providerId),+ preferencesRepository.getHiddenCategoryIds(providerId, ContentType.SERIES),+ preferencesRepository.parentalControlLevel+ ) { categories, hiddenCategoryIds, level ->+ categories.filter { category ->+ category.id in pinnedIds &&+ category.id !in hiddenCategoryIds &&+ !shouldHideVodCategoryFromHome(category, level)+ }+ }.flatMapLatest { pinned ->if (pinned.isEmpty()) {flowOf(emptyMap())} else {val flows = pinned.map { category ->seriesRepository.getSeriesByCategoryPreview(providerId, category.id, SERIES_SHELF_LIMIT)- .map { series -> category.name to series }+ .combine(preferencesRepository.parentalControlLevel) { series, level ->+ category.name to series+ .filter { !shouldHideVodFromHome(it, level) }+ .take(SERIES_SHELF_LIMIT)+ }}combine(flows) { results -> results.toMap() }}@@ -800,6 +826,10 @@ class DashboardViewModel @Inject constructor(return titleLooksExplicit(series.name)}+ private fun shouldHideVodCategoryFromHome(category: Category, level: Int): Boolean =+ !AdultContentVisibilityPolicy.showInAggregatedSurfaces(level) &&+ (category.isAdult || category.isUserProtected)+private fun titleLooksExplicit(title: String): Boolean {val normalized = title.lowercase()val explicitTerms = listOf("porn", "porno", "xxx", "adult", "18+", "sex", "erotic", "hentai")diff --git a/app/src/main/java/com/streamvault/app/ui/screens/movies/MoviesScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/movies/MoviesScreen.ktindex 5ddc32ae..8a3e0bfb 100644--- a/app/src/main/java/com/streamvault/app/ui/screens/movies/MoviesScreen.kt+++ b/app/src/main/java/com/streamvault/app/ui/screens/movies/MoviesScreen.kt@@ -463,17 +463,17 @@ private fun MoviesVodContent(val categoryOptions = remember(visibleCategoryNames, uiState.categoryCounts, categoryByName, uiState.parentalControlLevel, uiState.unlockedCategoryIds) {visibleCategoryNames.map { name ->val matchedCategory = categoryByName[name]- val locked = matchedCategory?.let(isCategoryLocked) == true+ val lockedCategory = matchedCategory?.takeIf(isCategoryLocked)VodCategoryOption(name = name,count = uiState.categoryCounts[name] ?: 0,onClick = {- if (locked && matchedCategory != null) openProtectedCategory(matchedCategory) else onSelectCategory(name)+ if (lockedCategory != null) openProtectedCategory(lockedCategory) else onSelectCategory(name)},- onLongClick = matchedCategory?.takeIf { !locked }?.let { category ->+ onLongClick = matchedCategory?.takeIf { lockedCategory == null }?.let { category ->{ onShowCategoryOptions(category.name) }},- isLocked = locked+ isLocked = lockedCategory != null)}}@@ -641,12 +641,12 @@ private fun MoviesVodContent(val categoryName = entry.keyval movies = entry.valueval matchedCategory = categoryByName[categoryName]- val lockedCategory = matchedCategory?.let(isCategoryLocked) == true+ val lockedCategory = matchedCategory?.takeIf(isCategoryLocked)CategoryRow(title = categoryName,items = movies,onSeeAll = {- if (lockedCategory && matchedCategory != null) openProtectedCategory(matchedCategory) else onSelectCategory(categoryName)+ if (lockedCategory != null) openProtectedCategory(lockedCategory) else onSelectCategory(categoryName)},onPinToggle = matchedCategory?.let { { onToggleCategoryPinned(it) } },isPinned = matchedCategory?.id in uiState.pinnedCategoryIds,@@ -704,12 +704,12 @@ private fun MoviesVodContent(val categoryName = entry.keyval movies = entry.valueval matchedCategory = categoryByName[categoryName]- val lockedCategory = matchedCategory?.let(isCategoryLocked) == true+ val lockedCategory = matchedCategory?.takeIf(isCategoryLocked)CategoryRow(title = categoryName,items = movies,onSeeAll = {- if (lockedCategory && matchedCategory != null) openProtectedCategory(matchedCategory) else onSelectCategory(categoryName)+ if (lockedCategory != null) openProtectedCategory(lockedCategory) else onSelectCategory(categoryName)},onPinToggle = matchedCategory?.let { { onToggleCategoryPinned(it) } },isPinned = matchedCategory?.id in uiState.pinnedCategoryIds,@@ -1158,7 +1158,7 @@ private fun MoviesVodClassicContent(.filterNot { it == uiState.favoriteCategoryName }.forEach { name ->val matchedCategory = categoryByName[name]- val locked = matchedCategory?.let(isCategoryLocked) == true+ val lockedCategory = matchedCategory?.takeIf(isCategoryLocked)add(VodClassicCategoryOption(key = "category:$name",@@ -1166,10 +1166,10 @@ private fun MoviesVodClassicContent(count = uiState.categoryCounts[name] ?: 0,isSelected = selectedKey == "category:$name",onClick = {- if (locked && matchedCategory != null) openProtectedCategory(matchedCategory) else onSelectCategory(name)+ if (lockedCategory != null) openProtectedCategory(lockedCategory) else onSelectCategory(name)},- onLongClick = matchedCategory?.takeIf { !locked }?.let { { onShowCategoryOptions(name) } },- isLocked = locked+ onLongClick = matchedCategory?.takeIf { lockedCategory == null }?.let { { onShowCategoryOptions(name) } },+ isLocked = lockedCategory != null))}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.ktindex 123ec9a9..a7b74247 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@@ -178,14 +178,10 @@ class MoviesViewModel @Inject constructor(categories}}- val pinnedProviderCategories = visibleProviderCategories.filter { it.id in pinnedCategoryIds }- val unpinnedProviderCategories = visibleProviderCategories.filterNot { it.id in pinnedCategoryIds }MovieCatalogDependencies(allFavorites = allFavorites,customCategories = customCategories,providerCategories = visibleProviderCategories,- pinnedProviderCategories = pinnedProviderCategories,- unpinnedProviderCategories = unpinnedProviderCategories,providerCategoryCounts = providerCategoryCounts,libraryCount = libraryCount,hiddenCategoryIds = hiddenCategoryIds,@@ -198,8 +194,6 @@ class MoviesViewModel @Inject constructor(allFavorites = dependencies.allFavorites,customCategories = dependencies.customCategories,providerCategories = dependencies.providerCategories,- pinnedProviderCategories = dependencies.pinnedProviderCategories,- unpinnedProviderCategories = dependencies.unpinnedProviderCategories,providerCategoryCounts = dependencies.providerCategoryCounts,libraryCount = dependencies.libraryCount,hiddenCategoryIds = dependencies.hiddenCategoryIds,@@ -246,7 +240,8 @@ class MoviesViewModel @Inject constructor(allFavorites = params.allFavorites,customCategories = params.customCategories,providerCategories = params.providerCategories,- hiddenCategoryIds = params.hiddenCategoryIds+ hiddenCategoryIds = params.hiddenCategoryIds,+ pinnedCategoryIds = params.pinnedCategoryIds).copy(libraryCount = 0),false, false))@@ -260,7 +255,8 @@ class MoviesViewModel @Inject constructor(allFavorites = params.allFavorites,customCategories = params.customCategories,providerCategories = params.providerCategories,- hiddenCategoryIds = params.hiddenCategoryIds+ hiddenCategoryIds = params.hiddenCategoryIds,+ pinnedCategoryIds = params.pinnedCategoryIds).copy(libraryCount = searchResults.size),false, false))@@ -282,7 +278,6 @@ class MoviesViewModel @Inject constructor(selected in providerCategoryNames ||selected in customCategoryNames}- val currentPinnedIds = _uiState.value.pinnedCategoryIds_uiState.update {it.copy(moviesByCategory = snapshot.grouped,@@ -290,7 +285,7 @@ class MoviesViewModel @Inject constructor(categoryCounts = snapshot.categoryCounts,libraryCount = snapshot.libraryCount,providerCategories = snapshot.providerCategories,- pinnedCategoryIds = currentPinnedIds.ifEmpty { snapshot.pinnedCategoryIds },+ pinnedCategoryIds = snapshot.pinnedCategoryIds,selectedCategory = resolvedSelected,selectedCategoryItems = if (resolvedSelected == null) emptyList() else it.selectedCategoryItems,selectedCategoryLoadedCount = if (resolvedSelected == null) 0 else it.selectedCategoryLoadedCount,@@ -1120,7 +1115,8 @@ class MoviesViewModel @Inject constructor(categoryNames = snapshot.categoryNames,categoryCounts = snapshot.categoryCounts,libraryCount = snapshot.libraryCount,- providerCategories = params.providerCategories+ providerCategories = params.providerCategories,+ pinnedCategoryIds = params.pinnedCategoryIds)}@@ -1129,7 +1125,8 @@ class MoviesViewModel @Inject constructor(allFavorites: List<com.streamvault.domain.model.Favorite>,customCategories: List<Category>,providerCategories: List<Category>,- hiddenCategoryIds: Set<Long>+ hiddenCategoryIds: Set<Long>,+ pinnedCategoryIds: Set<Long>): MovieCatalogSnapshot {val snapshot = buildVodSearchCatalog(items = movies,@@ -1148,7 +1145,8 @@ class MoviesViewModel @Inject constructor(categoryNames = snapshot.categoryNames,categoryCounts = snapshot.categoryCounts,libraryCount = snapshot.libraryCount,- providerCategories = providerCategories+ providerCategories = providerCategories,+ pinnedCategoryIds = pinnedCategoryIds)}@@ -1369,8 +1367,6 @@ private data class MovieCatalogParams(val allFavorites: List<com.streamvault.domain.model.Favorite>,val customCategories: List<Category>,val providerCategories: List<Category>,- val pinnedProviderCategories: List<Category> = emptyList(),- val unpinnedProviderCategories: List<Category> = emptyList(),val providerCategoryCounts: Map<Long, Int>,val libraryCount: Int,val hiddenCategoryIds: Set<Long>,@@ -1383,8 +1379,6 @@ private data class MovieCatalogDependencies(val allFavorites: List<com.streamvault.domain.model.Favorite>,val customCategories: List<Category>,val providerCategories: List<Category>,- val pinnedProviderCategories: List<Category> = emptyList(),- val unpinnedProviderCategories: List<Category> = emptyList(),val providerCategoryCounts: Map<Long, Int>,val libraryCount: Int,val hiddenCategoryIds: Set<Long>,diff --git a/app/src/main/java/com/streamvault/app/ui/screens/series/SeriesScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/series/SeriesScreen.ktindex c4866fd5..b1b0cf17 100644--- a/app/src/main/java/com/streamvault/app/ui/screens/series/SeriesScreen.kt+++ b/app/src/main/java/com/streamvault/app/ui/screens/series/SeriesScreen.kt@@ -462,17 +462,17 @@ private fun SeriesVodContent(val categoryOptions = remember(visibleCategoryNames, uiState.categoryCounts, categoryByName, uiState.parentalControlLevel, uiState.unlockedCategoryIds) {visibleCategoryNames.map { name ->val matchedCategory = categoryByName[name]- val locked = matchedCategory?.let(isCategoryLocked) == true+ val lockedCategory = matchedCategory?.takeIf(isCategoryLocked)VodCategoryOption(name = name,count = uiState.categoryCounts[name] ?: 0,onClick = {- if (locked && matchedCategory != null) openProtectedCategory(matchedCategory) else onSelectCategory(name)+ if (lockedCategory != null) openProtectedCategory(lockedCategory) else onSelectCategory(name)},- onLongClick = matchedCategory?.takeIf { !locked }?.let { category ->+ onLongClick = matchedCategory?.takeIf { lockedCategory == null }?.let { category ->{ onShowCategoryOptions(category.name) }},- isLocked = locked+ isLocked = lockedCategory != null)}}@@ -649,12 +649,12 @@ private fun SeriesVodContent(val categoryName = entry.keyval seriesList = entry.valueval matchedCategory = categoryByName[categoryName]- val lockedCategory = matchedCategory?.let(isCategoryLocked) == true+ val lockedCategory = matchedCategory?.takeIf(isCategoryLocked)CategoryRow(title = categoryName,items = seriesList,onSeeAll = {- if (lockedCategory && matchedCategory != null) openProtectedCategory(matchedCategory) else onSelectCategory(categoryName)+ if (lockedCategory != null) openProtectedCategory(lockedCategory) else onSelectCategory(categoryName)},onPinToggle = matchedCategory?.let { { onToggleCategoryPinned(it) } },isPinned = matchedCategory?.id in uiState.pinnedCategoryIds,@@ -711,12 +711,12 @@ private fun SeriesVodContent(val categoryName = entry.keyval seriesList = entry.valueval matchedCategory = categoryByName[categoryName]- val lockedCategory = matchedCategory?.let(isCategoryLocked) == true+ val lockedCategory = matchedCategory?.takeIf(isCategoryLocked)CategoryRow(title = categoryName,items = seriesList,onSeeAll = {- if (lockedCategory && matchedCategory != null) openProtectedCategory(matchedCategory) else onSelectCategory(categoryName)+ if (lockedCategory != null) openProtectedCategory(lockedCategory) else onSelectCategory(categoryName)},onPinToggle = matchedCategory?.let { { onToggleCategoryPinned(it) } },isPinned = matchedCategory?.id in uiState.pinnedCategoryIds,@@ -1165,7 +1165,7 @@ private fun SeriesVodClassicContent(.filterNot { it == uiState.favoriteCategoryName }.forEach { name ->val matchedCategory = categoryByName[name]- val locked = matchedCategory?.let(isCategoryLocked) == true+ val lockedCategory = matchedCategory?.takeIf(isCategoryLocked)add(VodClassicCategoryOption(key = "category:$name",@@ -1173,10 +1173,10 @@ private fun SeriesVodClassicContent(count = uiState.categoryCounts[name] ?: 0,isSelected = selectedKey == "category:$name",onClick = {- if (locked && matchedCategory != null) openProtectedCategory(matchedCategory) else onSelectCategory(name)+ if (lockedCategory != null) openProtectedCategory(lockedCategory) else onSelectCategory(name)},- onLongClick = matchedCategory?.takeIf { !locked }?.let { { onShowCategoryOptions(name) } },- isLocked = locked+ onLongClick = matchedCategory?.takeIf { lockedCategory == null }?.let { { onShowCategoryOptions(name) } },+ isLocked = lockedCategory != null))}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.ktindex 51ce79e1..d945ef98 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@@ -178,14 +178,10 @@ class SeriesViewModel @Inject constructor(categories}}- val pinnedProviderCategories = visibleProviderCategories.filter { it.id in pinnedCategoryIds }- val unpinnedProviderCategories = visibleProviderCategories.filterNot { it.id in pinnedCategoryIds }SeriesCatalogDependencies(allFavorites = allFavorites,customCategories = customCategories,providerCategories = visibleProviderCategories,- pinnedProviderCategories = pinnedProviderCategories,- unpinnedProviderCategories = unpinnedProviderCategories,providerCategoryCounts = providerCategoryCounts,libraryCount = libraryCount,hiddenCategoryIds = hiddenCategoryIds,@@ -198,8 +194,6 @@ class SeriesViewModel @Inject constructor(allFavorites = dependencies.allFavorites,customCategories = dependencies.customCategories,providerCategories = dependencies.providerCategories,- pinnedProviderCategories = dependencies.pinnedProviderCategories,- unpinnedProviderCategories = dependencies.unpinnedProviderCategories,providerCategoryCounts = dependencies.providerCategoryCounts,libraryCount = dependencies.libraryCount,hiddenCategoryIds = dependencies.hiddenCategoryIds,@@ -242,7 +236,8 @@ class SeriesViewModel @Inject constructor(allFavorites = params.allFavorites,customCategories = params.customCategories,providerCategories = params.providerCategories,- hiddenCategoryIds = params.hiddenCategoryIds+ hiddenCategoryIds = params.hiddenCategoryIds,+ pinnedCategoryIds = params.pinnedCategoryIds).copy(libraryCount = 0),false, false))@@ -256,7 +251,8 @@ class SeriesViewModel @Inject constructor(allFavorites = params.allFavorites,customCategories = params.customCategories,providerCategories = params.providerCategories,- hiddenCategoryIds = params.hiddenCategoryIds+ hiddenCategoryIds = params.hiddenCategoryIds,+ pinnedCategoryIds = params.pinnedCategoryIds).copy(libraryCount = searchResults.size),false, false))@@ -278,7 +274,6 @@ class SeriesViewModel @Inject constructor(selected in providerCategoryNames ||selected in customCategoryNames}- val currentPinnedIds = _uiState.value.pinnedCategoryIds_uiState.update {it.copy(seriesByCategory = snapshot.grouped,@@ -286,7 +281,7 @@ class SeriesViewModel @Inject constructor(categoryCounts = snapshot.categoryCounts,libraryCount = snapshot.libraryCount,providerCategories = snapshot.providerCategories,- pinnedCategoryIds = currentPinnedIds.ifEmpty { snapshot.pinnedCategoryIds },+ pinnedCategoryIds = snapshot.pinnedCategoryIds,selectedCategory = resolvedSelected,selectedCategoryItems = if (resolvedSelected == null) emptyList() else it.selectedCategoryItems,selectedCategoryLoadedCount = if (resolvedSelected == null) 0 else it.selectedCategoryLoadedCount,@@ -1113,7 +1108,8 @@ class SeriesViewModel @Inject constructor(categoryNames = snapshot.categoryNames,categoryCounts = snapshot.categoryCounts,libraryCount = snapshot.libraryCount,- providerCategories = params.providerCategories+ providerCategories = params.providerCategories,+ pinnedCategoryIds = params.pinnedCategoryIds)}@@ -1122,7 +1118,8 @@ class SeriesViewModel @Inject constructor(allFavorites: List<com.streamvault.domain.model.Favorite>,customCategories: List<Category>,providerCategories: List<Category>,- hiddenCategoryIds: Set<Long>+ hiddenCategoryIds: Set<Long>,+ pinnedCategoryIds: Set<Long>): SeriesCatalogSnapshot {val snapshot = buildVodSearchCatalog(items = series,@@ -1141,7 +1138,8 @@ class SeriesViewModel @Inject constructor(categoryNames = snapshot.categoryNames,categoryCounts = snapshot.categoryCounts,libraryCount = snapshot.libraryCount,- providerCategories = providerCategories+ providerCategories = providerCategories,+ pinnedCategoryIds = pinnedCategoryIds)}@@ -1371,8 +1369,6 @@ private data class SeriesCatalogParams(val allFavorites: List<com.streamvault.domain.model.Favorite>,val customCategories: List<Category>,val providerCategories: List<Category>,- val pinnedProviderCategories: List<Category> = emptyList(),- val unpinnedProviderCategories: List<Category> = emptyList(),val providerCategoryCounts: Map<Long, Int>,val libraryCount: Int,val hiddenCategoryIds: Set<Long>,@@ -1385,8 +1381,6 @@ private data class SeriesCatalogDependencies(val allFavorites: List<com.streamvault.domain.model.Favorite>,val customCategories: List<Category>,val providerCategories: List<Category>,- val pinnedProviderCategories: List<Category> = emptyList(),- val unpinnedProviderCategories: List<Category> = emptyList(),val providerCategoryCounts: Map<Long, Int>,val libraryCount: Int,val hiddenCategoryIds: Set<Long>,diff --git a/app/src/test/java/com/streamvault/app/ui/screens/dashboard/DashboardHomeShelvesTest.kt b/app/src/test/java/com/streamvault/app/ui/screens/dashboard/DashboardHomeShelvesTest.ktindex 29c0d231..d0156f47 100644--- a/app/src/test/java/com/streamvault/app/ui/screens/dashboard/DashboardHomeShelvesTest.kt+++ b/app/src/test/java/com/streamvault/app/ui/screens/dashboard/DashboardHomeShelvesTest.kt@@ -47,4 +47,15 @@ class DashboardHomeShelvesTest {AppHomeDashboardShelf.FAVORITE_MOVIES).inOrder()}++ @Test+ fun `resolveVisibleDashboardShelves shows pinned categories when they have content`() {+ val uiState = DashboardUiState(+ homeDashboardShelves = listOf(AppHomeDashboardShelf.PINNED_CATEGORIES),+ pinnedMovieCategories = mapOf("Action" to listOf(Movie(id = 20L, name = "Pinned Pick")))+ )++ assertThat(resolveVisibleDashboardShelves(uiState))+ .containsExactly(AppHomeDashboardShelf.PINNED_CATEGORIES)+ }}