From 4028018605461f9e8f209b993b5557453e3c553d Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Sun, 15 Oct 2023 17:07:35 -0400 Subject: [PATCH] Adds a border in the image dialog to avoid overriding controllers. --- .../amethyst/ui/components/VideoView.kt | 33 ++++++++++++++- .../ui/components/ZoomableContentView.kt | 42 ++++++++++++++++--- 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/VideoView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/VideoView.kt index e8103b524..d5633b953 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/VideoView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/VideoView.kt @@ -46,8 +46,10 @@ import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.platform.LocalView +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.isFinite +import androidx.compose.ui.unit.isSpecified import androidx.compose.ui.viewinterop.AndroidView import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleEventObserver @@ -149,6 +151,7 @@ fun VideoView( title: String? = null, thumb: VideoThumb? = null, roundedCorner: Boolean, + topPaddingForControllers: Dp = Dp.Unspecified, waveform: ImmutableList? = null, artworkUri: String? = null, authorName: String? = null, @@ -166,6 +169,7 @@ fun VideoView( title = title, thumb = thumb, roundedCorner = roundedCorner, + topPaddingForControllers = topPaddingForControllers, waveform = waveform, artworkUri = artworkUri, authorName = authorName, @@ -185,6 +189,7 @@ fun VideoViewInner( title: String? = null, thumb: VideoThumb? = null, roundedCorner: Boolean, + topPaddingForControllers: Dp = Dp.Unspecified, waveform: ImmutableList? = null, artworkUri: String? = null, authorName: String? = null, @@ -246,6 +251,7 @@ fun VideoViewInner( controller = controller, thumbData = thumb, roundedCorner = roundedCorner, + topPaddingForControllers = topPaddingForControllers, waveform = waveform, keepPlaying = keepPlaying, automaticallyStartPlayback = automaticallyStartPlayback, @@ -514,6 +520,7 @@ private fun RenderVideoPlayer( controller: MediaController, thumbData: VideoThumb?, roundedCorner: Boolean, + topPaddingForControllers: Dp = Dp.Unspecified, waveform: ImmutableList? = null, keepPlaying: MutableState, automaticallyStartPlayback: MutableState, @@ -587,7 +594,17 @@ private fun RenderVideoPlayer( controller.volume < 0.001 } - MuteButton(controllerVisible, startingMuteState) { mute: Boolean -> + MuteButton( + controllerVisible, + startingMuteState, + remember { + if (topPaddingForControllers.isSpecified) { + Modifier.padding(top = topPaddingForControllers) + } else { + Modifier + } + } + ) { mute: Boolean -> // makes the new setting the default for new creations. DefaultMutedSetting.value = mute @@ -601,7 +618,17 @@ private fun RenderVideoPlayer( controller.volume = if (mute) 0f else 1f } - KeepPlayingButton(keepPlaying, controllerVisible, remember { Modifier.align(Alignment.TopEnd) }) { newKeepPlaying: Boolean -> + KeepPlayingButton( + keepPlaying, + controllerVisible, + remember { + if (topPaddingForControllers.isSpecified) { + Modifier.align(Alignment.TopEnd).padding(top = topPaddingForControllers) + } else { + Modifier.align(Alignment.TopEnd) + } + } + ) { newKeepPlaying: Boolean -> // If something else is playing and the user marks this video to keep playing, stops the other one. if (newKeepPlaying) { if (keepPlayingMutex != null && keepPlayingMutex != controller) { @@ -775,6 +802,7 @@ fun LayoutCoordinates.getDistanceToVertCenterIfVisible(view: View): Float? { private fun MuteButton( controllerVisible: MutableState, startingMuteState: Boolean, + modifier: Modifier, toggle: (Boolean) -> Unit ) { val holdOn = remember { @@ -794,6 +822,7 @@ private fun MuteButton( AnimatedVisibility( visible = holdOn.value || controllerVisible.value, + modifier = modifier, enter = fadeIn(), exit = fadeOut() ) { diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt index c4c7dc07d..40060becc 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt @@ -64,8 +64,10 @@ import androidx.compose.ui.text.Placeholder import androidx.compose.ui.text.PlaceholderVerticalAlign import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.withStyle +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.isFinite +import androidx.compose.ui.unit.isSpecified import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.DialogProperties import androidx.compose.ui.window.DialogWindowProvider @@ -92,6 +94,7 @@ import com.vitorpamplona.amethyst.ui.theme.Size20Modifier import com.vitorpamplona.amethyst.ui.theme.Size20dp import com.vitorpamplona.amethyst.ui.theme.Size24dp import com.vitorpamplona.amethyst.ui.theme.Size30dp +import com.vitorpamplona.amethyst.ui.theme.Size55dp import com.vitorpamplona.amethyst.ui.theme.Size5dp import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer import com.vitorpamplona.amethyst.ui.theme.imageModifier @@ -234,7 +237,7 @@ fun ZoomableContentView( } when (content) { - is ZoomableUrlImage -> UrlImageView(content, mainImageModifier, accountViewModel) + is ZoomableUrlImage -> UrlImageView(content, mainImageModifier, accountViewModel = accountViewModel) is ZoomableUrlVideo -> VideoView( videoUri = content.url, title = content.description, @@ -246,7 +249,7 @@ fun ZoomableContentView( accountViewModel = accountViewModel ) - is ZoomableLocalImage -> LocalImageView(content, mainImageModifier, accountViewModel) + is ZoomableLocalImage -> LocalImageView(content, mainImageModifier, accountViewModel = accountViewModel) is ZoomableLocalVideo -> content.localFile?.let { VideoView( @@ -271,6 +274,7 @@ fun ZoomableContentView( private fun LocalImageView( content: ZoomableLocalImage, mainImageModifier: Modifier, + topPaddingForControllers: Dp = Dp.Unspecified, accountViewModel: AccountViewModel?, alwayShowImage: Boolean = false ) { @@ -304,7 +308,11 @@ private fun LocalImageView( if (maxHeight.isFinite) ContentScale.Fit else ContentScale.FillWidth } - val verifierModifier = Modifier.align(Alignment.TopEnd) + val verifierModifier = if (topPaddingForControllers.isSpecified) { + Modifier.padding(top = topPaddingForControllers).align(Alignment.TopEnd) + } else { + Modifier.align(Alignment.TopEnd) + } val painterState = remember { mutableStateOf(null) @@ -340,6 +348,7 @@ private fun LocalImageView( private fun UrlImageView( content: ZoomableUrlImage, mainImageModifier: Modifier, + topPaddingForControllers: Dp = Dp.Unspecified, accountViewModel: AccountViewModel?, alwayShowImage: Boolean = false ) { @@ -374,7 +383,11 @@ private fun UrlImageView( if (maxHeight.isFinite) ContentScale.Fit else ContentScale.FillWidth } - val verifierModifier = Modifier.align(Alignment.TopEnd) + val verifierModifier = if (topPaddingForControllers.isSpecified) { + Modifier.padding(top = topPaddingForControllers).align(Alignment.TopEnd) + } else { + Modifier.align(Alignment.TopEnd) + } val painterState = remember { mutableStateOf(null) @@ -679,6 +692,7 @@ private fun DialogContent( RenderImageOrVideo( content = allImages[index], roundedCorner = false, + topPaddingForControllers = Size55dp, onControllerVisibilityChanged = { controllerVisible.value = it }, @@ -689,6 +703,7 @@ private fun DialogContent( RenderImageOrVideo( content = imageUrl, roundedCorner = false, + topPaddingForControllers = Size55dp, onControllerVisibilityChanged = { controllerVisible.value = it }, @@ -798,6 +813,7 @@ private fun ShareImageAction( private fun RenderImageOrVideo( content: ZoomableContent, roundedCorner: Boolean, + topPaddingForControllers: Dp = Dp.Unspecified, onControllerVisibilityChanged: ((Boolean) -> Unit)? = null, accountViewModel: AccountViewModel ) { @@ -806,7 +822,13 @@ private fun RenderImageOrVideo( .zoomable(rememberZoomState()) if (content is ZoomableUrlImage) { - UrlImageView(content = content, mainImageModifier = mainModifier, accountViewModel, alwayShowImage = true) + UrlImageView( + content = content, + mainImageModifier = mainModifier, + topPaddingForControllers = topPaddingForControllers, + accountViewModel, + alwayShowImage = true + ) } else if (content is ZoomableUrlVideo) { Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxSize(1f)) { VideoView( @@ -815,13 +837,20 @@ private fun RenderImageOrVideo( artworkUri = content.artworkUri, authorName = content.authorName, roundedCorner = roundedCorner, + topPaddingForControllers = topPaddingForControllers, onControllerVisibilityChanged = onControllerVisibilityChanged, accountViewModel = accountViewModel, alwaysShowVideo = true ) } } else if (content is ZoomableLocalImage) { - LocalImageView(content = content, mainImageModifier = mainModifier, accountViewModel, alwayShowImage = true) + LocalImageView( + content = content, + mainImageModifier = mainModifier, + topPaddingForControllers = topPaddingForControllers, + accountViewModel, + alwayShowImage = true + ) } else if (content is ZoomableLocalVideo) { Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxSize(1f)) { content.localFile?.let { @@ -831,6 +860,7 @@ private fun RenderImageOrVideo( artworkUri = content.artworkUri, authorName = content.authorName, roundedCorner = roundedCorner, + topPaddingForControllers = topPaddingForControllers, onControllerVisibilityChanged = onControllerVisibilityChanged, accountViewModel = accountViewModel, alwaysShowVideo = true