From bfce57f686144e27f9c7bb0b39681834220daecf Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 11 Dec 2023 19:58:29 -0500 Subject: [PATCH] Improving the video switching from blurhash to video --- .../amethyst/ui/components/VideoView.kt | 94 +++++++++++-------- 1 file changed, 57 insertions(+), 37 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 53a0fdacb..2fe16d2fd 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 @@ -182,26 +182,36 @@ fun VideoView( ) } - if (!automaticallyStartPlayback.value) { - if (blurhash != null) { - val ratio = aspectRatio(dimensions) - val modifier = if (ratio != null && roundedCorner) { - Modifier.aspectRatio(ratio) - } else { - Modifier - } - - Box(modifier, contentAlignment = Alignment.Center) { - DisplayBlurHash(blurhash, null, ContentScale.Crop, MaterialTheme.colorScheme.imageModifier) - IconButton( - modifier = Modifier.size(Size75dp), - onClick = { automaticallyStartPlayback.value = true } - ) { - DownloadForOfflineIcon(Size75dp, Color.White) - } - } + if (blurhash == null) { + val ratio = aspectRatio(dimensions) + val modifier = if (ratio != null && roundedCorner) { + Modifier.aspectRatio(ratio) } else { - ImageUrlWithDownloadButton(url = videoUri, showImage = automaticallyStartPlayback) + Modifier + } + + Box(modifier) { + if (!automaticallyStartPlayback.value) { + ImageUrlWithDownloadButton(url = videoUri, showImage = automaticallyStartPlayback) + } else { + VideoViewInner( + videoUri = videoUri, + defaultToStart = defaultToStart, + title = title, + thumb = thumb, + roundedCorner = roundedCorner, + topPaddingForControllers = topPaddingForControllers, + waveform = waveform, + artworkUri = artworkUri, + authorName = authorName, + dimensions = dimensions, + blurhash = blurhash, + nostrUriCallback = nostrUriCallback, + automaticallyStartPlayback = automaticallyStartPlayback, + onControllerVisibilityChanged = onControllerVisibilityChanged, + onDialog = onDialog + ) + } } } else { val ratio = aspectRatio(dimensions) @@ -211,24 +221,34 @@ fun VideoView( Modifier } - Box(modifier) { - VideoViewInner( - videoUri = videoUri, - defaultToStart = defaultToStart, - title = title, - thumb = thumb, - roundedCorner = roundedCorner, - topPaddingForControllers = topPaddingForControllers, - waveform = waveform, - artworkUri = artworkUri, - authorName = authorName, - dimensions = dimensions, - blurhash = blurhash, - nostrUriCallback = nostrUriCallback, - automaticallyStartPlayback = automaticallyStartPlayback, - onControllerVisibilityChanged = onControllerVisibilityChanged, - onDialog = onDialog - ) + Box(modifier, contentAlignment = Alignment.Center) { + if (!automaticallyStartPlayback.value) { + DisplayBlurHash(blurhash, null, ContentScale.Crop, MaterialTheme.colorScheme.imageModifier) + IconButton( + modifier = Modifier.size(Size75dp), + onClick = { automaticallyStartPlayback.value = true } + ) { + DownloadForOfflineIcon(Size75dp, Color.White) + } + } else { + VideoViewInner( + videoUri = videoUri, + defaultToStart = defaultToStart, + title = title, + thumb = thumb, + roundedCorner = roundedCorner, + topPaddingForControllers = topPaddingForControllers, + waveform = waveform, + artworkUri = artworkUri, + authorName = authorName, + dimensions = dimensions, + blurhash = blurhash, + nostrUriCallback = nostrUriCallback, + automaticallyStartPlayback = automaticallyStartPlayback, + onControllerVisibilityChanged = onControllerVisibilityChanged, + onDialog = onDialog + ) + } } } }