new: add navigation guards for previous/next sentence in player controls
This commit is contained in:
@@ -39,6 +39,8 @@ fun PlayerControl(
|
||||
onMainPlayActionButtonClicked: () -> Unit = {},
|
||||
onPreviousSentenceClicked: () -> Unit = {},
|
||||
onNextSentenceClicked: () -> Unit = {},
|
||||
canGoToPreviousSentence: Boolean = true,
|
||||
canGoToNextSentence: Boolean = true,
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
@@ -66,6 +68,7 @@ fun PlayerControl(
|
||||
) {
|
||||
IconButton(
|
||||
modifier = Modifier.size(60.dp),
|
||||
enabled = canGoToPreviousSentence,
|
||||
onClick = onPreviousSentenceClicked,
|
||||
) {
|
||||
Icon(
|
||||
@@ -87,6 +90,7 @@ fun PlayerControl(
|
||||
|
||||
IconButton(
|
||||
modifier = Modifier.size(60.dp),
|
||||
enabled = canGoToNextSentence,
|
||||
onClick = onNextSentenceClicked,
|
||||
) {
|
||||
Icon(
|
||||
@@ -122,3 +126,27 @@ private fun PlayerControlPreview() {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
private fun PlayerControlFirstSentencePreview() {
|
||||
GwenedegTheme {
|
||||
PlayerControl(
|
||||
playbackState = PlaybackState.PLAYING,
|
||||
playbackTiming = PlaybackTiming(positionMs = 1234, durationMs = 5000),
|
||||
canGoToPreviousSentence = false,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
private fun PlayerControlLastSentencePreview() {
|
||||
GwenedegTheme {
|
||||
PlayerControl(
|
||||
playbackState = PlaybackState.PLAYING,
|
||||
playbackTiming = PlaybackTiming(positionMs = 1234, durationMs = 5000),
|
||||
canGoToNextSentence = false,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +150,8 @@ fun PlayerScreen(
|
||||
onMainPlayActionButtonClicked = onMainPlayActionButtonClicked,
|
||||
onPreviousSentenceClicked = onPreviousSentenceClicked,
|
||||
onNextSentenceClicked = onNextSentenceClicked,
|
||||
canGoToPreviousSentence = uiState.canGoToPreviousSentence,
|
||||
canGoToNextSentence = uiState.canGoToNextSentence,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+7
-1
@@ -8,4 +8,10 @@ data class PlayerUiState(
|
||||
val recordTitle: Phrase = Phrase(transcription = ""),
|
||||
val playerState: PlayerState = PlayerState(),
|
||||
val subtitlePreferences: SubtitlePreferences = SubtitlePreferences(),
|
||||
)
|
||||
) {
|
||||
val canGoToPreviousSentence: Boolean
|
||||
get() = playerState.playbackTiming.positionMs > 2000
|
||||
|
||||
val canGoToNextSentence: Boolean
|
||||
get() = (playerState.currentSubtitleIndex ?: Int.MAX_VALUE) < playerState.subtitleLines.lastIndex
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user