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 @@ -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,
Expand Down Expand Up @@ -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)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?,
)

/**
Expand Down Expand Up @@ -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(),
)
}
}
Expand Down Expand Up @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,19 @@ data class LibraryUngroupedSection(
@SerialName("sort_order") val sortOrder: Int = Int.MAX_VALUE,
val collections: List<LibraryCollection> = 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)
}
Original file line number Diff line number Diff line change
@@ -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}")
}
}
}
Loading