Skip to content

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

Add VOD pinned categories with pin buttons, Home dashboard integration

disclosurez30063591463d
diff --git a/app/src/main/java/com/streamvault/app/ui/components/CategoryRow.kt b/app/src/main/java/com/streamvault/app/ui/components/CategoryRow.kt
index fc1ac6c5..9089154c 100644
--- a/app/src/main/java/com/streamvault/app/ui/components/CategoryRow.kt
+++ b/app/src/main/java/com/streamvault/app/ui/components/CategoryRow.kt
@@ -1,21 +1,32 @@
package com.streamvault.app.ui.components
-import androidx.compose.foundation.layout.*
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.PushPin
+import androidx.compose.material.icons.outlined.PushPin
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
+import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRestorer
import androidx.compose.ui.focus.focusRequester
+import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.res.stringResource
import androidx.tv.material3.Border
import androidx.tv.material3.ClickableSurfaceDefaults
+import androidx.tv.material3.Icon
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Surface
import androidx.tv.material3.Text
@@ -37,6 +48,8 @@ fun <T : Any> CategoryRow(
items: List<T>,
modifier: Modifier = Modifier,
onSeeAll: (() -> Unit)? = null,
+ onPinToggle: (() -> Unit)? = null,
+ isPinned: Boolean = false,
keySelector: ((T) -> Any)? = null,
contentTypeSelector: ((T) -> Any?)? = null,
itemContent: @Composable (T) -> Unit
@@ -50,40 +63,78 @@ fun <T : Any> CategoryRow(
) {
if (onSeeAll != null) {
val seeAllFocusRequester = remember { FocusRequester() }
+ val pinFocusRequester = remember { FocusRequester() }
Column(
modifier = Modifier
.fillMaxWidth()
.padding(start = 20.dp, end = 20.dp, top = 14.dp, bottom = 6.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
- AppSectionHeader(title = title)
- Surface(
- onClick = onSeeAll,
- modifier = Modifier
- .focusRequester(seeAllFocusRequester)
- .mouseClickable(
- focusRequester = seeAllFocusRequester,
- onClick = onSeeAll
+ Row(
+ modifier = Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.spacedBy(8.dp),
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ AppSectionHeader(title = title, modifier = Modifier.weight(1f))
+ Surface(
+ onClick = onSeeAll,
+ modifier = Modifier
+ .focusRequester(seeAllFocusRequester)
+ .mouseClickable(
+ focusRequester = seeAllFocusRequester,
+ onClick = onSeeAll
+ ),
+ colors = ClickableSurfaceDefaults.colors(
+ containerColor = SurfaceElevated,
+ focusedContainerColor = SurfaceHighlight,
+ contentColor = Primary,
+ focusedContentColor = OnSurface
),
- colors = ClickableSurfaceDefaults.colors(
- containerColor = SurfaceElevated,
- focusedContainerColor = SurfaceHighlight,
- contentColor = Primary,
- focusedContentColor = OnSurface
- ),
- shape = ClickableSurfaceDefaults.shape(RoundedCornerShape(999.dp)),
- border = ClickableSurfaceDefaults.border(
- focusedBorder = Border(
- border = BorderStroke(2.dp, FocusBorder),
- shape = RoundedCornerShape(999.dp)
+ shape = ClickableSurfaceDefaults.shape(RoundedCornerShape(999.dp)),
+ border = ClickableSurfaceDefaults.border(
+ focusedBorder = Border(
+ border = BorderStroke(2.dp, FocusBorder),
+ shape = RoundedCornerShape(999.dp)
+ )
)
- )
- ) {
- Text(
- text = stringResource(R.string.category_see_all),
- modifier = Modifier.padding(horizontal = 12.dp, vertical = 7.dp),
- style = MaterialTheme.typography.labelMedium
- )
+ ) {
+ Text(
+ text = stringResource(R.string.category_see_all),
+ modifier = Modifier.padding(horizontal = 12.dp, vertical = 7.dp),
+ style = MaterialTheme.typography.labelMedium
+ )
+ }
+ if (onPinToggle != null) {
+ Surface(
+ onClick = onPinToggle,
+ modifier = Modifier
+ .focusRequester(pinFocusRequester)
+ .mouseClickable(
+ focusRequester = pinFocusRequester,
+ onClick = onPinToggle
+ ),
+ colors = ClickableSurfaceDefaults.colors(
+ containerColor = if (isPinned) Primary.copy(alpha = 0.18f) else SurfaceElevated,
+ focusedContainerColor = SurfaceHighlight,
+ contentColor = if (isPinned) Primary else OnSurface,
+ focusedContentColor = OnSurface
+ ),
+ shape = ClickableSurfaceDefaults.shape(RoundedCornerShape(999.dp)),
+ border = ClickableSurfaceDefaults.border(
+ focusedBorder = Border(
+ border = BorderStroke(2.dp, FocusBorder),
+ shape = RoundedCornerShape(999.dp)
+ )
+ )
+ ) {
+ Icon(
+ imageVector = if (isPinned) Icons.Filled.PushPin else Icons.Outlined.PushPin,
+ contentDescription = if (isPinned) stringResource(R.string.category_unpin) else stringResource(R.string.category_pin),
+ modifier = Modifier.padding(8.dp),
+ tint = if (isPinned) Primary else OnSurface
+ )
+ }
+ }
}
}
} else {
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardHomeShelves.kt b/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardHomeShelves.kt
index 4a5292d6..3d852904 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardHomeShelves.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardHomeShelves.kt
@@ -13,6 +13,7 @@ internal fun DashboardUiState.hasContentFor(shelf: AppHomeDashboardShelf): Boole
AppHomeDashboardShelf.RECENT_CHANNELS -> recentChannels.isNotEmpty()
AppHomeDashboardShelf.LIVE_SHORTCUTS -> liveShortcuts.isNotEmpty()
AppHomeDashboardShelf.CONTINUE_WATCHING -> continueWatching.isNotEmpty()
+ AppHomeDashboardShelf.PINNED_CATEGORIES -> pinnedMovieCategories.isNotEmpty() || pinnedSeriesCategories.isNotEmpty()
AppHomeDashboardShelf.RECENT_MOVIES -> recentMovies.isNotEmpty()
AppHomeDashboardShelf.RECENT_SERIES -> recentSeries.isNotEmpty()
AppHomeDashboardShelf.FAVORITE_MOVIES -> favoriteMovies.isNotEmpty()
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardScreen.kt
index 6c20435b..4595f514 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardScreen.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardScreen.kt
@@ -76,6 +76,7 @@ import com.streamvault.app.ui.design.AppColors.TextPrimary as TextPrimary
import com.streamvault.app.ui.design.AppColors.TextTertiary as OnSurfaceDim
import com.streamvault.app.ui.design.AppColors.TextTertiary as TextTertiary
import com.streamvault.domain.model.AppHomeDashboardShelf
+import com.streamvault.domain.model.Category
import com.streamvault.domain.model.Channel
import com.streamvault.domain.model.Movie
import com.streamvault.domain.model.PlaybackHistory
@@ -226,6 +227,13 @@ fun DashboardScreen(
onItemClick = onContinueWatchingItemClick
)
+ AppHomeDashboardShelf.PINNED_CATEGORIES -> PinnedCategoriesSection(
+ pinnedMovieCategories = uiState.pinnedMovieCategories,
+ pinnedSeriesCategories = uiState.pinnedSeriesCategories,
+ onMovieClick = onMovieClick,
+ onSeriesClick = onSeriesClick
+ )
+
AppHomeDashboardShelf.RECENT_MOVIES -> CategoryRow(
title = stringResource(R.string.dashboard_recent_movies),
items = uiState.recentMovies,
@@ -869,6 +877,49 @@ private fun EmptyDashboard(
}
}
+@Composable
+private fun PinnedCategoriesSection(
+ pinnedMovieCategories: Map<String, List<Movie>>,
+ pinnedSeriesCategories: Map<String, List<Series>>,
+ onMovieClick: (Movie) -> Unit,
+ onSeriesClick: (Series) -> Unit
+) {
+ Column {
+ pinnedMovieCategories.forEach { (categoryName, movies) ->
+ if (movies.isNotEmpty()) {
+ CategoryRow(
+ title = categoryName,
+ items = movies,
+ keySelector = { it.id }
+ ) { movie ->
+ MovieCard(
+ movie = movie,
+ isLocked = false,
+ onClick = { onMovieClick(movie) },
+ onLongClick = {}
+ )
+ }
+ }
+ }
+ pinnedSeriesCategories.forEach { (categoryName, seriesList) ->
+ if (seriesList.isNotEmpty()) {
+ CategoryRow(
+ title = categoryName,
+ items = seriesList,
+ keySelector = { it.id }
+ ) { series ->
+ SeriesCard(
+ series = series,
+ isLocked = false,
+ onClick = { onSeriesClick(series) },
+ onLongClick = {}
+ )
+ }
+ }
+ }
+ }
+}
+
@Composable
private fun rememberDashboardSections(
uiState: DashboardUiState
@@ -886,7 +937,9 @@ private fun rememberDashboardSections(
uiState.recentMovies,
uiState.recentSeries,
uiState.topRatedMovies,
- uiState.recommendedMovies
+ uiState.recommendedMovies,
+ uiState.pinnedMovieCategories,
+ uiState.pinnedSeriesCategories
) {
resolveVisibleDashboardShelves(uiState)
}
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardShelfCustomizationDialog.kt b/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardShelfCustomizationDialog.kt
index 7c5aeeda..e814db11 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardShelfCustomizationDialog.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardShelfCustomizationDialog.kt
@@ -243,6 +243,7 @@ private fun AppHomeDashboardShelf.labelResId(): Int = when (this) {
AppHomeDashboardShelf.CONTINUE_WATCHING -> R.string.dashboard_continue_watching
AppHomeDashboardShelf.RECENT_MOVIES -> R.string.dashboard_recent_movies
AppHomeDashboardShelf.RECENT_SERIES -> R.string.dashboard_recent_series
+ AppHomeDashboardShelf.PINNED_CATEGORIES -> R.string.dashboard_pinned_categories
AppHomeDashboardShelf.FAVORITE_MOVIES -> R.string.dashboard_favorite_movies
AppHomeDashboardShelf.FAVORITE_SERIES -> R.string.dashboard_favorite_series
AppHomeDashboardShelf.CONTINUE_WATCHING_MOVIES -> R.string.dashboard_continue_watching_movies
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.kt
index 108324b6..17a2b1f5 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
@@ -161,6 +161,48 @@ class DashboardViewModel @Inject constructor(
}
}
+ private fun observePinnedMovieCategories(providerId: Long): Flow<Map<String, List<Movie>>> =
+ preferencesRepository.getPinnedCategoryIds(providerId, ContentType.MOVIE)
+ .flatMapLatest { pinnedIds ->
+ if (pinnedIds.isEmpty()) {
+ flowOf(emptyMap())
+ } else {
+ movieRepository.getCategories(providerId).flatMapLatest { categories ->
+ val pinned = categories.filter { it.id in pinnedIds }
+ 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(flows) { results -> results.toMap() }
+ }
+ }
+ }
+ }
+
+ private fun observePinnedSeriesCategories(providerId: Long): Flow<Map<String, List<Series>>> =
+ preferencesRepository.getPinnedCategoryIds(providerId, ContentType.SERIES)
+ .flatMapLatest { pinnedIds ->
+ if (pinnedIds.isEmpty()) {
+ flowOf(emptyMap())
+ } else {
+ seriesRepository.getCategories(providerId).flatMapLatest { categories ->
+ val pinned = categories.filter { it.id in pinnedIds }
+ 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(flows) { results -> results.toMap() }
+ }
+ }
+ }
+ }
+
private fun observeDashboard(
provider: Provider,
liveProviderIds: List<Long>,
@@ -238,9 +280,21 @@ class DashboardViewModel @Inject constructor(
recommendedMovies = recommendedMovies
)
}
+ val pinnedMovieCategoriesShelf = observePinnedMovieCategories(provider.id).onStart { emit(emptyMap()) }
+ val pinnedSeriesCategoriesShelf = observePinnedSeriesCategories(provider.id).onStart { emit(emptyMap()) }
+ val contentShelvesWithPinned = combine(
+ contentShelves,
+ pinnedMovieCategoriesShelf,
+ pinnedSeriesCategoriesShelf
+ ) { shelves, pinnedMovies, pinnedSeries ->
+ shelves.copy(
+ pinnedMovieCategories = pinnedMovies,
+ pinnedSeriesCategories = pinnedSeries
+ )
+ }
val baseSnapshot = combine(
- contentShelves,
+ contentShelvesWithPinned,
buildLiveContext(
providerIds = liveProviderIds,
lastVisitedProviderId = provider.id.takeIf { combinedProfileId == null }
@@ -258,7 +312,9 @@ class DashboardViewModel @Inject constructor(
movieCount = movieCount,
seriesCount = seriesCount,
homeDashboardShelves = AppHomeDashboardShelf.defaultOrder,
- updateNotice = null
+ updateNotice = null,
+ pinnedMovieCategories = shelves.pinnedMovieCategories,
+ pinnedSeriesCategories = shelves.pinnedSeriesCategories
)
}
@@ -285,6 +341,8 @@ class DashboardViewModel @Inject constructor(
recentSeries = snapshot.shelves.recentSeries,
topRatedMovies = snapshot.shelves.topRatedMovies,
recommendedMovies = snapshot.shelves.recommendedMovies,
+ pinnedMovieCategories = snapshot.pinnedMovieCategories,
+ pinnedSeriesCategories = snapshot.pinnedSeriesCategories,
lastLiveCategory = snapshot.liveContext.lastVisitedCategory,
liveShortcuts = snapshot.liveContext.shortcuts,
currentCombinedProfileId = combinedProfileId,
@@ -819,7 +877,9 @@ private data class DashboardContentShelves(
val recentMovies: List<Movie>,
val recentSeries: List<Series>,
val topRatedMovies: List<Movie> = emptyList(),
- val recommendedMovies: List<Movie> = emptyList()
+ val recommendedMovies: List<Movie> = emptyList(),
+ val pinnedMovieCategories: Map<String, List<Movie>> = emptyMap(),
+ val pinnedSeriesCategories: Map<String, List<Series>> = emptyMap()
)
private data class DashboardSnapshot(
@@ -829,7 +889,9 @@ private data class DashboardSnapshot(
val movieCount: Int,
val seriesCount: Int,
val homeDashboardShelves: List<AppHomeDashboardShelf>,
- val updateNotice: DashboardUpdateNotice?
+ val updateNotice: DashboardUpdateNotice?,
+ val pinnedMovieCategories: Map<String, List<Movie>> = emptyMap(),
+ val pinnedSeriesCategories: Map<String, List<Series>> = emptyMap()
)
private data class DashboardCachedUpdateRelease(
@@ -856,6 +918,8 @@ data class DashboardUiState(
val recentSeries: List<Series> = emptyList(),
val topRatedMovies: List<Movie> = emptyList(),
val recommendedMovies: List<Movie> = emptyList(),
+ val pinnedMovieCategories: Map<String, List<Movie>> = emptyMap(),
+ val pinnedSeriesCategories: Map<String, List<Series>> = emptyMap(),
val lastLiveCategory: Category? = null,
val liveShortcuts: List<DashboardLiveShortcut> = emptyList(),
val feature: DashboardFeature = DashboardFeature(),
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.kt
index 4a6c273d..5ddc32ae 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
@@ -255,6 +255,7 @@ fun MoviesScreen(
onLoadMore = viewModel::loadMoreSelectedCategory,
onLoadMorePreviewRows = viewModel::loadMorePreviewRows,
onDismissReorder = viewModel::exitCategoryReorderMode,
+ onToggleCategoryPinned = viewModel::toggleCategoryPinned,
initialFocusRequester = initialContentFocusRequester
)
}
@@ -293,6 +294,10 @@ fun MoviesScreen(
com.streamvault.app.ui.components.dialogs.CategoryOptionsDialog(
category = category,
onDismissRequest = { viewModel.dismissCategoryOptions() },
+ isPinned = category.id in uiState.pinnedCategoryIds,
+ onTogglePinned = if (!category.isVirtual) {
+ { viewModel.toggleCategoryPinned(category) }
+ } else null,
onHide = if (!category.isVirtual) {
{ viewModel.hideCategory(category) }
} else null,
@@ -351,6 +356,7 @@ private fun MoviesVodContent(
onLoadMore: () -> Unit,
onLoadMorePreviewRows: () -> Unit,
onDismissReorder: () -> Unit,
+ onToggleCategoryPinned: (Category) -> Unit,
initialFocusRequester: FocusRequester
) {
val screenWidth = LocalConfiguration.current.screenWidthDp.dp
@@ -436,6 +442,18 @@ private fun MoviesVodContent(
}
.toList()
}
+ val pinnedCatEntries = remember(catEntries, uiState.pinnedCategoryIds, categoryByName) {
+ catEntries.filter { (name, _) ->
+ val category = categoryByName[name]
+ category != null && category.id in uiState.pinnedCategoryIds
+ }
+ }
+ val unpinnedCatEntries = remember(catEntries, uiState.pinnedCategoryIds, categoryByName) {
+ catEntries.filter { (name, _) ->
+ val category = categoryByName[name]
+ category == null || category.id !in uiState.pinnedCategoryIds
+ }
+ }
val fallbackMovieId = if (heroMovie == null) {
favoriteMovies.firstOrNull()?.id
?: freshMovies.firstOrNull()?.id
@@ -618,6 +636,34 @@ private fun MoviesVodContent(
}
}
}
+ if (pinnedCatEntries.isNotEmpty()) {
+ items(pinnedCatEntries, key = { it.key }) { entry ->
+ val categoryName = entry.key
+ val movies = entry.value
+ val matchedCategory = categoryByName[categoryName]
+ val lockedCategory = matchedCategory?.let(isCategoryLocked) == true
+ CategoryRow(
+ title = categoryName,
+ items = movies,
+ onSeeAll = {
+ if (lockedCategory && matchedCategory != null) openProtectedCategory(matchedCategory) else onSelectCategory(categoryName)
+ },
+ onPinToggle = matchedCategory?.let { { onToggleCategoryPinned(it) } },
+ isPinned = matchedCategory?.id in uiState.pinnedCategoryIds,
+ keySelector = { it.id }
+ ) { movie ->
+ val isLocked = isMovieLocked(movie)
+ MovieCard(
+ movie = movie,
+ isLocked = isLocked,
+ onClick = { if (isLocked) onProtectedMovieClick(movie) else onMovieClick(movie) },
+ onLongClick = { onShowDialog(movie) }
+ ,
+ modifier = if (movie.id == fallbackMovieId) Modifier.focusRequester(initialFocusRequester) else Modifier
+ )
+ }
+ }
+ }
if (freshMovies.isNotEmpty()) {
item(key = "fresh_row") {
CategoryRow(
@@ -654,7 +700,7 @@ private fun MoviesVodContent(
}
}
}
- items(catEntries, key = { it.key }) { entry ->
+ items(unpinnedCatEntries, key = { it.key }) { entry ->
val categoryName = entry.key
val movies = entry.value
val matchedCategory = categoryByName[categoryName]
@@ -665,6 +711,8 @@ private fun MoviesVodContent(
onSeeAll = {
if (lockedCategory && matchedCategory != null) openProtectedCategory(matchedCategory) else onSelectCategory(categoryName)
},
+ onPinToggle = matchedCategory?.let { { onToggleCategoryPinned(it) } },
+ isPinned = matchedCategory?.id in uiState.pinnedCategoryIds,
keySelector = { it.id }
) { movie ->
val isLocked = isMovieLocked(movie)
@@ -1042,79 +1090,93 @@ private fun MoviesVodClassicContent(
uiState.continueWatching.map { it.contentId }.distinct().size
}
val recentCount = uiState.libraryLensRows[MovieLibraryLens.FRESH]?.size ?: 0
- val railOptions = remember(
- visibleCategoryNames,
- uiState.categoryCounts,
- uiState.favoriteCategoryName,
- uiState.selectedCategory,
- selectedFilterType,
- categoryQuery,
- continueCount,
- recentCount,
- uiState.libraryCount,
- uiState.unlockedCategoryIds,
- uiState.parentalControlLevel
- ) {
- buildList {
- add(
- VodClassicCategoryOption(
- key = "all",
- label = allLabel,
- count = uiState.libraryCount,
- isSelected = selectedKey == "all",
- onClick = onSelectFullLibraryBrowse
+ val pinnedCategoryNames = remember(visibleCategoryNames, uiState.pinnedCategoryIds, categoryByName) {
+ visibleCategoryNames.filter { name ->
+ val category = categoryByName[name]
+ category != null && category.id in uiState.pinnedCategoryIds
+ }
+ }
+ val unpinnedCategoryNames = remember(visibleCategoryNames, uiState.pinnedCategoryIds, categoryByName) {
+ visibleCategoryNames.filter { name ->
+ val category = categoryByName[name]
+ category == null || category.id !in uiState.pinnedCategoryIds
+ }
+ }
+ val railOptions = remember(
+ visibleCategoryNames,
+ pinnedCategoryNames,
+ unpinnedCategoryNames,
+ uiState.categoryCounts,
+ uiState.favoriteCategoryName,
+ uiState.selectedCategory,
+ selectedFilterType,
+ categoryQuery,
+ continueCount,
+ recentCount,
+ uiState.libraryCount,
+ uiState.unlockedCategoryIds,
+ uiState.parentalControlLevel
+ ) {
+ buildList {
+ add(
+ VodClassicCategoryOption(
+ key = "all",
+ label = allLabel,
+ count = uiState.libraryCount,
+ isSelected = selectedKey == "all",
+ onClick = onSelectFullLibraryBrowse
+ )
)
- )
- add(
- VodClassicCategoryOption(
- key = "favorites",
- label = uiState.favoriteCategoryName,
- count = uiState.categoryCounts[uiState.favoriteCategoryName] ?: 0,
- isSelected = selectedKey == "favorites",
- onClick = { onSelectCategory(uiState.favoriteCategoryName) }
+ add(
+ VodClassicCategoryOption(
+ key = "favorites",
+ label = uiState.favoriteCategoryName,
+ count = uiState.categoryCounts[uiState.favoriteCategoryName] ?: 0,
+ isSelected = selectedKey == "favorites",
+ onClick = { onSelectCategory(uiState.favoriteCategoryName) }
+ )
)
- )
- add(
- VodClassicCategoryOption(
- key = "continue",
- label = continueLabel,
- count = continueCount,
- isSelected = selectedKey == "continue",
- onClick = onOpenContinueWatching
+ add(
+ VodClassicCategoryOption(
+ key = "continue",
+ label = continueLabel,
+ count = continueCount,
+ isSelected = selectedKey == "continue",
+ onClick = onOpenContinueWatching
+ )
)
- )
- add(
- VodClassicCategoryOption(
- key = "recent",
- label = recentLabel,
- count = recentCount,
- isSelected = selectedKey == "recent",
- onClick = onOpenFresh
+ add(
+ VodClassicCategoryOption(
+ key = "recent",
+ label = recentLabel,
+ count = recentCount,
+ isSelected = selectedKey == "recent",
+ onClick = onOpenFresh
+ )
)
- )
- visibleCategoryNames
- .filterNot { it == uiState.favoriteCategoryName }
- .forEach { name ->
- val matchedCategory = categoryByName[name]
- val locked = matchedCategory?.let(isCategoryLocked) == true
- add(
- VodClassicCategoryOption(
- key = "category:$name",
- label = name,
- count = uiState.categoryCounts[name] ?: 0,
- isSelected = selectedKey == "category:$name",
- onClick = {
- if (locked && matchedCategory != null) openProtectedCategory(matchedCategory) else onSelectCategory(name)
- },
- onLongClick = matchedCategory?.takeIf { !locked }?.let { { onShowCategoryOptions(name) } },
- isLocked = locked
+ (pinnedCategoryNames + unpinnedCategoryNames)
+ .filterNot { it == uiState.favoriteCategoryName }
+ .forEach { name ->
+ val matchedCategory = categoryByName[name]
+ val locked = matchedCategory?.let(isCategoryLocked) == true
+ add(
+ VodClassicCategoryOption(
+ key = "category:$name",
+ label = name,
+ count = uiState.categoryCounts[name] ?: 0,
+ isSelected = selectedKey == "category:$name",
+ onClick = {
+ if (locked && matchedCategory != null) openProtectedCategory(matchedCategory) else onSelectCategory(name)
+ },
+ onLongClick = matchedCategory?.takeIf { !locked }?.let { { onShowCategoryOptions(name) } },
+ isLocked = locked
+ )
)
- )
- }
- }.filter { option ->
- categoryQuery.isBlank() || option.label.contains(categoryQuery.trim(), ignoreCase = true)
+ }
+ }.filter { option ->
+ categoryQuery.isBlank() || option.label.contains(categoryQuery.trim(), ignoreCase = true)
+ }
}
- }
VodClassicSplitLayout(
railTitle = stringResource(R.string.nav_movies),
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 0ee0ab63..123ec9a9 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
@@ -156,7 +156,8 @@ class MoviesViewModel @Inject constructor(
movieRepository.getCategoryItemCounts(provider.id),
movieRepository.getLibraryCount(provider.id),
preferencesRepository.getHiddenCategoryIds(provider.id, ContentType.MOVIE),
- preferencesRepository.getCategorySortMode(provider.id, ContentType.MOVIE)
+ preferencesRepository.getCategorySortMode(provider.id, ContentType.MOVIE),
+ preferencesRepository.getPinnedCategoryIds(provider.id, ContentType.MOVIE)
) { values ->
val allFavorites = values[0] as List<com.streamvault.domain.model.Favorite>
val customCategories = values[1] as List<Category>
@@ -165,6 +166,7 @@ class MoviesViewModel @Inject constructor(
val libraryCount = values[4] as Int
val hiddenCategoryIds = values[5] as Set<Long>
val sortMode = values[6] as CategorySortMode
+ val pinnedCategoryIds = values[7] as Set<Long>
val visibleProviderCategories = applyProviderCategoryDisplayPreferences(
categories = providerCategories,
hiddenCategoryIds = hiddenCategoryIds,
@@ -176,13 +178,18 @@ 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,
+ pinnedCategoryIds = pinnedCategoryIds,
categorySortMode = sortMode
)
}.combine(searchQueryForBrowse) { dependencies, query ->
@@ -191,9 +198,12 @@ 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,
+ pinnedCategoryIds = dependencies.pinnedCategoryIds,
categorySortMode = dependencies.categorySortMode,
query = query
)
@@ -272,6 +282,7 @@ class MoviesViewModel @Inject constructor(
selected in providerCategoryNames ||
selected in customCategoryNames
}
+ val currentPinnedIds = _uiState.value.pinnedCategoryIds
_uiState.update {
it.copy(
moviesByCategory = snapshot.grouped,
@@ -279,6 +290,7 @@ class MoviesViewModel @Inject constructor(
categoryCounts = snapshot.categoryCounts,
libraryCount = snapshot.libraryCount,
providerCategories = snapshot.providerCategories,
+ pinnedCategoryIds = currentPinnedIds.ifEmpty { snapshot.pinnedCategoryIds },
selectedCategory = resolvedSelected,
selectedCategoryItems = if (resolvedSelected == null) emptyList() else it.selectedCategoryItems,
selectedCategoryLoadedCount = if (resolvedSelected == null) 0 else it.selectedCategoryLoadedCount,
@@ -532,6 +544,17 @@ class MoviesViewModel @Inject constructor(
_uiState.update { it.copy(categories = categories) }
}
}
+
+ viewModelScope.launch {
+ providerRepository.getActiveProvider()
+ .filterNotNull()
+ .flatMapLatest { provider ->
+ preferencesRepository.getPinnedCategoryIds(provider.id, ContentType.MOVIE)
+ }
+ .collect { pinnedIds ->
+ _uiState.update { it.copy(pinnedCategoryIds = pinnedIds) }
+ }
+ }
}
fun selectCategory(categoryName: String?) {
@@ -898,6 +921,26 @@ class MoviesViewModel @Inject constructor(
}
}
+ fun toggleCategoryPinned(category: Category) {
+ if (category.isVirtual) return
+ val providerId = activeProviderId ?: return
+ val shouldPin = category.id !in _uiState.value.pinnedCategoryIds
+ viewModelScope.launch {
+ preferencesRepository.setCategoryPinned(
+ providerId = providerId,
+ type = ContentType.MOVIE,
+ categoryId = category.id,
+ pinned = shouldPin
+ )
+ dismissCategoryOptions()
+ _uiState.update {
+ it.copy(
+ userMessage = if (shouldPin) "Pinned ${category.name}" else "Unpinned ${category.name}"
+ )
+ }
+ }
+ }
+
fun requestRenameGroup(category: Category) {
if (!category.isVirtual || category.id == VodBrowseDefaults.FAVORITES_SENTINEL_ID) return
_uiState.update {
@@ -1326,9 +1369,12 @@ 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>,
+ val pinnedCategoryIds: Set<Long> = emptySet(),
val categorySortMode: CategorySortMode,
val query: String
)
@@ -1337,9 +1383,12 @@ 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>,
+ val pinnedCategoryIds: Set<Long> = emptySet(),
val categorySortMode: CategorySortMode
)
@@ -1348,7 +1397,8 @@ private data class MovieCatalogSnapshot(
val categoryNames: List<String>,
val categoryCounts: Map<String, Int>,
val libraryCount: Int,
- val providerCategories: List<Category>
+ val providerCategories: List<Category>,
+ val pinnedCategoryIds: Set<Long> = emptySet()
)
private data class MovieLibraryLensDependencies(
@@ -1430,6 +1480,7 @@ data class MoviesUiState(
val selectedMovieForDialog: Movie? = null,
val categories: List<Category> = emptyList(),
val providerCategories: List<Category> = emptyList(),
+ val pinnedCategoryIds: Set<Long> = emptySet(),
val dialogGroupMemberships: List<Long> = emptyList(),
val userMessage: String? = null,
val selectedCategoryForOptions: Category? = null,
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.kt
index 6c6076b5..c4866fd5 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
@@ -255,6 +255,7 @@ fun SeriesScreen(
onLoadMore = viewModel::loadMoreSelectedCategory,
onLoadMorePreviewRows = viewModel::loadMorePreviewRows,
onDismissReorder = viewModel::exitCategoryReorderMode,
+ onToggleCategoryPinned = viewModel::toggleCategoryPinned,
initialFocusRequester = initialContentFocusRequester
)
}
@@ -301,6 +302,10 @@ fun SeriesScreen(
com.streamvault.app.ui.components.dialogs.CategoryOptionsDialog(
category = category,
onDismissRequest = { viewModel.dismissCategoryOptions() },
+ isPinned = category.id in uiState.pinnedCategoryIds,
+ onTogglePinned = if (!category.isVirtual) {
+ { viewModel.toggleCategoryPinned(category) }
+ } else null,
onHide = if (!category.isVirtual) {
{ viewModel.hideCategory(category) }
} else null,
@@ -349,6 +354,7 @@ private fun SeriesVodContent(
onLoadMore: () -> Unit,
onLoadMorePreviewRows: () -> Unit,
onDismissReorder: () -> Unit,
+ onToggleCategoryPinned: (Category) -> Unit,
initialFocusRequester: FocusRequester
) {
val screenWidth = LocalConfiguration.current.screenWidthDp.dp
@@ -435,6 +441,18 @@ private fun SeriesVodContent(
}
.toList()
}
+ val pinnedCatEntries = remember(catEntries, uiState.pinnedCategoryIds, categoryByName) {
+ catEntries.filter { (name, _) ->
+ val category = categoryByName[name]
+ category != null && category.id in uiState.pinnedCategoryIds
+ }
+ }
+ val unpinnedCatEntries = remember(catEntries, uiState.pinnedCategoryIds, categoryByName) {
+ catEntries.filter { (name, _) ->
+ val category = categoryByName[name]
+ category == null || category.id !in uiState.pinnedCategoryIds
+ }
+ }
val fallbackSeriesId = if (heroSeries == null) {
favoriteSeries.firstOrNull()?.id
?: freshSeries.firstOrNull()?.id
@@ -626,6 +644,33 @@ private fun SeriesVodContent(
}
}
}
+ if (pinnedCatEntries.isNotEmpty()) {
+ items(pinnedCatEntries, key = { it.key }) { entry ->
+ val categoryName = entry.key
+ val seriesList = entry.value
+ val matchedCategory = categoryByName[categoryName]
+ val lockedCategory = matchedCategory?.let(isCategoryLocked) == true
+ CategoryRow(
+ title = categoryName,
+ items = seriesList,
+ onSeeAll = {
+ if (lockedCategory && matchedCategory != null) openProtectedCategory(matchedCategory) else onSelectCategory(categoryName)
+ },
+ onPinToggle = matchedCategory?.let { { onToggleCategoryPinned(it) } },
+ isPinned = matchedCategory?.id in uiState.pinnedCategoryIds,
+ keySelector = { it.id }
+ ) { series ->
+ val isLocked = isSeriesLocked(series)
+ SeriesCard(
+ series = series,
+ isLocked = isLocked,
+ onClick = { if (isLocked) onProtectedSeriesClick(series) else onSeriesClick(series) },
+ onLongClick = { onShowDialog(series) },
+ modifier = if (series.id == fallbackSeriesId) Modifier.focusRequester(initialFocusRequester) else Modifier
+ )
+ }
+ }
+ }
if (freshSeries.isNotEmpty()) {
item(key = "fresh_row") {
CategoryRow(
@@ -662,7 +707,7 @@ private fun SeriesVodContent(
}
}
}
- items(catEntries, key = { it.key }) { entry ->
+ items(unpinnedCatEntries, key = { it.key }) { entry ->
val categoryName = entry.key
val seriesList = entry.value
val matchedCategory = categoryByName[categoryName]
@@ -673,6 +718,8 @@ private fun SeriesVodContent(
onSeeAll = {
if (lockedCategory && matchedCategory != null) openProtectedCategory(matchedCategory) else onSelectCategory(categoryName)
},
+ onPinToggle = matchedCategory?.let { { onToggleCategoryPinned(it) } },
+ isPinned = matchedCategory?.id in uiState.pinnedCategoryIds,
keySelector = { it.id }
) { series ->
val isLocked = isSeriesLocked(series)
@@ -1050,79 +1097,93 @@ private fun SeriesVodClassicContent(
uiState.continueWatching.map { it.seriesId ?: it.contentId }.distinct().size
}
val recentCount = uiState.libraryLensRows[SeriesLibraryLens.FRESH]?.size ?: 0
- val railOptions = remember(
- visibleCategoryNames,
- uiState.categoryCounts,
- uiState.favoriteCategoryName,
- uiState.selectedCategory,
- selectedFilterType,
- categoryQuery,
- continueCount,
- recentCount,
- uiState.libraryCount,
- uiState.unlockedCategoryIds,
- uiState.parentalControlLevel
- ) {
- buildList {
- add(
- VodClassicCategoryOption(
- key = "all",
- label = allLabel,
- count = uiState.libraryCount,
- isSelected = selectedKey == "all",
- onClick = onSelectFullLibraryBrowse
+ val pinnedCategoryNames = remember(visibleCategoryNames, uiState.pinnedCategoryIds, categoryByName) {
+ visibleCategoryNames.filter { name ->
+ val category = categoryByName[name]
+ category != null && category.id in uiState.pinnedCategoryIds
+ }
+ }
+ val unpinnedCategoryNames = remember(visibleCategoryNames, uiState.pinnedCategoryIds, categoryByName) {
+ visibleCategoryNames.filter { name ->
+ val category = categoryByName[name]
+ category == null || category.id !in uiState.pinnedCategoryIds
+ }
+ }
+ val railOptions = remember(
+ visibleCategoryNames,
+ pinnedCategoryNames,
+ unpinnedCategoryNames,
+ uiState.categoryCounts,
+ uiState.favoriteCategoryName,
+ uiState.selectedCategory,
+ selectedFilterType,
+ categoryQuery,
+ continueCount,
+ recentCount,
+ uiState.libraryCount,
+ uiState.unlockedCategoryIds,
+ uiState.parentalControlLevel
+ ) {
+ buildList {
+ add(
+ VodClassicCategoryOption(
+ key = "all",
+ label = allLabel,
+ count = uiState.libraryCount,
+ isSelected = selectedKey == "all",
+ onClick = onSelectFullLibraryBrowse
+ )
)
- )
- add(
- VodClassicCategoryOption(
- key = "favorites",
- label = uiState.favoriteCategoryName,
- count = uiState.categoryCounts[uiState.favoriteCategoryName] ?: 0,
- isSelected = selectedKey == "favorites",
- onClick = { onSelectCategory(uiState.favoriteCategoryName) }
+ add(
+ VodClassicCategoryOption(
+ key = "favorites",
+ label = uiState.favoriteCategoryName,
+ count = uiState.categoryCounts[uiState.favoriteCategoryName] ?: 0,
+ isSelected = selectedKey == "favorites",
+ onClick = { onSelectCategory(uiState.favoriteCategoryName) }
+ )
)
- )
- add(
- VodClassicCategoryOption(
- key = "continue",
- label = continueLabel,
- count = continueCount,
- isSelected = selectedKey == "continue",
- onClick = onOpenContinueWatching
+ add(
+ VodClassicCategoryOption(
+ key = "continue",
+ label = continueLabel,
+ count = continueCount,
+ isSelected = selectedKey == "continue",
+ onClick = onOpenContinueWatching
+ )
)
- )
- add(
- VodClassicCategoryOption(
- key = "recent",
- label = recentLabel,
- count = recentCount,
- isSelected = selectedKey == "recent",
- onClick = onOpenFresh
+ add(
+ VodClassicCategoryOption(
+ key = "recent",
+ label = recentLabel,
+ count = recentCount,
+ isSelected = selectedKey == "recent",
+ onClick = onOpenFresh
+ )
)
- )
- visibleCategoryNames
- .filterNot { it == uiState.favoriteCategoryName }
- .forEach { name ->
- val matchedCategory = categoryByName[name]
- val locked = matchedCategory?.let(isCategoryLocked) == true
- add(
- VodClassicCategoryOption(
- key = "category:$name",
- label = name,
- count = uiState.categoryCounts[name] ?: 0,
- isSelected = selectedKey == "category:$name",
- onClick = {
- if (locked && matchedCategory != null) openProtectedCategory(matchedCategory) else onSelectCategory(name)
- },
- onLongClick = matchedCategory?.takeIf { !locked }?.let { { onShowCategoryOptions(name) } },
- isLocked = locked
+ (pinnedCategoryNames + unpinnedCategoryNames)
+ .filterNot { it == uiState.favoriteCategoryName }
+ .forEach { name ->
+ val matchedCategory = categoryByName[name]
+ val locked = matchedCategory?.let(isCategoryLocked) == true
+ add(
+ VodClassicCategoryOption(
+ key = "category:$name",
+ label = name,
+ count = uiState.categoryCounts[name] ?: 0,
+ isSelected = selectedKey == "category:$name",
+ onClick = {
+ if (locked && matchedCategory != null) openProtectedCategory(matchedCategory) else onSelectCategory(name)
+ },
+ onLongClick = matchedCategory?.takeIf { !locked }?.let { { onShowCategoryOptions(name) } },
+ isLocked = locked
+ )
)
- )
- }
- }.filter { option ->
- categoryQuery.isBlank() || option.label.contains(categoryQuery.trim(), ignoreCase = true)
+ }
+ }.filter { option ->
+ categoryQuery.isBlank() || option.label.contains(categoryQuery.trim(), ignoreCase = true)
+ }
}
- }
VodClassicSplitLayout(
railTitle = stringResource(R.string.nav_series),
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 b1b5c4e2..51ce79e1 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
@@ -156,7 +156,8 @@ class SeriesViewModel @Inject constructor(
seriesRepository.getCategoryItemCounts(provider.id),
seriesRepository.getLibraryCount(provider.id),
preferencesRepository.getHiddenCategoryIds(provider.id, ContentType.SERIES),
- preferencesRepository.getCategorySortMode(provider.id, ContentType.SERIES)
+ preferencesRepository.getCategorySortMode(provider.id, ContentType.SERIES),
+ preferencesRepository.getPinnedCategoryIds(provider.id, ContentType.SERIES)
) { values ->
val allFavorites = values[0] as List<com.streamvault.domain.model.Favorite>
val customCategories = values[1] as List<Category>
@@ -165,6 +166,7 @@ class SeriesViewModel @Inject constructor(
val libraryCount = values[4] as Int
val hiddenCategoryIds = values[5] as Set<Long>
val sortMode = values[6] as CategorySortMode
+ val pinnedCategoryIds = values[7] as Set<Long>
val visibleProviderCategories = applyProviderCategoryDisplayPreferences(
categories = providerCategories,
hiddenCategoryIds = hiddenCategoryIds,
@@ -176,13 +178,18 @@ 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,
+ pinnedCategoryIds = pinnedCategoryIds,
categorySortMode = sortMode
)
}.combine(searchQueryForBrowse) { dependencies, query ->
@@ -191,9 +198,12 @@ 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,
+ pinnedCategoryIds = dependencies.pinnedCategoryIds,
categorySortMode = dependencies.categorySortMode,
query = query
)
@@ -268,6 +278,7 @@ class SeriesViewModel @Inject constructor(
selected in providerCategoryNames ||
selected in customCategoryNames
}
+ val currentPinnedIds = _uiState.value.pinnedCategoryIds
_uiState.update {
it.copy(
seriesByCategory = snapshot.grouped,
@@ -275,6 +286,7 @@ class SeriesViewModel @Inject constructor(
categoryCounts = snapshot.categoryCounts,
libraryCount = snapshot.libraryCount,
providerCategories = snapshot.providerCategories,
+ pinnedCategoryIds = currentPinnedIds.ifEmpty { snapshot.pinnedCategoryIds },
selectedCategory = resolvedSelected,
selectedCategoryItems = if (resolvedSelected == null) emptyList() else it.selectedCategoryItems,
selectedCategoryLoadedCount = if (resolvedSelected == null) 0 else it.selectedCategoryLoadedCount,
@@ -525,6 +537,17 @@ class SeriesViewModel @Inject constructor(
_uiState.update { it.copy(categories = categories) }
}
}
+
+ viewModelScope.launch {
+ providerRepository.getActiveProvider()
+ .filterNotNull()
+ .flatMapLatest { provider ->
+ preferencesRepository.getPinnedCategoryIds(provider.id, ContentType.SERIES)
+ }
+ .collect { pinnedIds ->
+ _uiState.update { it.copy(pinnedCategoryIds = pinnedIds) }
+ }
+ }
}
fun selectCategory(categoryName: String?) {
@@ -891,6 +914,26 @@ class SeriesViewModel @Inject constructor(
}
}
+ fun toggleCategoryPinned(category: Category) {
+ if (category.isVirtual) return
+ val providerId = activeProviderId ?: return
+ val shouldPin = category.id !in _uiState.value.pinnedCategoryIds
+ viewModelScope.launch {
+ preferencesRepository.setCategoryPinned(
+ providerId = providerId,
+ type = ContentType.SERIES,
+ categoryId = category.id,
+ pinned = shouldPin
+ )
+ dismissCategoryOptions()
+ _uiState.update {
+ it.copy(
+ userMessage = if (shouldPin) "Pinned ${category.name}" else "Unpinned ${category.name}"
+ )
+ }
+ }
+ }
+
fun requestRenameGroup(category: Category) {
if (!category.isVirtual || category.id == VodBrowseDefaults.FAVORITES_SENTINEL_ID) return
_uiState.update {
@@ -1328,9 +1371,12 @@ 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>,
+ val pinnedCategoryIds: Set<Long> = emptySet(),
val categorySortMode: CategorySortMode,
val query: String
)
@@ -1339,9 +1385,12 @@ 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>,
+ val pinnedCategoryIds: Set<Long> = emptySet(),
val categorySortMode: CategorySortMode
)
@@ -1350,7 +1399,8 @@ private data class SeriesCatalogSnapshot(
val categoryNames: List<String>,
val categoryCounts: Map<String, Int>,
val libraryCount: Int,
- val providerCategories: List<Category>
+ val providerCategories: List<Category>,
+ val pinnedCategoryIds: Set<Long> = emptySet()
)
private data class SeriesLibraryLensDependencies(
@@ -1432,6 +1482,7 @@ data class SeriesUiState(
val selectedSeriesForDialog: Series? = null,
val categories: List<Category> = emptyList(),
val providerCategories: List<Category> = emptyList(),
+ val pinnedCategoryIds: Set<Long> = emptySet(),
val dialogGroupMemberships: List<Long> = emptyList(),
val userMessage: String? = null,
val selectedCategoryForOptions: Category? = null,
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 5f96a0ba..8b9a4033 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -110,6 +110,7 @@
<string name="dashboard_favorite_movies">Favorite Movies</string>
<string name="dashboard_favorite_series">Favorite Series</string>
<string name="dashboard_recent_movies">Recently Added Movies</string>
+ <string name="dashboard_pinned_categories">Pinned Categories</string>
<string name="dashboard_recent_series">Recently Updated Series</string>
<string name="dashboard_top_rated_movies">Top Rated Movies</string>
<string name="dashboard_recommended_movies">Recommended Movies</string>
@@ -179,6 +180,8 @@
<string name="m3u_series_review_subtitle">Review the automatic suggestions or assign each entry to a series, season, and episode.</string>
<string name="m3u_episode_unresolved">Episode number unresolved — it will remain flagged for correction.</string>
<string name="category_pinned">Pinned %1$s.</string>
+ <string name="category_pin">Pin</string>
+ <string name="category_unpin">Unpin</string>
<string name="category_unpinned">Unpinned %1$s.</string>
<string name="add_group_manage_title">Manage: %1$s</string>
diff --git a/domain/src/main/java/com/streamvault/domain/model/AppHomeDashboardShelf.kt b/domain/src/main/java/com/streamvault/domain/model/AppHomeDashboardShelf.kt
index 28677eaf..e37034eb 100644
--- a/domain/src/main/java/com/streamvault/domain/model/AppHomeDashboardShelf.kt
+++ b/domain/src/main/java/com/streamvault/domain/model/AppHomeDashboardShelf.kt
@@ -8,6 +8,7 @@ enum class AppHomeDashboardShelf(
RECENT_CHANNELS("recent_channels", defaultEnabled = true),
LIVE_SHORTCUTS("live_shortcuts", defaultEnabled = true),
CONTINUE_WATCHING("continue_watching", defaultEnabled = true),
+ PINNED_CATEGORIES("pinned_categories", defaultEnabled = true),
RECENT_MOVIES("recent_movies", defaultEnabled = true),
RECENT_SERIES("recent_series", defaultEnabled = true),
FAVORITE_MOVIES("favorite_movies", defaultEnabled = false),
@@ -23,6 +24,7 @@ enum class AppHomeDashboardShelf(
RECENT_CHANNELS,
LIVE_SHORTCUTS,
CONTINUE_WATCHING,
+ PINNED_CATEGORIES,
RECENT_MOVIES,
RECENT_SERIES,
FAVORITE_MOVIES,