new: add navigation guards for previous/next sentence in player controls
This commit is contained in:
@@ -39,6 +39,8 @@ fun PlayerControl(
|
|||||||
onMainPlayActionButtonClicked: () -> Unit = {},
|
onMainPlayActionButtonClicked: () -> Unit = {},
|
||||||
onPreviousSentenceClicked: () -> Unit = {},
|
onPreviousSentenceClicked: () -> Unit = {},
|
||||||
onNextSentenceClicked: () -> Unit = {},
|
onNextSentenceClicked: () -> Unit = {},
|
||||||
|
canGoToPreviousSentence: Boolean = true,
|
||||||
|
canGoToNextSentence: Boolean = true,
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = modifier.fillMaxWidth(),
|
modifier = modifier.fillMaxWidth(),
|
||||||
@@ -66,6 +68,7 @@ fun PlayerControl(
|
|||||||
) {
|
) {
|
||||||
IconButton(
|
IconButton(
|
||||||
modifier = Modifier.size(60.dp),
|
modifier = Modifier.size(60.dp),
|
||||||
|
enabled = canGoToPreviousSentence,
|
||||||
onClick = onPreviousSentenceClicked,
|
onClick = onPreviousSentenceClicked,
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
@@ -87,6 +90,7 @@ fun PlayerControl(
|
|||||||
|
|
||||||
IconButton(
|
IconButton(
|
||||||
modifier = Modifier.size(60.dp),
|
modifier = Modifier.size(60.dp),
|
||||||
|
enabled = canGoToNextSentence,
|
||||||
onClick = onNextSentenceClicked,
|
onClick = onNextSentenceClicked,
|
||||||
) {
|
) {
|
||||||
Icon(
|
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,
|
onMainPlayActionButtonClicked = onMainPlayActionButtonClicked,
|
||||||
onPreviousSentenceClicked = onPreviousSentenceClicked,
|
onPreviousSentenceClicked = onPreviousSentenceClicked,
|
||||||
onNextSentenceClicked = onNextSentenceClicked,
|
onNextSentenceClicked = onNextSentenceClicked,
|
||||||
|
canGoToPreviousSentence = uiState.canGoToPreviousSentence,
|
||||||
|
canGoToNextSentence = uiState.canGoToNextSentence,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -8,4 +8,10 @@ data class PlayerUiState(
|
|||||||
val recordTitle: Phrase = Phrase(transcription = ""),
|
val recordTitle: Phrase = Phrase(transcription = ""),
|
||||||
val playerState: PlayerState = PlayerState(),
|
val playerState: PlayerState = PlayerState(),
|
||||||
val subtitlePreferences: SubtitlePreferences = SubtitlePreferences(),
|
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