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

Code before:

@Composable
fun PlayerScreen(
    volumeViewModel: VolumeViewModel,
    onVolumeClick: () -> Unit,
    modifier: Modifier = Modifier,
    playerScreenViewModel: PlayerViewModel = hiltViewModel(),
) {
    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) {
                val episode = playerUiState?.episodePlayerState?.currentEpisode
                if (episode != null && episode.title.isNotEmpty()) {
                    TextMediaDisplay(
                        title = episode.podcastName,
                        subtitle = episode.title
                    )
                } else {
                    TextMediaDisplay(
                        title = "Nothing to play",
                        subtitle = ""
                    )
                }
            } else {
                LoadingMediaDisplay()
            }
        },

        controlButtons = {

Review comment (suggestion):
PlayerUiState can be non nullable.

We might want to change the model to reflect no loaded item, rather then "" being no item.

Code after:
import com.google.android.horologist.media.ui.screens.player.PlayerScreen

@Composable
fun PlayerScreen(
    volumeViewModel: VolumeViewModel,
    onVolumeClick: () -> Unit,
    modifier: Modifier = Modifier,
    playerScreenViewModel: PlayerViewModel = hiltViewModel(),
) {
    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,