Repository: android/compose-samples
File: Jetcaster/wear/src/main/java/com/example/jetcaster/ui/player/PlayerScreen.kt (Kotlin)

Code before:
    val volumeUiState by volumeViewModel.volumeUiState.collectAsStateWithLifecycle()
    val playerUiState by playerScreenViewModel.uiState.collectAsStateWithLifecycle()

    PlayerScreen(
        modifier = modifier,
        playerUiState = playerUiState,
        playerScreenViewModel = playerScreenViewModel,
        volumeUiState = volumeUiState,
        onVolumeClick = onVolumeClick,
        onUpdateVolume = { newVolume -> volumeViewModel.setVolume(newVolume) },
    )
}

@Composable
private fun PlayerScreen(
    playerUiState: PlayerUiState?,
    playerScreenViewModel: PlayerViewModel,
    volumeUiState: VolumeUiState,
    onVolumeClick: () -> Unit,
    onUpdateVolume: (Int) -> Unit,
    modifier: Modifier = Modifier,
) {
    PlayerScreen(
        mediaDisplay = {
            if (playerUiState != null) {
                if (playerUiState.episodePlayerState.currentEpisode != null) {
                    val episode = playerUiState.episodePlayerState.currentEpisode
                    if (episode != null) {
                        if (episode.title != "") {
                            TextMediaDisplay(
                                title = episode.podcastName,
                                subtitle = episode.title
                            )
                        }
                    }
                } else {
                    TextMediaDisplay(
                        title = "Nothing to play",
                        subtitle = ""
                    )
                }
            } else {
                LoadingMediaDisplay()
            }
        },

        controlButtons = {
            if (playerUiState != null) {
                PodcastControlButtons(
                    onPlayButtonClick = playerScreenViewModel::onPlay,
                    onPauseButtonClick = playerScreenViewModel::onPause,

Review comment (refactor):
2 null checks are being done here. You can simplify this to:

```
val episode = playerUiState.episodePlayerState.currentEpisode
if (episode != null) {
     TextMediaDisplay(
         title = episode.podcastName,
         subtitle = episode.title
     )
} else {
    TextMediaDisplay(
          title = it.podcastName,
          subtitle = it.title
          title = "Nothing to play",
          subtitle = ""
      )
}
```

Code after:
) {
    val volumeUiState by volumeViewModel.volumeUiState.collectAsStateWithLifecycle()
    val playerUiState by playerScreenViewModel.uiState.collectAsStateWithLifecycle()

    PlayerScreen(
        modifier = modifier,
        playerUiState = playerUiState,
        playerScreenViewModel = playerScreenViewModel,
        volumeUiState = volumeUiState,
        onVolumeClick = onVolumeClick,
        onUpdateVolume = { newVolume -> volumeViewModel.setVolume(newVolume) },
    )
}

@Composable
private fun PlayerScreen(
    playerUiState: PlayerUiState,
    playerScreenViewModel: PlayerViewModel,
    volumeUiState: VolumeUiState,
    onVolumeClick: () -> Unit,
    onUpdateVolume: (Int) -> Unit,
    modifier: Modifier = Modifier,
) {
    val episode = playerUiState.episodePlayerState.currentEpisode
    PlayerScreen(
        mediaDisplay = {
            if (episode != null && episode.title.isNotEmpty()) {
                TextMediaDisplay(
                    title = episode.podcastName,
                    subtitle = episode.title
                )
            } else {
                TextMediaDisplay(
                    title = stringResource(R.string.nothing_playing),
                    subtitle = ""
                )
            }
        },

        controlButtons = {
            if (episode != null && episode.title.isNotEmpty()) {
                PodcastControlButtons(
                    onPlayButtonClick = playerScreenViewModel::onPlay,
                    onPauseButtonClick = playerScreenViewModel::onPause,
                    playPauseButtonEnabled = true,
                    playing = playerUiState.episodePlayerState.isPlaying,
                    onSeekBackButtonClick = playerScreenViewModel::onRewindBy,
                    seekBackButtonEnabled = true,
                    onSeekForwardButtonClick = playerScreenViewModel::onAdvanceBy,
                    seekForwardButtonEnabled = true,
                    seekBackButtonIncrement = SeekButtonIncrement.Ten,