Fixes video rotation screen in full size while playing

This commit is contained in:
Vitor Pamplona 2024-12-03 15:53:17 -05:00
parent b9883093ac
commit fe3246c94e
2 changed files with 15 additions and 31 deletions

View File

@ -363,15 +363,15 @@ fun VideoViewInner(
onDialog: ((Boolean) -> Unit)? = null,
accountViewModel: AccountViewModel,
) {
VideoPlayerActiveMutex(videoUri) { videoModifier, activeOnScreen ->
GetMediaItem(videoUri, title, artworkUri, authorName) { mediaItem ->
GetVideoController(
mediaItem = mediaItem,
videoUri = videoUri,
defaultToStart = defaultToStart,
nostrUriCallback = nostrUriCallback,
proxyPort = HttpClientManager.getCurrentProxyPort(accountViewModel.account.shouldUseTorForVideoDownload(videoUri)),
) { controller, keepPlaying ->
GetMediaItem(videoUri, title, artworkUri, authorName) { mediaItem ->
GetVideoController(
mediaItem = mediaItem,
videoUri = videoUri,
defaultToStart = defaultToStart,
nostrUriCallback = nostrUriCallback,
proxyPort = HttpClientManager.getCurrentProxyPort(accountViewModel.account.shouldUseTorForVideoDownload(videoUri)),
) { controller, keepPlaying ->
VideoPlayerActiveMutex(controller) { videoModifier, activeOnScreen ->
RenderVideoPlayer(
videoUri = videoUri,
mimeType = mimeType,
@ -670,22 +670,22 @@ class VisibilityData {
*/
@Composable
fun VideoPlayerActiveMutex(
videoUri: String,
controller: MediaController,
inner: @Composable (Modifier, MutableState<Boolean>) -> Unit,
) {
val myCache = remember(videoUri) { VisibilityData() }
val myCache = remember(controller) { VisibilityData() }
// Is the current video the closest to the center?
val active = remember(videoUri) { mutableStateOf<Boolean>(false) }
val active = remember(controller) { mutableStateOf<Boolean>(false) }
// Keep track of all available videos.
DisposableEffect(key1 = videoUri) {
DisposableEffect(key1 = controller) {
trackingVideos.add(myCache)
onDispose { trackingVideos.remove(myCache) }
}
val videoModifier =
remember(videoUri) {
remember(controller) {
Modifier.fillMaxWidth().heightIn(min = 100.dp).onVisiblePositionChanges { distanceToCenter ->
myCache.distanceToCenter = distanceToCenter

View File

@ -23,9 +23,7 @@ package com.vitorpamplona.amethyst.ui.components
import android.Manifest
import android.content.Context
import android.os.Build
import android.view.View
import android.view.WindowManager
import android.widget.FrameLayout
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
@ -61,7 +59,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import androidx.core.net.toUri
@ -105,34 +102,21 @@ fun ZoomableImageDialog(
onDismissRequest = onDismiss,
properties =
DialogProperties(
usePlatformDefaultWidth = false,
usePlatformDefaultWidth = true,
decorFitsSystemWindows = false,
),
) {
val view = LocalView.current
val orientation = LocalConfiguration.current.orientation
println("This Log only exists to force orientation listener $orientation")
val activityWindow = getActivityWindow()
val dialogWindow = getDialogWindow()
val parentView = LocalView.current.parent as View
if (activityWindow != null && dialogWindow != null) {
val attributes = WindowManager.LayoutParams()
attributes.copyFrom(activityWindow.attributes)
attributes.type = dialogWindow.attributes.type
dialogWindow.attributes = attributes
parentView.layoutParams =
FrameLayout.LayoutParams(
activityWindow.decorView.width,
activityWindow.decorView.height,
)
view.layoutParams =
FrameLayout.LayoutParams(
activityWindow.decorView.width,
activityWindow.decorView.height,
)
}
Surface(Modifier.fillMaxSize()) {