Skip to content

Commit

Permalink
Fixes video rotation screen in full size while playing
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Dec 3, 2024
1 parent b988309 commit fe3246c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit fe3246c

Please sign in to comment.