fun SpeakerScreen()

in WearSpeakerSample/wear/src/main/java/com/example/android/wearable/speaker/SpeakerScreen.kt [40:104]


fun SpeakerScreen(
    playbackState: PlaybackState,
    isPermissionDenied: Boolean,
    recordingProgress: Float,
    onMicClicked: () -> Unit,
    onPlayClicked: () -> Unit,
    onMusicClicked: () -> Unit
) {
    Scaffold(
        timeText = {
            TimeText()
        }
    ) {
        // Determine the control dashboard state.
        // This converts the main app state into a control dashboard state for rendering
        val controlDashboardUiState = computeControlDashboardUiState(
            playbackState = playbackState,
            isPermissionDenied = isPermissionDenied
        )

        // The progress bar should only be visible when actively recording
        val isProgressVisible =
            when (playbackState) {
                PlaybackState.PlayingMusic,
                PlaybackState.PlayingVoice,
                is PlaybackState.Ready -> false
                PlaybackState.Recording -> true
            }

        // We are using ConstraintLayout here to center the ControlDashboard, and align the progress
        // indicator to it.
        // In general, ConstraintLayout is less necessary for Compose than it was for Views
        ConstraintLayout(
            modifier = Modifier.fillMaxSize()
        ) {
            val (controlDashboard, progressBar) = createRefs()

            ControlDashboard(
                controlDashboardUiState = controlDashboardUiState,
                onMicClicked = onMicClicked,
                onPlayClicked = onPlayClicked,
                onMusicClicked = onMusicClicked,
                modifier = Modifier
                    .constrainAs(controlDashboard) {
                        centerTo(parent)
                    }
            )

            AnimatedVisibility(
                visible = isProgressVisible,
                modifier = Modifier
                    .constrainAs(progressBar) {
                        width = Dimension.fillToConstraints
                        top.linkTo(controlDashboard.bottom, 5.dp)
                        start.linkTo(controlDashboard.start)
                        end.linkTo(controlDashboard.end)
                    }
            ) {
                LinearProgressIndicator(
                    progress = recordingProgress
                )
            }
        }
    }
}