Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import org.koin.compose.koinInject
import org.siloserver.silo.network.ServerRegistry
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand Down Expand Up @@ -130,6 +134,32 @@ internal fun CollectionPosterCard(
}
}

/**
* The name of the profile that made a personal collection, when another
* profile of the account made it, for a card's "by Name" line (web
* `CollectionPosterCard`). The names come from the account's cached profile
* list; an unknown name, or any other card, answers null.
*/
@Composable
internal fun rememberCollectionOwnerName(activeProfileId: String? = null): (SectionCollectionCard) -> String? {
val serverRegistry: ServerRegistry = koinInject()
val activeAccount by serverRegistry.activeAccount.collectAsState()
val activeEntry by serverRegistry.activeEntry.collectAsState()
val viewerId = activeEntry?.profileId ?: activeProfileId
val profileNames = remember(activeAccount) {
activeAccount?.cachedProfiles.orEmpty()
.filter { it.name.isNotBlank() }
.associate { it.id to it.name }
}
return remember(viewerId, profileNames) {
{ card ->
card.creatorProfileId
?.takeIf { card.isUserCollection && viewerId != null && it != viewerId }
?.let { profileNames[it] }
}
}
}

/**
* A Home or library page row of collections (`collection_posters`): the
* [MediaRow] header over one [CollectionPosterCard] per card, sized and
Expand All @@ -147,11 +177,13 @@ internal fun CollectionPosterRow(
byline: @Composable (SectionCollectionCard) -> String?,
modifier: Modifier = Modifier,
showCounts: Boolean = true,
/** Off where the host draws its own heading, as a title page does. */
showHeader: Boolean = true,
) {
val uniqueCards = remember(cards) { cards.distinctBy { it.rowKey } }
val cardWidth = 120.dp * LocalCardPresentation.current.posterSize.posterScale
Column(modifier = modifier) {
MediaRowHeader(title = title)
if (showHeader) MediaRowHeader(title = title)
// Same gesture handling as MediaRow: a stricter slop for the row's
// scroll, the stock one for the cards' taps.
val baseViewConfiguration = LocalViewConfiguration.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,12 @@ fun AppNavigation(
onBoxSetMovieClick = { contentId, boxSetLibraryId ->
navController.navigate(Route.ItemDetail(contentId, libraryId = boxSetLibraryId.toIntOrNull()).route)
},
onCollectionClick = { card ->
sectionCollectionCardRoute(card)?.let { navController.navigate(it) }
},
onCollectionItemClick = { contentId ->
navController.navigate(Route.ItemDetail(contentId).route)
},
viewModel = detailViewModel,
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package org.siloserver.silo.android.ui.screens.detail

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import org.siloserver.silo.android.ui.components.CardStyle
import org.siloserver.silo.android.ui.components.CollectionPosterRow
import org.siloserver.silo.android.ui.components.ExploreAllCard
import org.siloserver.silo.android.ui.components.MediaCard
import org.siloserver.silo.android.ui.components.rememberCollectionOwnerName
import org.siloserver.silo.android.ui.components.sharedArtworkAspectRatio
import org.siloserver.silo.common.R as CommonR
import org.siloserver.silo.common.cards.LocalCardPresentation
import org.siloserver.silo.common.i18n.stringResourceWithNames
import org.siloserver.silo.common.ui.components.DeferImagePresentationWhileScrolling
import org.siloserver.silo.model.catalog.BrowseItem
import org.siloserver.silo.model.section.SectionCollectionCard
import org.siloserver.silo.overlays.OverlayDataExtractor
import org.siloserver.silo.viewmodel.DetailSeeds
import org.siloserver.silo.viewmodel.ItemCollectionsRow

/**
* The collections row on a movie or series page (web `ItemCollectionsRow`).
* When one collection holds the title, its other titles show under the
* collection's name, ended by an Explore all card that opens the collection.
* Otherwise an "Also in" row shows a poster card for every collection.
*/
@Composable
internal fun ItemCollectionsRail(
row: ItemCollectionsRow,
onCollectionClick: (SectionCollectionCard) -> Unit,
onItemClick: (BrowseItem) -> Unit,
modifier: Modifier = Modifier,
) {
val cardWidth = 120.dp * LocalCardPresentation.current.posterSize.posterScale
Column(
verticalArrangement = Arrangement.spacedBy(14.dp),
modifier = modifier,
) {
when (row) {
is ItemCollectionsRow.Preview -> {
SectionHeader(title = row.collection.title)
// Square covers when every title is an audiobook; one card height otherwise.
val posterAspectRatio = remember(row.items) { sharedArtworkAspectRatio(row.items.map { it.type }) }
ItemCollectionsLazyRow {
items(row.items, key = { it.contentId }, contentType = { "collection-title" }) { item ->
Comment thread
Quick104 marked this conversation as resolved.
Resolved
MediaCard(
width = cardWidth,
title = item.title,
posterUrl = item.posterUrl,
posterThumbhash = item.posterThumbhash,
detailBackdropUrl = item.backdropUrl,
detailBackdropThumbhash = item.backdropThumbhash,
year = item.year?.takeIf { it > 0 },
type = item.type,
userState = item.userState,
progress = null,
onClick = {
DetailSeeds.offer(item)
onItemClick(item)
},
artworkAspectRatio = posterAspectRatio,
overlay = OverlayDataExtractor.fromBrowseItem(item),
sharedContentId = item.contentId,
widthIsExact = true,
)
}
item(key = "explore-all", contentType = "explore-all") {
ExploreAllCard(
cardStyle = CardStyle.Poster,
onClick = { onCollectionClick(row.collection) },
width = cardWidth,
posterAspectRatio = posterAspectRatio,
)
}
}
}
is ItemCollectionsRow.AlsoIn -> {
val title = stringResource(CommonR.string.detail_alsoIn)
SectionHeader(title = title)
val ownerName = rememberCollectionOwnerName()
CollectionPosterRow(
title = title,
cards = row.cards,
onCardClick = onCollectionClick,
byline = { card ->
ownerName(card)?.let { stringResourceWithNames(CommonR.string.collections_posterCard_byOwner, it) }
},
showHeader = false,
)
}
}
}
}

@Composable
private fun ItemCollectionsLazyRow(content: androidx.compose.foundation.lazy.LazyListScope.() -> Unit) {
val rowState = rememberLazyListState()
DeferImagePresentationWhileScrolling(rowState) {
LazyRow(
state = rowState,
contentPadding = PaddingValues(horizontal = SafePadding),
horizontalArrangement = Arrangement.spacedBy(12.dp),
modifier = Modifier.fillMaxWidth(),
content = content,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ fun ItemDetailScreen(
onBoxSetClick: (boxSetId: String, libraryId: String) -> Unit = { _, _ -> },
/** Opens a movie from a box set row, scoped to the box set's library. */
onBoxSetMovieClick: (contentId: String, libraryId: String) -> Unit,
/** Opens a collection from the collections row. */
onCollectionClick: (org.siloserver.silo.model.section.SectionCollectionCard) -> Unit = {},
/**
* Opens a title from a collection's preview, with no library: a
* collection's titles can live in other libraries, as on its own page.
*/
onCollectionItemClick: (contentId: String) -> Unit = {},
viewModel: ItemDetailViewModel,
modifier: Modifier = Modifier,
) {
Expand Down Expand Up @@ -772,6 +779,9 @@ fun ItemDetailScreen(
translation = translationSlot,
detail = detail,
similarItems = state.similarItems,
collectionsRow = state.collectionsRow,
onCollectionClick = onCollectionClick,
onCollectionItemClick = { item -> onCollectionItemClick(item.contentId) },
seasons = state.seasons,
selectedSeasonNumber = state.selectedSeasonNumber,
episodes = state.episodes,
Expand Down Expand Up @@ -1031,6 +1041,9 @@ fun ItemDetailScreen(
boxSet = state.boxSet,
onOpenBoxSet = { boxSet -> onBoxSetClick(boxSet.id, boxSet.libraryId) },
onBoxSetMovieClick = onBoxSetMovieClick,
collectionsRow = state.collectionsRow,
onCollectionClick = onCollectionClick,
onCollectionItemClick = { item -> onCollectionItemClick(item.contentId) },
portraitArtwork = portraitArtwork,
isFavorite = state.isFavorite,
isInWatchlist = state.isInWatchlist,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ data class ItemDetailUiState(
val similarItems: List<org.siloserver.silo.model.catalog.BrowseItem> = emptyList(),
/** The box set this movie belongs to, for the box set row after the extras; null for none. */
val boxSet: org.siloserver.silo.model.catalog.CatalogBoxSetDetail? = null,
/** The collections row of a movie or series page; null for none. */
val collectionsRow: org.siloserver.silo.viewmodel.ItemCollectionsRow? = null,
val seasons: List<Season> = emptyList(),
val selectedSeasonNumber: Int = 1,
val episodes: List<EpisodeListItem> = emptyList(),
Expand Down Expand Up @@ -198,6 +200,8 @@ class ItemDetailViewModel(
private var similarJob: kotlinx.coroutines.Job? = null
private var boxSetGeneration = 0L
private var boxSetJob: Job? = null
private var collectionsGeneration = 0L
private var collectionsJob: Job? = null
private var detailLoadJob: Job? = null
private var quietDetailJob: Job? = null
/** Whether [quietDetailJob] clears the page on a refusal (an access-change refresh). */
Expand Down Expand Up @@ -495,10 +499,12 @@ class ItemDetailViewModel(
// gave under an older access policy never lands after it.
detailLoadJob?.cancel()
quietDetailJob?.cancel()
// A new load shows no box set row until its own read answers.
// A new load shows no box set or collections row until its own read answers.
boxSetGeneration++
boxSetJob?.cancel()
_uiState.update { it.copy(similarItems = emptyList(), boxSet = null) }
collectionsGeneration++
collectionsJob?.cancel()
_uiState.update { it.copy(similarItems = emptyList(), boxSet = null, collectionsRow = null) }
detailLoadJob = viewModelScope.launch {
val similarOwner = recommendationRepository.captureSimilarAuthority()
trackChoiceOwner = catalogRepository.captureWatchAuthority()
Expand Down Expand Up @@ -541,6 +547,7 @@ class ItemDetailViewModel(
similarJob = viewModelScope.launch { loadSimilar(detail, similarOwner, similarRun) }
}
loadBoxSet(detail)
loadCollections(detail)
if (detail.type == "series" && !seasonsStarted) {
loadSeasons(detail.contentId)
}
Expand Down Expand Up @@ -620,6 +627,20 @@ class ItemDetailViewModel(
}
}

/**
* Reads the collections row for a movie or series. A failed read keeps
* the row on screen, as [loadBoxSet] does.
*/
private fun loadCollections(detail: ItemDetail) {
val run = ++collectionsGeneration
collectionsJob?.cancel()
collectionsJob = viewModelScope.launch {
val result = org.siloserver.silo.viewmodel.loadItemCollectionsRow(catalogRepository, detail, libraryId)
if (run != collectionsGeneration || _uiState.value.detail?.contentId != detail.contentId) return@launch
if (result is ApiResult.Success) _uiState.update { it.copy(collectionsRow = result.data) }
Comment thread
Rhainland marked this conversation as resolved.
Resolved
}
}

/**
* Quiet refresh for returning to an already-loaded detail screen (e.g.
* backing out of the player): re-reads userData so the Play button's
Expand Down Expand Up @@ -714,6 +735,8 @@ class ItemDetailViewModel(
}
// Watched badges in the box set row follow the player too.
loadBoxSet(current)
// A collection edited elsewhere (or one the title joined) shows on return.
loadCollections(current)
if (current.type == "series") {
refreshSeasonsQuietly(current.contentId, fresh = afterWatchedChange)
loadEpisodes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ fun MovieDetailContent(
boxSet: org.siloserver.silo.model.catalog.CatalogBoxSetDetail? = null,
onOpenBoxSet: (org.siloserver.silo.model.catalog.CatalogBoxSet) -> Unit = {},
onBoxSetMovieClick: (contentId: String, libraryId: String) -> Unit = { _, _ -> },
/** The collections row; null shows none. */
collectionsRow: org.siloserver.silo.viewmodel.ItemCollectionsRow? = null,
onCollectionClick: (org.siloserver.silo.model.section.SectionCollectionCard) -> Unit = {},
onCollectionItemClick: (org.siloserver.silo.model.catalog.BrowseItem) -> Unit = {},
isFavorite: Boolean,
isInWatchlist: Boolean,
selectedVersionIndex: Int,
Expand Down Expand Up @@ -363,6 +367,17 @@ fun MovieDetailContent(
}
}

// The collections holding the movie, below the box set row (web).
if (collectionsRow != null) {
item(contentType = "detail-collections") {
ItemCollectionsRail(
row = collectionsRow,
onCollectionClick = onCollectionClick,
onItemClick = onCollectionItemClick,
)
}
}

// Hide the similar rail on episode pages — viewers usually want
// the next episode, not a tangentially related title. Skip it when
// empty so it leaves no extra gap above Details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ import org.siloserver.silo.common.ui.components.DeferImagePresentationWhileScrol
fun SeriesDetailContent(
detail: ItemDetail,
similarItems: List<org.siloserver.silo.model.catalog.BrowseItem> = emptyList(),
/** The collections row; null shows none. */
collectionsRow: org.siloserver.silo.viewmodel.ItemCollectionsRow? = null,
onCollectionClick: (org.siloserver.silo.model.section.SectionCollectionCard) -> Unit = {},
onCollectionItemClick: (org.siloserver.silo.model.catalog.BrowseItem) -> Unit = {},
seasons: List<Season>,
selectedSeasonNumber: Int,
episodes: List<EpisodeListItem>,
Expand Down Expand Up @@ -537,6 +541,17 @@ fun SeriesDetailContent(
}
}

// The collections holding the series, below Cast & Crew (web).
if (collectionsRow != null) {
item(contentType = "detail-collections") {
ItemCollectionsRail(
row = collectionsRow,
onCollectionClick = onCollectionClick,
onItemClick = onCollectionItemClick,
)
}
}

val trailerEntries = trailerRailEntries(detail)
if (trailerEntries.isNotEmpty()) {
item(contentType = "detail-trailers") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ import org.siloserver.silo.android.ui.components.areAllAudiobooks
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.PlayCircle
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import org.koin.compose.koinInject
import org.siloserver.silo.android.ui.components.CollectionPosterRow
import org.siloserver.silo.android.ui.components.rememberCollectionOwnerName
import org.siloserver.silo.common.R as CommonR
import org.siloserver.silo.common.i18n.stringResourceWithNames
import org.siloserver.silo.model.section.SectionCollectionCard
import org.siloserver.silo.network.ServerRegistry
import androidx.compose.ui.Modifier
import org.siloserver.silo.android.ui.components.CardStyle
import org.siloserver.silo.android.ui.components.MediaCardActions
Expand Down Expand Up @@ -124,24 +121,13 @@ private fun HomeCollectionRow(
showCounts: Boolean,
modifier: Modifier,
) {
val serverRegistry: ServerRegistry = koinInject()
val activeAccount by serverRegistry.activeAccount.collectAsState()
val activeEntry by serverRegistry.activeEntry.collectAsState()
val viewerId = activeEntry?.profileId ?: activeProfileId
val profileNames = remember(activeAccount) {
activeAccount?.cachedProfiles.orEmpty()
.filter { it.name.isNotBlank() }
.associate { it.id to it.name }
}
val ownerName = rememberCollectionOwnerName(activeProfileId)
CollectionPosterRow(
title = sectionTitle(section),
cards = section.collections,
onCardClick = onCollectionClick,
byline = { card ->
val ownerName = card.creatorProfileId
?.takeIf { card.isUserCollection && viewerId != null && it != viewerId }
?.let { profileNames[it] }
ownerName?.let { stringResourceWithNames(CommonR.string.collections_posterCard_byOwner, it) }
ownerName(card)?.let { stringResourceWithNames(CommonR.string.collections_posterCard_byOwner, it) }
},
modifier = modifier,
showCounts = showCounts,
Expand Down
Loading
Loading