From 38bf37e88a67ac6b35a0ae4b1b13b6bb654da615 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Mon, 2 Sep 2024 15:26:37 +0200 Subject: [PATCH] cleanup stream items --- .../newplayer/ui/videoplayer/BottomUI.kt | 2 - .../ui/videoplayer/StreamSelectUI.kt | 1 - .../videoplayer/streamselect/ChapterItem.kt | 2 +- .../ui/videoplayer/streamselect/StreamItem.kt | 125 ++++++++++-------- new-player/src/main/res/values/strings.xml | 3 +- 5 files changed, 70 insertions(+), 63 deletions(-) diff --git a/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/BottomUI.kt b/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/BottomUI.kt index 1623f45..f732bd8 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/BottomUI.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/BottomUI.kt @@ -80,8 +80,6 @@ fun BottomUI( colors = customizedSeekerColors() ) - //Slider(value = 0.4F, onValueChange = {}, modifier = Modifier.weight(1F)) - Text(getTimeStringFromMs(uiState.durationInMs, getLocale() ?: locale)) val embeddedUiConfig = getEmbeddedUiConfig(LocalContext.current as Activity) diff --git a/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/StreamSelectUI.kt b/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/StreamSelectUI.kt index 1e23815..216de80 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/StreamSelectUI.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/StreamSelectUI.kt @@ -95,7 +95,6 @@ fun StreamSelectUI( modifier = Modifier .padding(innerPadding) .fillMaxSize(), -// verticalArrangement = Arrangement.spacedBy(10.dp), contentPadding = PaddingValues(start = 8.dp, end = 4.dp) ) { if (isChapterSelect) { diff --git a/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/streamselect/ChapterItem.kt b/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/streamselect/ChapterItem.kt index 3ceea08..7b92bf2 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/streamselect/ChapterItem.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/streamselect/ChapterItem.kt @@ -68,7 +68,7 @@ fun ChapterItem( .padding(5.dp) .clickable { onClicked(id) } ) { - val contentDescription = stringResource(R.string.chapter) + val contentDescription = stringResource(R.string.chapter_thumbnail) if (thumbnail != null) { when (thumbnail) { is OnlineThumbnail -> AsyncImage( diff --git a/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/streamselect/StreamItem.kt b/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/streamselect/StreamItem.kt index c1fddda..aa72960 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/streamselect/StreamItem.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/streamselect/StreamItem.kt @@ -65,7 +65,68 @@ import net.newpipe.newplayer.utils.VectorThumbnail import net.newpipe.newplayer.utils.getLocale import net.newpipe.newplayer.utils.getTimeStringFromMs +@Composable +private fun Thumbnail(thumbnail: Thumbnail?, contentDescription: String) { + if (thumbnail != null) { + when (thumbnail) { + is OnlineThumbnail -> AsyncImage( + modifier = Modifier.fillMaxSize(), + model = thumbnail.url, + contentDescription = contentDescription + ) + + is BitmapThumbnail -> Image( + modifier = Modifier.fillMaxSize(), + bitmap = thumbnail.img, + contentDescription = contentDescription + ) + + is VectorThumbnail -> Image( + modifier = Modifier.fillMaxSize(), + imageVector = thumbnail.vec, + contentDescription = contentDescription + ) + } + } else { + Image( + painter = painterResource(R.drawable.tiny_placeholder), + contentDescription = contentDescription + ) + } +} + @OptIn(ExperimentalComposeUiApi::class) +@Composable +private fun DragComposable(onDragStart: () -> Unit, onDragEnd: () -> Unit) { + Box(modifier = Modifier + .aspectRatio(1f) + .fillMaxSize() + .pointerInteropFilter { + when (it.action) { + MotionEvent.ACTION_UP -> { + onDragEnd() + false + } + + MotionEvent.ACTION_DOWN -> { + onDragStart() + false + } + + else -> true + } + }) { + Icon( + modifier = Modifier + .size(25.dp) + .align(Alignment.Center), + imageVector = Icons.Filled.DragHandle, + //contentDescription = stringResource(R.string.stream_item_drag_handle) + contentDescription = "placeholer, TODO: FIXME" + ) + } +} + @Composable fun StreamItem( modifier: Modifier = Modifier, @@ -86,37 +147,10 @@ fun StreamItem( Box( modifier = Modifier .aspectRatio(16f / 9f) - .wrapContentHeight() - .fillMaxWidth() + .wrapContentSize() ) { - val contentDescription = stringResource(R.string.chapter) - if (thumbnail != null) { - when (thumbnail) { - is OnlineThumbnail -> AsyncImage( - modifier = Modifier.fillMaxSize(), - model = thumbnail.url, - contentDescription = contentDescription - ) - - is BitmapThumbnail -> Image( - modifier = Modifier.fillMaxSize(), - bitmap = thumbnail.img, - contentDescription = contentDescription - ) - - is VectorThumbnail -> Image( - modifier = Modifier.fillMaxSize(), - imageVector = thumbnail.vec, - contentDescription = contentDescription - ) - } - } else { - Image( - modifier = Modifier.fillMaxSize(), - painter = painterResource(R.drawable.tiny_placeholder), - contentDescription = contentDescription - ) - } + val contentDescription = stringResource(R.string.stream_item_thumbnail) + Thumbnail(thumbnail, contentDescription) Surface( color = CONTROLLER_UI_BACKGROUND_COLOR, modifier = Modifier @@ -141,7 +175,7 @@ fun StreamItem( modifier = Modifier .padding(1.dp) .weight(1f) - .height(IntrinsicSize.Min) + .wrapContentHeight() .fillMaxWidth() ) { Text( @@ -156,37 +190,12 @@ fun StreamItem( } } - Box(modifier = Modifier - .aspectRatio(1f) - .fillMaxSize() - .pointerInteropFilter { - when (it.action) { - MotionEvent.ACTION_UP -> { - onDragEnd(id) - false - } + DragComposable(onDragStart = { onDragStart(id) }, onDragEnd = { onDragEnd(id) }) - MotionEvent.ACTION_DOWN -> { - onDragStart(id) - false - } - - else -> true - } - }) { - Icon( - modifier = Modifier - .size(25.dp) - .align(Alignment.Center), - imageVector = Icons.Filled.DragHandle, - //contentDescription = stringResource(R.string.stream_item_drag_handle) - contentDescription = "placeholer, TODO: FIXME" - ) - } } } -@Preview(device = "spec:width=1080px,height=200px,dpi=440,orientation=landscape") +@Preview(device = "spec:width=1080px,height=400px,dpi=440,orientation=landscape") @Composable fun StreamItemPreview() { VideoPlayerTheme { diff --git a/new-player/src/main/res/values/strings.xml b/new-player/src/main/res/values/strings.xml index d7df845..10eb491 100644 --- a/new-player/src/main/res/values/strings.xml +++ b/new-player/src/main/res/values/strings.xml @@ -43,7 +43,8 @@ Close chapter selection Close stream selection Chapter - Chapter Thumbnail + Chapter thumbnail + Stream item thumbnail Stream item drag handle Repeat mode: No repeat Repeat mode: Repeat all