From 9aaffdc363453fd418bdfadf4c5c994b89f7a7cf Mon Sep 17 00:00:00 2001 From: Antoine Jaury Date: Fri, 3 Jul 2026 10:10:30 +0200 Subject: [PATCH] new: add navigation guards for previous/next sentence in player controls --- .../gwenedeg/player/ui/PlayerControl.kt | 28 +++++++++++++++++++ .../ajaury/gwenedeg/player/ui/PlayerScreen.kt | 2 ++ .../player/ui/viewmodel/PlayerUiState.kt | 8 +++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/player/ui/PlayerControl.kt b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/player/ui/PlayerControl.kt index 9dc3944..72f18d1 100644 --- a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/player/ui/PlayerControl.kt +++ b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/player/ui/PlayerControl.kt @@ -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, + ) + } +} diff --git a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/player/ui/PlayerScreen.kt b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/player/ui/PlayerScreen.kt index 90c6f99..3b6a865 100644 --- a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/player/ui/PlayerScreen.kt +++ b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/player/ui/PlayerScreen.kt @@ -150,6 +150,8 @@ fun PlayerScreen( onMainPlayActionButtonClicked = onMainPlayActionButtonClicked, onPreviousSentenceClicked = onPreviousSentenceClicked, onNextSentenceClicked = onNextSentenceClicked, + canGoToPreviousSentence = uiState.canGoToPreviousSentence, + canGoToNextSentence = uiState.canGoToNextSentence, ) } diff --git a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/player/ui/viewmodel/PlayerUiState.kt b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/player/ui/viewmodel/PlayerUiState.kt index dc1074e..72408ec 100644 --- a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/player/ui/viewmodel/PlayerUiState.kt +++ b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/player/ui/viewmodel/PlayerUiState.kt @@ -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 +}