library-tv: detekt clean (16 tests)
- Commit
1b626fdeeef4fcc75872fc4b92a1b615b0920f0d- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-14 23:13 UTC (21 days ago)
- Parents
075fd12
Findings before: 17 detekt (1 UndocumentedPublicClass warning, 1 LongMethod, 11 MagicNumber, 4 MaxLineLength) plus 1 lintDebug error (RememberInComposition in TvComponentsTest). After: 0. - Documented TvAspect (16:9 / 2:3 / square artwork ratios). - Named the TvTheme colour-blend fractions and the dark-accent luminance threshold; moved the inline error colours to named Error/ErrorContainer/OnErrorContainer values (identical hex). - Named the seek-bar chapter-marker widths in TvTransport. - Extracted TvInfoCard's text column into TvInfoCardText so TvInfoCard is under the length cap; wrapped over-length lines in TvInfoCard/TvInput/TvLayout. - Lint: the focus test now remembers its FocusRequester instead of allocating one in composition. Verified: ./gradlew :library:tv:detekt :library:tv:testDebugUnitTest :library:tv:lint --max-workers=32 all green (16 unit tests, lintDebug included).
Diff
library/tv/src/main/java/com/vayunmathur/library/tv/TvCards.kt
diff --git a/library/tv/src/main/java/com/vayunmathur/library/tv/TvCards.kt b/library/tv/src/main/java/com/vayunmathur/library/tv/TvCards.ktindex b314402834..b1bdb87225 100644--- a/library/tv/src/main/java/com/vayunmathur/library/tv/TvCards.kt+++ b/library/tv/src/main/java/com/vayunmathur/library/tv/TvCards.kt@@ -26,6 +26,7 @@ import androidx.tv.material3.MaterialTheme import androidx.tv.material3.StandardCardContainer import androidx.tv.material3.Text +/** Width-over-height aspect ratios for TV artwork: 16:9 landscape, 2:3 poster, square. */ object TvAspect { const val Landscape = 16f / 9f const val Poster = 2f / 3f
library/tv/src/main/java/com/vayunmathur/library/tv/TvInfoCard.kt
diff --git a/library/tv/src/main/java/com/vayunmathur/library/tv/TvInfoCard.kt b/library/tv/src/main/java/com/vayunmathur/library/tv/TvInfoCard.ktindex e6dcda5a34..3f850c057f 100644--- a/library/tv/src/main/java/com/vayunmathur/library/tv/TvInfoCard.kt+++ b/library/tv/src/main/java/com/vayunmathur/library/tv/TvInfoCard.kt@@ -77,38 +77,15 @@ fun TvInfoCard( content = leading, ) }- Column(- Modifier.weight(1f).padding(start = if (leading != null) 14.dp else 0.dp),- verticalArrangement = Arrangement.spacedBy(2.dp),- ) {- Text(title, style = MaterialTheme.typography.titleMedium, maxLines = 1, overflow = TextOverflow.Ellipsis)- if (subtitle != null) {- Text(- subtitle,- style = MaterialTheme.typography.bodySmall,- color = LocalContentColor.current.copy(alpha = 0.72f),- maxLines = 1,- overflow = TextOverflow.Ellipsis,- )- }- if (!description.isNullOrBlank()) {- Text(- description,- style = MaterialTheme.typography.bodyMedium,- color = LocalContentColor.current.copy(alpha = 0.86f),- maxLines = descriptionLines,- overflow = TextOverflow.Ellipsis,- )- }- if (badges != null) {- Row(- Modifier.padding(top = 4.dp),- horizontalArrangement = Arrangement.spacedBy(6.dp),- verticalAlignment = Alignment.CenterVertically,- content = badges,- )- }- }+ TvInfoCardText(+ title = title,+ subtitle = subtitle,+ description = description,+ descriptionLines = descriptionLines,+ hasLeading = leading != null,+ badges = badges,+ modifier = Modifier.weight(1f),+ ) if (trailing != null) { Box(Modifier.padding(start = 10.dp)) { TvIcon(trailing) } }@@ -121,3 +98,53 @@ fun TvInfoCard( /** Fixed width when given, otherwise fill the grid cell / parent. */ internal fun Modifier.cellWidth(width: Dp): Modifier = if (width == Dp.Unspecified) fillMaxWidth() else width(width)++/** Title, subtitle, description and badge column of a [TvInfoCard]. */+@Composable+private fun TvInfoCardText(+ title: String,+ subtitle: String?,+ description: String?,+ descriptionLines: Int,+ hasLeading: Boolean,+ badges: (@Composable RowScope.() -> Unit)?,+ modifier: Modifier = Modifier,+) {+ Column(+ modifier.padding(start = if (hasLeading) 14.dp else 0.dp),+ verticalArrangement = Arrangement.spacedBy(2.dp),+ ) {+ Text(+ title,+ style = MaterialTheme.typography.titleMedium,+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ )+ if (subtitle != null) {+ Text(+ subtitle,+ style = MaterialTheme.typography.bodySmall,+ color = LocalContentColor.current.copy(alpha = 0.72f),+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ )+ }+ if (!description.isNullOrBlank()) {+ Text(+ description,+ style = MaterialTheme.typography.bodyMedium,+ color = LocalContentColor.current.copy(alpha = 0.86f),+ maxLines = descriptionLines,+ overflow = TextOverflow.Ellipsis,+ )+ }+ if (badges != null) {+ Row(+ Modifier.padding(top = 4.dp),+ horizontalArrangement = Arrangement.spacedBy(6.dp),+ verticalAlignment = Alignment.CenterVertically,+ content = badges,+ )+ }+ }+}
library/tv/src/main/java/com/vayunmathur/library/tv/TvInput.kt
diff --git a/library/tv/src/main/java/com/vayunmathur/library/tv/TvInput.kt b/library/tv/src/main/java/com/vayunmathur/library/tv/TvInput.ktindex 704b465500..d8a923d72f 100644--- a/library/tv/src/main/java/com/vayunmathur/library/tv/TvInput.kt+++ b/library/tv/src/main/java/com/vayunmathur/library/tv/TvInput.kt@@ -93,7 +93,11 @@ fun TvTextField( } Box(Modifier.weight(1f).padding(start = if (leading != null) 16.dp else 0.dp)) { if (value.isEmpty()) {- Text(placeholder, style = MaterialTheme.typography.titleMedium, color = LocalContentColor.current.copy(alpha = 0.6f))+ Text(+ placeholder,+ style = MaterialTheme.typography.titleMedium,+ color = LocalContentColor.current.copy(alpha = 0.6f),+ ) } BasicTextField( value = value,@@ -136,7 +140,11 @@ fun TvDialog( Column(Modifier.padding(32.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) { Text(title, style = MaterialTheme.typography.headlineSmall, color = MaterialTheme.colorScheme.onSurface) if (body != null) {- Text(body, style = MaterialTheme.typography.bodyLarge, color = MaterialTheme.colorScheme.onSurfaceVariant)+ Text(+ body,+ style = MaterialTheme.typography.bodyLarge,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ ) } content?.invoke() Row(
library/tv/src/main/java/com/vayunmathur/library/tv/TvLayout.kt
diff --git a/library/tv/src/main/java/com/vayunmathur/library/tv/TvLayout.kt b/library/tv/src/main/java/com/vayunmathur/library/tv/TvLayout.ktindex 0c1aa39c69..10b935a7e1 100644--- a/library/tv/src/main/java/com/vayunmathur/library/tv/TvLayout.kt+++ b/library/tv/src/main/java/com/vayunmathur/library/tv/TvLayout.kt@@ -48,7 +48,12 @@ fun TvScreenHeader( Row( modifier .fillMaxWidth()- .padding(start = tvContentStart(), end = TvDimens.SafeHorizontal, top = TvDimens.SafeVertical, bottom = 8.dp),+ .padding(+ start = tvContentStart(),+ end = TvDimens.SafeHorizontal,+ top = TvDimens.SafeVertical,+ bottom = 8.dp,+ ), verticalAlignment = Alignment.CenterVertically, ) { Column(Modifier.weight(1f)) {
library/tv/src/main/java/com/vayunmathur/library/tv/TvTheme.kt
diff --git a/library/tv/src/main/java/com/vayunmathur/library/tv/TvTheme.kt b/library/tv/src/main/java/com/vayunmathur/library/tv/TvTheme.ktindex 413d9c0df8..222e8ef581 100644--- a/library/tv/src/main/java/com/vayunmathur/library/tv/TvTheme.kt+++ b/library/tv/src/main/java/com/vayunmathur/library/tv/TvTheme.kt@@ -70,24 +70,36 @@ fun TvIcon(content: @Composable () -> Unit) { CompositionLocalProvider(M3LocalContentColor provides LocalContentColor.current, content = content) } +/** Luminance above which an accent gets dark on-accent content instead of white. */+private const val ON_ACCENT_LUMINANCE_THRESHOLD = 0.4f+private const val PRIMARY_CONTAINER_BLEND = 0.7f+private const val ON_PRIMARY_CONTAINER_BLEND = 0.6f+private const val SECONDARY_BLEND = 0.35f+private const val SECONDARY_CONTAINER_BLEND = 0.8f+private const val TERTIARY_BLEND = 0.5f+private const val BORDER_BLEND = 0.25f+ private val Background = Color(0xFF0B0C10) private val Surface = Color(0xFF16181D) private val SurfaceVariant = Color(0xFF23262D) private val OnSurface = Color(0xFFECEDF0) private val OnSurfaceVariant = Color(0xFFA6AAB3)+private val Error = Color(0xFFFF8A80)+private val ErrorContainer = Color(0xFF5C1F1B)+private val OnErrorContainer = Color(0xFFFFDAD6) private fun tvColorScheme(accent: Color): ColorScheme {- val onAccent = if (accent.luminance() > 0.4f) Background else Color.White+ val onAccent = if (accent.luminance() > ON_ACCENT_LUMINANCE_THRESHOLD) Background else Color.White return darkColorScheme( primary = accent, onPrimary = onAccent,- primaryContainer = lerp(accent, Background, 0.7f),- onPrimaryContainer = lerp(accent, Color.White, 0.6f),- secondary = lerp(accent, Color.White, 0.35f),+ primaryContainer = lerp(accent, Background, PRIMARY_CONTAINER_BLEND),+ onPrimaryContainer = lerp(accent, Color.White, ON_PRIMARY_CONTAINER_BLEND),+ secondary = lerp(accent, Color.White, SECONDARY_BLEND), onSecondary = Background,- secondaryContainer = lerp(accent, SurfaceVariant, 0.8f),+ secondaryContainer = lerp(accent, SurfaceVariant, SECONDARY_CONTAINER_BLEND), onSecondaryContainer = OnSurface,- tertiary = lerp(accent, Color.White, 0.5f),+ tertiary = lerp(accent, Color.White, TERTIARY_BLEND), background = Background, onBackground = OnSurface, surface = Surface,@@ -96,12 +108,12 @@ private fun tvColorScheme(accent: Color): ColorScheme { onSurfaceVariant = OnSurfaceVariant, inverseSurface = OnSurface, inverseOnSurface = Background,- border = lerp(accent, Color.White, 0.25f),+ border = lerp(accent, Color.White, BORDER_BLEND), borderVariant = SurfaceVariant,- error = Color(0xFFFF8A80),+ error = Error, onError = Background,- errorContainer = Color(0xFF5C1F1B),- onErrorContainer = Color(0xFFFFDAD6),+ errorContainer = ErrorContainer,+ onErrorContainer = OnErrorContainer, scrim = Color.Black, ) }
library/tv/src/main/java/com/vayunmathur/library/tv/TvTransport.kt
diff --git a/library/tv/src/main/java/com/vayunmathur/library/tv/TvTransport.kt b/library/tv/src/main/java/com/vayunmathur/library/tv/TvTransport.ktindex 553ef2504e..4a9a0c687a 100644--- a/library/tv/src/main/java/com/vayunmathur/library/tv/TvTransport.kt+++ b/library/tv/src/main/java/com/vayunmathur/library/tv/TvTransport.kt@@ -18,6 +18,12 @@ import androidx.compose.ui.unit.dp import androidx.tv.material3.MaterialTheme import androidx.tv.material3.Text +/** Half the seek-bar chapter marker width, in pixels. */+private const val MARKER_HALF_WIDTH_PX = 1.5f++/** Width of a seek-bar chapter marker, in pixels. */+private const val MARKER_WIDTH_PX = 3f+ /** * Player seek bar. Draw-only - the caller owns LEFT/RIGHT scrubbing - but it thickens and * shows a thumb while [active] (focused or scrubbing), the visual cue that the arrows seek.@@ -51,7 +57,7 @@ fun TvSeekBar( drawRoundRect(primary, Offset(0f, top), Size(x, h), radius) markers.forEach { m -> val mx = size.width * m.coerceIn(0f, 1f)- drawRect(gapColor, Offset(mx - 1.5f, top), Size(3f, h))+ drawRect(gapColor, Offset(mx - MARKER_HALF_WIDTH_PX, top), Size(MARKER_WIDTH_PX, h)) } if (active) drawCircle(thumbColor, radius = h * 1.1f, center = Offset(x, size.height / 2)) }
library/tv/src/test/java/com/vayunmathur/library/tv/TvComponentsTest.kt
diff --git a/library/tv/src/test/java/com/vayunmathur/library/tv/TvComponentsTest.kt b/library/tv/src/test/java/com/vayunmathur/library/tv/TvComponentsTest.ktindex 86afb297c8..8bb86bf046 100644--- a/library/tv/src/test/java/com/vayunmathur/library/tv/TvComponentsTest.kt+++ b/library/tv/src/test/java/com/vayunmathur/library/tv/TvComponentsTest.kt@@ -166,7 +166,8 @@ class TvComponentsTest { @Test fun `initial focus composable and dimens are sane`() { themed { Box {- TvInitialFocus(FocusRequester())+ val requester = androidx.compose.runtime.remember { FocusRequester() }+ TvInitialFocus(requester) Text("focused root") } }