From 936aa4d2cffea157cf7c1894e6fbc8e9f41435dd Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Sat, 30 Sep 2023 16:28:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=86=E9=A2=91=E6=92=AD=E6=94=BE?= =?UTF-8?q?=E5=99=A8=E9=87=8D=E5=BB=BA=E5=90=8E=E8=87=AA=E5=8A=A8=E6=92=AD?= =?UTF-8?q?=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tieba/post/ui/common/PbContentRender.kt | 20 +++++++++---- .../tieba/post/ui/widgets/compose/FeedCard.kt | 28 +++++++++++++------ .../compose/video/MediaContaonButtons.kt | 10 +++++++ .../ui/widgets/compose/video/VideoPlayer.kt | 2 +- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/common/PbContentRender.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/common/PbContentRender.kt index a1d2a8ba..8f82686b 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/common/PbContentRender.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/common/PbContentRender.kt @@ -4,6 +4,8 @@ import androidx.compose.foundation.clickable import androidx.compose.foundation.gestures.awaitEachGesture import androidx.compose.foundation.gestures.awaitFirstDown import androidx.compose.foundation.gestures.waitForUpOrCancellation +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.shape.RoundedCornerShape @@ -188,11 +190,19 @@ data class VideoContentRender( .aspectRatio(width * 1f / height) if (videoUrl.isNotBlank()) { - com.huanchengfly.tieba.post.ui.widgets.compose.VideoPlayer( - videoUrl = videoUrl, - thumbnailUrl = picUrl, - modifier = picModifier - ) + Box( + modifier = Modifier.clickable( + interactionSource = remember { MutableInteractionSource() }, + indication = null, + onClick = {} + ) + ) { + com.huanchengfly.tieba.post.ui.widgets.compose.VideoPlayer( + videoUrl = videoUrl, + thumbnailUrl = picUrl, + modifier = picModifier + ) + } } else { AsyncImage( imageUri = picUrl, diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/FeedCard.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/FeedCard.kt index 3e584d3a..4d5f0238 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/FeedCard.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/FeedCard.kt @@ -5,6 +5,7 @@ import android.util.Log import androidx.compose.animation.animateColorAsState import androidx.compose.foundation.background import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -356,14 +357,22 @@ private fun ThreadMedia( 16f / 9 ) } - VideoPlayer( - videoUrl = videoInfo.get { videoUrl }, - thumbnailUrl = videoInfo.get { thumbnailUrl }, - modifier = Modifier - .fillMaxWidth(singleMediaFraction) - .aspectRatio(aspectRatio) - .clip(RoundedCornerShape(8.dp)) - ) + Box( + modifier = Modifier.clickable( + interactionSource = remember { MutableInteractionSource() }, + indication = null, + onClick = {} + ) + ) { + VideoPlayer( + videoUrl = videoInfo.get { videoUrl }, + thumbnailUrl = videoInfo.get { thumbnailUrl }, + modifier = Modifier + .fillMaxWidth(singleMediaFraction) + .aspectRatio(aspectRatio) + .clip(RoundedCornerShape(8.dp)) + ) + } } else if (hasMedia) { val mediaWidthFraction = remember(isSingleMedia, singleMediaFraction) { if (isSingleMedia) singleMediaFraction else 1f @@ -646,11 +655,12 @@ fun VideoPlayer( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE } else { context.findActivity()?.requestedOrientation = - ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT + ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } } } ) + val fullScreen by (videoPlayerController as DefaultVideoPlayerController).collect { isFullScreen } val videoPlayerContent = movableContentOf { isFullScreen: Boolean, playerModifier: Modifier -> diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/video/MediaContaonButtons.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/video/MediaContaonButtons.kt index 38c29444..732f2b2e 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/video/MediaContaonButtons.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/video/MediaContaonButtons.kt @@ -63,6 +63,16 @@ fun MediaControlButtons( .background(Color.Black.copy(alpha = appearAlpha.value * 0.6f)) .then(modifier) ) + } else { + Box(modifier = modifier) { + Box(modifier = Modifier + .fillMaxSize() + .clickable( + indication = null, + interactionSource = remember { MutableInteractionSource() } + ) {} + ) + } } } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/video/VideoPlayer.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/video/VideoPlayer.kt index 8eca969f..1549524f 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/video/VideoPlayer.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/video/VideoPlayer.kt @@ -70,7 +70,7 @@ fun rememberVideoPlayerController( override fun restore(value: VideoPlayerState): DefaultVideoPlayerController { return DefaultVideoPlayerController( context = context, - initialState = value, + initialState = value.copy(isPlaying = playWhenReady), coroutineScope = coroutineScope, fullScreenModeChangedListener = fullScreenModeChangedListener ).apply {