Skip to content

Commit 630d128

Browse files
committed
make seek preview chapter to be seek preview text, so not only the chapter can be shown
1 parent e5e8e4b commit 630d128

File tree

3 files changed

+40
-28
lines changed

3 files changed

+40
-28
lines changed

new-player/src/main/java/net/newpipe/newplayer/ui/common/thumb_preview/ThumbPreview.kt

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,27 @@ import androidx.compose.animation.fadeIn
2828
import androidx.compose.animation.fadeOut
2929
import androidx.compose.foundation.Image
3030
import androidx.compose.foundation.background
31-
import androidx.compose.foundation.layout.*
31+
import androidx.compose.foundation.layout.Box
32+
import androidx.compose.foundation.layout.Column
33+
import androidx.compose.foundation.layout.Row
34+
import androidx.compose.foundation.layout.aspectRatio
35+
import androidx.compose.foundation.layout.fillMaxSize
36+
import androidx.compose.foundation.layout.fillMaxWidth
37+
import androidx.compose.foundation.layout.height
38+
import androidx.compose.foundation.layout.offset
39+
import androidx.compose.foundation.layout.padding
40+
import androidx.compose.foundation.layout.wrapContentSize
3241
import androidx.compose.material3.Card
3342
import androidx.compose.material3.CardDefaults
3443
import androidx.compose.material3.Slider
3544
import androidx.compose.material3.Text
36-
import androidx.compose.runtime.*
45+
import androidx.compose.runtime.Composable
46+
import androidx.compose.runtime.getValue
47+
import androidx.compose.runtime.mutableFloatStateOf
48+
import androidx.compose.runtime.mutableIntStateOf
49+
import androidx.compose.runtime.mutableStateOf
50+
import androidx.compose.runtime.remember
51+
import androidx.compose.runtime.setValue
3752
import androidx.compose.ui.Alignment
3853
import androidx.compose.ui.Modifier
3954
import androidx.compose.ui.graphics.Color
@@ -93,9 +108,11 @@ internal fun ThumbPreview(
93108
) {
94109
// Together with the getHeight() function this Box ensures that the thumbnail
95110
// does not collapse and glitch during enter and exit animation.
96-
Box(Modifier
97-
.fillMaxSize()
98-
.background(Color.Red)) {
111+
Box(
112+
Modifier
113+
.fillMaxSize()
114+
.background(Color.Red)
115+
) {
99116
// this allows the current thumbnail to remain when animated visibility is being hidden
100117
var lastAvailableImage by remember {
101118
mutableStateOf(uiState.currentSeekPreviewThumbnail)
@@ -182,7 +199,11 @@ private fun ThumbPreviewPreview() {
182199
seekerPosition = sliderPosition,
183200
seekPreviewVisible = thumbDown,
184201
currentSeekPreviewThumbnail = previewThumbnail.asImageBitmap(),
185-
currentSeekPreviewChapter = Chapter(0, "What a wonderfull chapter", null)
202+
currentSeekPreviewText = Chapter(
203+
0,
204+
"What a wonderfull chapter",
205+
null
206+
).chapterTitle
186207
),
187208
additionalStartPaddingPxls = startOffset,
188209
additionalEndPaddingPxls = endOffset,

new-player/src/main/java/net/newpipe/newplayer/uiModel/NewPlayerUIState.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ data class NewPlayerUIState(
185185
val currentSeekPreviewThumbnail: ImageBitmap?,
186186

187187
/**
188-
* The seeker preview chapter that should be visible. This updates if the user uses
189-
* the seeker thumb to seek through a stream. If null no chapter is available.
188+
* The seeker preview text that should be visible when the playback position is changed through
189+
* the seek bar. If null no text will be rendered.
190190
*/
191-
val currentSeekPreviewChapter: Chapter?,
191+
val currentSeekPreviewText: String?,
192192

193193
/**
194194
* Depicts weather the seeker preview thumbnail should be visible or not.
@@ -227,7 +227,7 @@ data class NewPlayerUIState(
227227
currentlyPlayingTracks = emptyList(),
228228
enteringPip = false,
229229
currentSeekPreviewThumbnail = null,
230-
currentSeekPreviewChapter = null,
230+
currentSeekPreviewText = null,
231231
seekPreviewVisible = false,
232232
)
233233

new-player/src/main/java/net/newpipe/newplayer/uiModel/NewPlayerViewModelImpl.kt

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,7 @@ class NewPlayerViewModelImpl @Inject constructor(
476476
newPlayer?.currentPosition = seekPositionInMs
477477
Log.i(TAG, "Seek to Ms: $seekPositionInMs")
478478

479-
updateSeekPreviewThumbnail(seekPositionInMs)
480-
updateSeekPreviewChapter(seekPositionInMs)
479+
updateSeekPreview(seekPositionInMs)
481480
mutableUiState.update {
482481
it.copy(
483482
seekerPosition = newValue,
@@ -487,35 +486,27 @@ class NewPlayerViewModelImpl @Inject constructor(
487486
}
488487
}
489488

490-
private fun updateSeekPreviewChapter(seekPositionInMs: Long) {
491-
viewModelScope.launch {
492-
val chapters = mutableUiState.value.chapters
493-
val chapter = chapters.lastOrNull {
494-
it.chapterStartInMs < seekPositionInMs
495-
}
496-
mutableUiState.update {
497-
it.copy(
498-
currentSeekPreviewChapter = chapter,
499-
seekPreviewVisible = true
500-
)
501-
}
502-
}
503-
}
504-
505-
private fun updateSeekPreviewThumbnail(seekPositionInMs: Long) {
489+
private fun updateSeekPreview(seekPositionInMs: Long) {
506490
updatePreviewThumbnailJob?.cancel()
507491

508492
updatePreviewThumbnailJob = viewModelScope.launch {
509493

510494
val item = newPlayer?.currentlyPlaying?.value?.let {
511495
newPlayer?.getItemFromMediaItem(it)
512496
}
497+
498+
val chapters = mutableUiState.value.chapters
499+
val chapter = chapters.lastOrNull {
500+
it.chapterStartInMs < seekPositionInMs
501+
}
502+
513503
item?.let {
514504
val bitmap =
515505
newPlayer?.repository?.getPreviewThumbnail(item, seekPositionInMs)
516506

517507
mutableUiState.update {
518508
it.copy(
509+
currentSeekPreviewText = chapter?.chapterTitle,
519510
currentSeekPreviewThumbnail = bitmap?.asImageBitmap(),
520511
seekPreviewVisible = true
521512
)

0 commit comments

Comments
 (0)