Skip to content

Migrate TV snippets#873

Open
kkuan2011 wants to merge 1 commit intomainfrom
katherinekuan/tv-snippets
Open

Migrate TV snippets#873
kkuan2011 wants to merge 1 commit intomainfrom
katherinekuan/tv-snippets

Conversation

@kkuan2011
Copy link
Copy Markdown
Contributor

This PR adds code snippets for Android TV documentation.

Code snippets are for:

List of modifications:

  • Create page: Filled in name="MyTheme" to make it valid XML.
  • Hardware page: Added null check for location and used safe call for geocoder.
  • Details page: Fixed typos, updated model field to backgroundImageUrl, updated style to headlineMedium, and wrapped string in stringResource.
  • Browse page: Corrected function to fun.
  • Browse page: Replaced TvLazyColumn with standard Compose LazyColumn.
  • Now-playing page: Added FLAG_IMMUTABLE for Android 12 compatibility.
  • Games page: Added safe call ?. to it.keyboardType to prevent compilation error.
  • button.xml drawable: Omitted from the snippet region due to build failures when preceded by region tags or copyright header.

Snippets not migrated:

  • Java snippets were skipped across multiple pages (Multitasking, Ambient-mode, Media-session, Now-playing, Audio-capabilities, Memory, Games).
  • Manifest snippets were skipped (Create, Hardware, Controllers, Multitasking, Games).
  • View-based snippets were skipped (Onscreen-keyboard, Navigation, Multitasking).
  • Specific snippets skipped: Pause playback in onStop() in Hardware (to be fixed separately) and View Binding snippet on Multitasking.

@kkuan2011 kkuan2011 requested a review from yrezgui as a code owner April 17, 2026 21:18
@snippet-bot
Copy link
Copy Markdown

snippet-bot bot commented Apr 17, 2026

Here is the summary of changes.

You are about to add 29 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive collection of Android TV code snippets covering ambient mode, audio capabilities, display settings, hardware detection, media sessions, and Compose-based UI components. The review feedback identifies a potential runtime exception in the audio format selection logic and highlights several instances of inconsistent indentation and spacing in the Compose snippets that should be standardized to improve code quality and readability.

Comment on lines +70 to +72
val bestAudioProfile = preferredFormats.firstNotNullOf { format ->
audioProfiles.firstOrNull { it.format == format }
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of firstNotNullOf will throw a NoSuchElementException if no matching profile is found in audioProfiles. It is safer to use firstNotNullOfOrNull and handle the null case or provide a default value, especially since audioProfiles could be empty depending on the device's capabilities.

Suggested change
val bestAudioProfile = preferredFormats.firstNotNullOf { format ->
audioProfiles.firstOrNull { it.format == format }
}
val bestAudioProfile = preferredFormats.firstNotNullOfOrNull { format ->
audioProfiles.firstOrNull { it.format == format }
} ?: return AudioFormat.Builder().build()

Comment on lines +80 to +100
fun Section(
section: Section,
modifier: Modifier = Modifier,
onItemSelected: (Movie) -> Unit = {},
) {
Text(
text = section.title,
style = MaterialTheme.typography.headlineSmall,
)
LazyRow(
modifier = modifier,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
items(section.movieList){ movie ->
MovieCard(
movie = movie,
onClick = { onItemSelected(movie) }
)
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The indentation in this block is inconsistent (using 2, 3, or 5 spaces). Adhering to the standard 4-space indentation for Kotlin and adding a space before the opening brace of lambdas will improve the readability of these documentation snippets.

@Composable
fun Section(
    section: Section,
    modifier: Modifier = Modifier,
    onItemSelected: (Movie) -> Unit = {},
) {
    Text(
        text = section.title,
        style = MaterialTheme.typography.headlineSmall,
    )
    LazyRow(
        modifier = modifier,
        horizontalArrangement = Arrangement.spacedBy(8.dp)
    ) {
        items(section.movieList) { movie ->
            MovieCard(
                movie = movie,
                onClick = { onItemSelected(movie) }
            )
        }
    }
}

modifier: Modifier = Modifier,
onClick: () -> Unit = {}
) {
Card(modifier = modifier, onClick = onClick){
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Missing space before the opening brace of the lambda and inconsistent indentation.

Suggested change
Card(modifier = modifier, onClick = onClick){
Card(modifier = modifier, onClick = onClick) {

Comment on lines +179 to +196
Box(modifier = modifier.fillMaxSize()){
AsyncImage(
modifier = Modifier.fillMaxSize(),
model = movie.backgroundImageUrl,
contentDescription = null,
contentScale = ContentScale.Crop,
)
Column(modifier = Modifier.padding(32.dp)){
Text(
text = movie.title,
style = MaterialTheme.typography.headlineMedium
)
Text(text = movie.description)
Button(onClick = { onStartPlayback(movie) }){
Text(text = stringResource(id = R.string.startPlayback))
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The indentation and spacing in this function are inconsistent. Using standard 4-space indentation and adding spaces before lambda braces will make the snippet clearer for documentation purposes.

Suggested change
Box(modifier = modifier.fillMaxSize()){
AsyncImage(
modifier = Modifier.fillMaxSize(),
model = movie.backgroundImageUrl,
contentDescription = null,
contentScale = ContentScale.Crop,
)
Column(modifier = Modifier.padding(32.dp)){
Text(
text = movie.title,
style = MaterialTheme.typography.headlineMedium
)
Text(text = movie.description)
Button(onClick = { onStartPlayback(movie) }){
Text(text = stringResource(id = R.string.startPlayback))
}
}
}
Box(modifier = modifier.fillMaxSize()) {
AsyncImage(
modifier = Modifier.fillMaxSize(),
model = movie.backgroundImageUrl,
contentDescription = null,
contentScale = ContentScale.Crop,
)
Column(modifier = Modifier.padding(32.dp)) {
Text(
text = movie.title,
style = MaterialTheme.typography.headlineMedium
)
Text(text = movie.description)
Button(onClick = { onStartPlayback(movie) }) {
Text(text = stringResource(id = R.string.startPlayback))
}
}
}

@kkuan2011 kkuan2011 force-pushed the katherinekuan/tv-snippets branch from bd3cfeb to 5d1f6d7 Compare April 17, 2026 22:24
@kkuan2011 kkuan2011 requested a review from chikoski April 17, 2026 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant