diff --git a/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/components/BackdropCard.kt b/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/components/BackdropCard.kt index 33fbc342fd..1c68d756db 100644 --- a/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/components/BackdropCard.kt +++ b/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/components/BackdropCard.kt @@ -206,10 +206,8 @@ fun BackdropCard( overflow = TextOverflow.Ellipsis, modifier = Modifier.fillMaxWidth(), ) - val episodeTag = formatEpisodeTag(seasonNumber, episodeNumber, episodeLabels, airDate) - val subtitle = if (episodeTag != null) "$episodeTag \u2022 $title" else title Text( - text = subtitle, + text = episodeCaption(seasonNumber, episodeNumber, title, episodeLabels, airDate).orEmpty(), style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1, @@ -249,6 +247,29 @@ fun BackdropCard( } } +/** + * "S01E02 \u2022 Title", an episode card's line under its series title; + * whichever part exists when the other is missing. + */ +@Composable +internal fun episodeCaption( + season: Int?, + episode: Int?, + title: String?, + episodeLabels: String? = null, + airDate: String? = null, +): String? { + val episodeTag = formatEpisodeTag(season, episode, episodeLabels, airDate) + return when { + episodeTag == null -> title + title == null -> episodeTag + // Isolate (FSI…PDI) the server title so a right-to-left title keeps its + // punctuation at its own end after the left-to-right tag. A lone title + // stays bare so its own script still sets the paragraph direction. + else -> "$episodeTag \u2022 \u2068$title\u2069" + } +} + /** * "S01E02" (or the air date for a date-labeled series), "S01" or "E02" (each * number at least two digits); null without either. diff --git a/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/components/MediaCard.kt b/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/components/MediaCard.kt index fba20a7047..88013eee11 100644 --- a/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/components/MediaCard.kt +++ b/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/components/MediaCard.kt @@ -110,6 +110,8 @@ fun MediaCard( year: Int? = null, /** Replaces the year caption when set (e.g. the active sort's date). */ subtitle: String? = null, + /** Line cap for [subtitle]; a fixed-height card ([reserveTextLines]) always takes one. */ + subtitleMaxLines: Int = Int.MAX_VALUE, type: String? = null, userState: MediaItemUserState? = null, progress: Float? = null, @@ -280,7 +282,7 @@ fun MediaCard( MediaCardTitleAndCaption(title, caption, captionMaxLines = 1) } } else { - MediaCardTitleAndCaption(title, caption) + MediaCardTitleAndCaption(title, caption, captionMaxLines = if (subtitle != null) subtitleMaxLines else Int.MAX_VALUE) } MediaCardContextMenu( diff --git a/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/components/MediaRow.kt b/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/components/MediaRow.kt index 1de1f779ab..aead9d5428 100644 --- a/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/components/MediaRow.kt +++ b/androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/components/MediaRow.kt @@ -61,6 +61,7 @@ import org.siloserver.silo.common.diagnostics.DiagnosticsKeyCollection import org.siloserver.silo.common.diagnostics.DiagnosticsListSnapshot import org.siloserver.silo.common.cards.LocalEpisodeSpoilerPrefs import org.siloserver.silo.model.section.SectionItem +import org.siloserver.silo.model.section.episodeCardLabel import org.siloserver.silo.model.settings.EpisodeSpoilerPrefs import org.siloserver.silo.model.settings.EpisodeSpoilers import org.siloserver.silo.overlays.OverlayData @@ -308,8 +309,12 @@ fun MediaRow( ) } CardStyle.Poster -> { + val episodeLabel = item.episodeCardLabel() MediaCard( - title = item.title, + title = episodeLabel?.seriesTitle ?: item.title, + subtitle = episodeLabel?.let { episodeCaption(item.seasonNumber, item.episodeNumber, it.episodeTitle, item.episodeLabels, item.airDate) }, + // An episode caption stays on one line, so a long title cannot make its card taller than the row. + subtitleMaxLines = 1, hideArtwork = item.type.equals("episode", ignoreCase = true) && spoilerPrefs.hidesImage(EpisodeSpoilers.isUnwatched(item), item.posterIsEpisodeStill), posterUrl = item.posterUrl, posterThumbhash = item.posterThumbhash, diff --git a/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/components/TvMediaCard.kt b/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/components/TvMediaCard.kt index c756ee4d6c..542a5842b0 100644 --- a/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/components/TvMediaCard.kt +++ b/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/components/TvMediaCard.kt @@ -109,6 +109,8 @@ fun TvMediaCard( cornerLabel: String? = null, /** Replaces the year line under the title. */ caption: String? = null, + /** Line cap for [caption]. */ + captionMaxLines: Int = Int.MAX_VALUE, /** Draws a box set's sleeves above the artwork; see [boxSetSleeves]. */ sleeves: BoxSetSleeveColors? = null, /** Outlines the artwork at rest, such as the movie being viewed in its box set row. */ @@ -196,7 +198,9 @@ fun TvMediaCard( hidden = hideArtwork, url = posterUrl, thumbhash = posterThumbhash, - contentDescription = title, + // The caption sits outside the focusable card, so name it here + // too: two episodes of one series share a title. + contentDescription = caption?.let { "$title, $it" } ?: title, contentScale = ContentScale.Crop, modifier = Modifier.fillMaxSize(), defaultArtwork = DefaultArtworkKind.forItemType(mediaType), @@ -296,6 +300,8 @@ fun TvMediaCard( lineHeight = 18.sp, ), color = Color.White.copy(alpha = 0.70f), + maxLines = if (caption != null) captionMaxLines else Int.MAX_VALUE, + overflow = TextOverflow.Ellipsis, textAlign = TextAlign.Start, modifier = Modifier.fillMaxWidth(), ) diff --git a/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/components/TvMediaRow.kt b/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/components/TvMediaRow.kt index 6be07a82eb..372a760ba5 100644 --- a/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/components/TvMediaRow.kt +++ b/androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/components/TvMediaRow.kt @@ -33,6 +33,8 @@ import androidx.compose.ui.ExperimentalComposeUiApi import org.siloserver.silo.common.R as CommonR import org.siloserver.silo.common.cards.LocalEpisodeSpoilerPrefs import org.siloserver.silo.model.section.SectionItem +import org.siloserver.silo.model.section.EpisodeCardLabel +import org.siloserver.silo.model.section.episodeCardLabel import org.siloserver.silo.model.settings.EpisodeSpoilers import org.siloserver.silo.overlays.OverlayData import org.siloserver.silo.overlays.OverlayDataExtractor @@ -71,6 +73,8 @@ private data class TvMediaRowItemModel( val hidesArtwork: Boolean, /** The same for the poster layout, which shows the item's own poster. */ val hidesPoster: Boolean, + /** The series and episode title a poster card shows for an episode. */ + val episodeLabel: EpisodeCardLabel?, ) /** @@ -210,6 +214,7 @@ fun TvMediaRow( // Protect the selected still while preserving series fallback art. hidesArtwork = spoilerPrefs.hidesImage(unwatchedEpisode, EpisodeSpoilers.selectedImageIsStill(item)), hidesPoster = spoilerPrefs.hidesImage(unwatchedEpisode, item.posterIsEpisodeStill), + episodeLabel = item.episodeCardLabel(), ) } } @@ -480,7 +485,12 @@ fun TvMediaRow( ) TvRowStyle.Poster -> TvMediaCard( hideArtwork = rowItem.hidesPoster, - title = item.title, + title = rowItem.episodeLabel?.seriesTitle ?: item.title, + caption = rowItem.episodeLabel?.let { + tvEpisodeTitleLine(item.seasonNumber, item.episodeNumber, it.episodeTitle.orEmpty(), item.episodeLabels, item.airDate) + }, + // An episode caption stays on one line, so a long title cannot make its card taller than the row. + captionMaxLines = 1, posterUrl = item.posterUrl, posterThumbhash = item.posterThumbhash, year = item.year.takeIf { it > 0 }, diff --git a/shared/src/commonMain/kotlin/org/siloserver/silo/model/section/SectionModels.kt b/shared/src/commonMain/kotlin/org/siloserver/silo/model/section/SectionModels.kt index 47aad51026..f0c57f88c1 100644 --- a/shared/src/commonMain/kotlin/org/siloserver/silo/model/section/SectionModels.kt +++ b/shared/src/commonMain/kotlin/org/siloserver/silo/model/section/SectionModels.kt @@ -231,3 +231,19 @@ data class LibraryUngroupedSection( @SerialName("sort_order") val sortOrder: Int = Int.MAX_VALUE, val collections: List = emptyList(), ) + +/** + * What an episode's poster card prints: its series as the card title, then + * the episode code and [episodeTitle] as the caption ("S01E02 • Pilot"), as + * the web and Apple cards do. [episodeTitle] is null when it is blank or only + * repeats the series name. + */ +data class EpisodeCardLabel(val seriesTitle: String, val episodeTitle: String?) + +/** This item's [EpisodeCardLabel]; null unless it is an episode with a series title. */ +fun SectionItem.episodeCardLabel(): EpisodeCardLabel? { + if (!type.equals("episode", ignoreCase = true)) return null + val series = seriesTitle?.trim()?.takeIf { it.isNotEmpty() } ?: return null + val episode = title.trim().takeIf { it.isNotEmpty() && !it.equals(series, ignoreCase = true) } + return EpisodeCardLabel(series, episode) +} diff --git a/shared/src/commonTest/kotlin/org/siloserver/silo/model/section/EpisodeCardLabelTest.kt b/shared/src/commonTest/kotlin/org/siloserver/silo/model/section/EpisodeCardLabelTest.kt new file mode 100644 index 0000000000..12a7865a6c --- /dev/null +++ b/shared/src/commonTest/kotlin/org/siloserver/silo/model/section/EpisodeCardLabelTest.kt @@ -0,0 +1,28 @@ +package org.siloserver.silo.model.section + +import kotlin.test.Test +import kotlin.test.assertEquals + +class EpisodeCardLabelTest { + + private fun item(type: String, title: String, seriesTitle: String?) = + SectionItem(contentId = "c", type = type, title = title, seriesTitle = seriesTitle) + + @Test + fun episodeCardsLeadWithTheirSeriesAndKeepADistinctEpisodeTitle() { + val cases = listOf( + item("episode", "Pilot", "Running Show") to EpisodeCardLabel("Running Show", "Pilot"), + // A title that only repeats the series name (some scanners fill unknown titles that way) is dropped, + // so the caption keeps just the episode code, as on Apple. + item("episode", "running show ", "Running Show") to EpisodeCardLabel("Running Show", null), + item("episode", " ", "Running Show") to EpisodeCardLabel("Running Show", null), + item("episode", "Pilot", null) to null, + item("episode", "Pilot", " ") to null, + item("movie", "Heat", "Some Collection") to null, + item("series", "Running Show", "Running Show") to null, + ) + for ((item, expected) in cases) { + assertEquals(expected, item.episodeCardLabel(), "${item.type} '${item.title}' / ${item.seriesTitle}") + } + } +}