Conversation
There was a problem hiding this comment.
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.
| val bestAudioProfile = preferredFormats.firstNotNullOf { format -> | ||
| audioProfiles.firstOrNull { it.format == format } | ||
| } |
There was a problem hiding this comment.
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.
| val bestAudioProfile = preferredFormats.firstNotNullOf { format -> | |
| audioProfiles.firstOrNull { it.format == format } | |
| } | |
| val bestAudioProfile = preferredFormats.firstNotNullOfOrNull { format -> | |
| audioProfiles.firstOrNull { it.format == format } | |
| } ?: return AudioFormat.Builder().build() |
| 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) } | ||
| ) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
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){ |
| 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)) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| 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)) | |
| } | |
| } | |
| } |
bd3cfeb to
5d1f6d7
Compare
This PR adds code snippets for Android TV documentation.
Code snippets are for:
List of modifications:
Snippets not migrated: