Skip to content
This repository was archived by the owner on Mar 30, 2026. It is now read-only.

Commit 83be423

Browse files
committed
Added a gesture to the Chapter Indicator to jump to Next/Previous chapter with left/right swipe.
1 parent 01a9306 commit 83be423

3 files changed

Lines changed: 38 additions & 6 deletions

File tree

app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/CurrentChapter.kt

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import androidx.compose.animation.AnimatedContent
44
import androidx.compose.animation.SizeTransform
55
import androidx.compose.animation.fadeIn
66
import androidx.compose.animation.fadeOut
7-
import androidx.compose.animation.slideInVertically
8-
import androidx.compose.animation.slideOutVertically
7+
import androidx.compose.animation.slideInHorizontally
8+
import androidx.compose.animation.slideOutHorizontally
99
import androidx.compose.animation.togetherWith
1010
import androidx.compose.foundation.background
1111
import androidx.compose.foundation.clickable
12+
import androidx.compose.foundation.gestures.detectHorizontalDragGestures
1213
import androidx.compose.foundation.layout.Arrangement
1314
import androidx.compose.foundation.layout.Box
1415
import androidx.compose.foundation.layout.Row
@@ -24,11 +25,13 @@ import androidx.compose.runtime.Composable
2425
import androidx.compose.ui.Alignment
2526
import androidx.compose.ui.Modifier
2627
import androidx.compose.ui.draw.clip
28+
import androidx.compose.ui.input.pointer.pointerInput
2729
import androidx.compose.ui.text.font.FontWeight
2830
import androidx.compose.ui.text.style.TextAlign
2931
import androidx.compose.ui.text.style.TextOverflow
3032
import androidx.compose.ui.unit.dp
3133
import dev.vivvvek.seeker.Segment
34+
import `is`.xyz.mpv.MPVLib
3235
import `is`.xyz.mpv.Utils
3336
import live.mehiz.mpvkt.ui.theme.spacing
3437

@@ -43,17 +46,41 @@ fun CurrentChapter(
4346
.clip(RoundedCornerShape(25))
4447
.background(MaterialTheme.colorScheme.background.copy(alpha = 0.6F))
4548
.clickable(onClick = onClick)
49+
.pointerInput(Unit) {
50+
var totalDrag = 0f
51+
val swipeThreshold = 100f
52+
detectHorizontalDragGestures(
53+
onHorizontalDrag = { change, dragAmount ->
54+
change.consume()
55+
totalDrag += dragAmount
56+
},
57+
onDragEnd = {
58+
val current = MPVLib.getPropertyInt("chapter") ?: 0
59+
when {
60+
totalDrag > swipeThreshold -> {
61+
// Previous chapter
62+
MPVLib.setPropertyInt("chapter", (current - 1).coerceAtLeast(0))
63+
}
64+
totalDrag < -swipeThreshold -> {
65+
// Next chapter
66+
MPVLib.setPropertyInt("chapter", (current + 1))
67+
}
68+
}
69+
totalDrag = 0f
70+
}
71+
)
72+
}
4673
.padding(horizontal = MaterialTheme.spacing.small, vertical = MaterialTheme.spacing.smaller),
4774
) {
4875
AnimatedContent(
4976
targetState = chapter,
5077
transitionSpec = {
5178
if (targetState.start > initialState.start) {
52-
(slideInVertically { height -> height } + fadeIn())
53-
.togetherWith(slideOutVertically { height -> -height } + fadeOut())
79+
(slideInHorizontally { width -> width } + fadeIn())
80+
.togetherWith(slideOutHorizontally { width -> -width } + fadeOut())
5481
} else {
55-
(slideInVertically { height -> -height } + fadeIn())
56-
.togetherWith(slideOutVertically { height -> height } + fadeOut())
82+
(slideInHorizontally { width -> -width } + fadeIn())
83+
.togetherWith(slideOutHorizontally { width -> width } + fadeOut())
5784
}.using(
5885
SizeTransform(clip = false),
5986
)

app/src/main/java/live/mehiz/mpvkt/ui/preferences/PlayerPreferencesScreen.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import live.mehiz.mpvkt.presentation.Screen
2828
import live.mehiz.mpvkt.ui.player.PlayerOrientation
2929
import live.mehiz.mpvkt.ui.player.controls.components.sheets.toFixed
3030
import live.mehiz.mpvkt.ui.utils.LocalBackStack
31+
import me.zhanghai.compose.preference.FooterPreference
3132
import me.zhanghai.compose.preference.ListPreference
3233
import me.zhanghai.compose.preference.PreferenceCategory
3334
import me.zhanghai.compose.preference.ProvidePreferenceLocals
@@ -223,6 +224,9 @@ object PlayerPreferencesScreen : Screen {
223224
title = { Text(stringResource(R.string.pref_player_controls_show_chapter_indicator)) },
224225
summary = { Text(stringResource(R.string.pref_player_controls_show_chapters_summary)) },
225226
)
227+
FooterPreference(
228+
{Text(stringResource(R.string.pref_player_controls_chapter_indicator_gestures))}
229+
)
226230

227231
PreferenceCategory(
228232
title = { Text(stringResource(R.string.pref_player_display)) },

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<string name="pref_player_controls_display_volume_as_percentage">Display volume as percentage</string>
6464
<string name="pref_player_controls_show_loading_circle">Show loading circle</string>
6565
<string name="pref_player_controls_show_chapter_indicator">Show current chapter indicator</string>
66+
<string name="pref_player_controls_chapter_indicator_gestures">On the indicator, swipe left to jump to the Next Chapter and right to jump to the Previous one</string>
6667
<string name="pref_player_controls_show_chapters_button">Show chapters select button</string>
6768
<string name="pref_player_controls_show_chapters_summary">Only appears if the video has chapters</string>
6869
<string name="pref_player_display_show_status_bar">Show system status bar with controls</string>

0 commit comments

Comments
 (0)