From 63888d55fd44abaac068604e8f24d8153d962f90 Mon Sep 17 00:00:00 2001 From: greenart7c3 <115044884+greenart7c3@users.noreply.github.com> Date: Thu, 13 Jul 2023 17:57:54 -0300 Subject: [PATCH 1/2] fix image loading in ZoomableImageDialog --- .../amethyst/ui/components/VideoView.kt | 31 ++++--- .../ui/components/ZoomableContentView.kt | 84 ++++++++++++++----- 2 files changed, 81 insertions(+), 34 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 7fb068148..b8ad68788 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 @@ -101,9 +101,9 @@ fun LoadThumbAndThenVideoView( if (loadingFinished.first) { if (loadingFinished.second != null) { - VideoView(videoUri, description, VideoThumb(loadingFinished.second), accountViewModel, onDialog) + VideoView(videoUri, description, VideoThumb(loadingFinished.second), accountViewModel, onDialog = onDialog) } else { - VideoView(videoUri, description, null, accountViewModel, onDialog) + VideoView(videoUri, description, null, accountViewModel, onDialog = onDialog) } } } @@ -115,10 +115,11 @@ fun VideoView( description: String? = null, thumb: VideoThumb? = null, accountViewModel: AccountViewModel, + alwaysShowVideo: Boolean = false, onDialog: ((Boolean) -> Unit)? = null ) { val (value, elapsed) = measureTimedValue { - VideoView1(videoUri, description, thumb, onDialog, accountViewModel) + VideoView1(videoUri, description, thumb, onDialog, accountViewModel, alwaysShowVideo) } Log.d("Rendering Metrics", "VideoView $elapsed $videoUri") } @@ -129,7 +130,8 @@ fun VideoView1( description: String? = null, thumb: VideoThumb? = null, onDialog: ((Boolean) -> Unit)? = null, - accountViewModel: AccountViewModel + accountViewModel: AccountViewModel, + alwaysShowVideo: Boolean = false, ) { var exoPlayerData by remember { mutableStateOf(null) } val defaultToStart by remember { mutableStateOf(DefaultMutedSetting.value) } @@ -144,7 +146,7 @@ fun VideoView1( } exoPlayerData?.let { - VideoView(videoUri, description, it, defaultToStart, thumb, onDialog, accountViewModel) + VideoView(videoUri, description, it, defaultToStart, thumb, onDialog, accountViewModel, alwaysShowVideo) } DisposableEffect(Unit) { @@ -163,10 +165,11 @@ fun VideoView( defaultToStart: Boolean = false, thumb: VideoThumb? = null, onDialog: ((Boolean) -> Unit)? = null, - accountViewModel: AccountViewModel + accountViewModel: AccountViewModel, + alwaysShowVideo: Boolean = false, ) { val (_, elapsed) = measureTimedValue { - VideoView1(videoUri, description, exoPlayerData, defaultToStart, thumb, onDialog, accountViewModel) + VideoView1(videoUri, description, exoPlayerData, defaultToStart, thumb, onDialog, accountViewModel, alwaysShowVideo) } Log.d("Rendering Metrics", "VideoView $elapsed $videoUri") } @@ -179,7 +182,8 @@ fun VideoView1( defaultToStart: Boolean = false, thumb: VideoThumb? = null, onDialog: ((Boolean) -> Unit)? = null, - accountViewModel: AccountViewModel + accountViewModel: AccountViewModel, + alwaysShowVideo: Boolean = false, ) { val lifecycleOwner = rememberUpdatedState(LocalLifecycleOwner.current) @@ -190,11 +194,12 @@ fun VideoView1( val automaticallyStartPlayback = remember { mutableStateOf( - when (settings.automaticallyStartPlayback) { - true -> !isMobile - false -> false - else -> true - } + if (alwaysShowVideo) true else + when (settings.automaticallyStartPlayback) { + true -> !isMobile + false -> false + else -> true + } ) } 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 21affa985..61a612608 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 @@ -201,11 +201,20 @@ fun ZoomableContentView( when (content) { is ZoomableUrlImage -> UrlImageView(content, mainImageModifier, accountViewModel) - is ZoomableUrlVideo -> VideoView(content.url, content.description, accountViewModel = accountViewModel) { dialogOpen = true } + is ZoomableUrlVideo -> VideoView( + content.url, + content.description, + accountViewModel = accountViewModel + ) { dialogOpen = true } + is ZoomableLocalImage -> LocalImageView(content, mainImageModifier, accountViewModel) is ZoomableLocalVideo -> content.localFile?.let { - VideoView(it.toUri().toString(), content.description, accountViewModel = accountViewModel) { dialogOpen = true } + VideoView( + it.toUri().toString(), + content.description, + accountViewModel = accountViewModel + ) { dialogOpen = true } } } @@ -218,7 +227,8 @@ fun ZoomableContentView( private fun LocalImageView( content: ZoomableLocalImage, mainImageModifier: Modifier, - accountViewModel: AccountViewModel? + accountViewModel: AccountViewModel?, + alwayShowImage: Boolean = false ) { if (content.localFile != null && content.localFile.exists()) { BoxWithConstraints(contentAlignment = Alignment.Center) { @@ -227,10 +237,12 @@ private fun LocalImageView( val showImage = remember { mutableStateOf( - when (settings?.automaticallyShowImages) { - true -> !isMobile - false -> false - else -> true + if (alwayShowImage) { true } else { + when (settings?.automaticallyShowImages) { + true -> !isMobile + false -> false + else -> true + } } ) } @@ -268,7 +280,14 @@ private fun LocalImageView( ) } - AddedImageFeatures(painterState, content, contentScale, myModifier, verifierModifier, showImage) + AddedImageFeatures( + painterState, + content, + contentScale, + myModifier, + verifierModifier, + showImage + ) } } else { BlankNote() @@ -279,7 +298,8 @@ private fun LocalImageView( private fun UrlImageView( content: ZoomableUrlImage, mainImageModifier: Modifier, - accountViewModel: AccountViewModel? + accountViewModel: AccountViewModel?, + alwayShowImage: Boolean = false ) { BoxWithConstraints(contentAlignment = Alignment.Center) { val settings = accountViewModel?.account?.settings @@ -287,10 +307,12 @@ private fun UrlImageView( val showImage = remember { mutableStateOf( - when (settings?.automaticallyShowImages) { - true -> !isMobile - false -> false - else -> true + if (alwayShowImage) { true } else { + when (settings?.automaticallyShowImages) { + true -> !isMobile + false -> false + else -> true + } } ) } @@ -328,7 +350,14 @@ private fun UrlImageView( ) } - AddedImageFeatures(painterState, content, contentScale, myModifier, verifierModifier, showImage) + AddedImageFeatures( + painterState, + content, + contentScale, + myModifier, + verifierModifier, + showImage + ) } } @@ -540,7 +569,12 @@ private fun DisplayBlurHash( @OptIn(ExperimentalFoundationApi::class) @Composable -fun ZoomableImageDialog(imageUrl: ZoomableContent, allImages: ImmutableList = listOf(imageUrl).toImmutableList(), onDismiss: () -> Unit, accountViewModel: AccountViewModel) { +fun ZoomableImageDialog( + imageUrl: ZoomableContent, + allImages: ImmutableList = listOf(imageUrl).toImmutableList(), + onDismiss: () -> Unit, + accountViewModel: AccountViewModel +) { val view = LocalView.current DisposableEffect(key1 = Unit) { @@ -602,7 +636,10 @@ fun ZoomableImageDialog(imageUrl: ZoomableContent, allImages: ImmutableList Date: Thu, 13 Jul 2023 18:07:57 -0300 Subject: [PATCH 2/2] show videos as links --- .../amethyst/ui/components/VideoView.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 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 b8ad68788..1cb447507 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 @@ -131,7 +131,7 @@ fun VideoView1( thumb: VideoThumb? = null, onDialog: ((Boolean) -> Unit)? = null, accountViewModel: AccountViewModel, - alwaysShowVideo: Boolean = false, + alwaysShowVideo: Boolean = false ) { var exoPlayerData by remember { mutableStateOf(null) } val defaultToStart by remember { mutableStateOf(DefaultMutedSetting.value) } @@ -166,7 +166,7 @@ fun VideoView( thumb: VideoThumb? = null, onDialog: ((Boolean) -> Unit)? = null, accountViewModel: AccountViewModel, - alwaysShowVideo: Boolean = false, + alwaysShowVideo: Boolean = false ) { val (_, elapsed) = measureTimedValue { VideoView1(videoUri, description, exoPlayerData, defaultToStart, thumb, onDialog, accountViewModel, alwaysShowVideo) @@ -183,7 +183,7 @@ fun VideoView1( thumb: VideoThumb? = null, onDialog: ((Boolean) -> Unit)? = null, accountViewModel: AccountViewModel, - alwaysShowVideo: Boolean = false, + alwaysShowVideo: Boolean = false ) { val lifecycleOwner = rememberUpdatedState(LocalLifecycleOwner.current) @@ -194,12 +194,13 @@ fun VideoView1( val automaticallyStartPlayback = remember { mutableStateOf( - if (alwaysShowVideo) true else + if (alwaysShowVideo) { true } else { when (settings.automaticallyStartPlayback) { true -> !isMobile false -> false else -> true } + } ) } @@ -227,7 +228,11 @@ fun VideoView1( prepare() } - RenderVideoPlayer(exoPlayerData, thumb, automaticallyStartPlayback, onDialog) + if (!automaticallyStartPlayback.value) { + ImageUrlWithDownloadButton(url = videoUri, showImage = automaticallyStartPlayback) + } else { + RenderVideoPlayer(exoPlayerData, thumb, automaticallyStartPlayback, onDialog) + } DisposableEffect(Unit) { val observer = LifecycleEventObserver { _, event ->