diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/LoadUrlPreview.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/LoadUrlPreview.kt index 82441101c9..9710607e24 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/LoadUrlPreview.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/LoadUrlPreview.kt @@ -32,7 +32,6 @@ import androidx.compose.runtime.setValue import com.vitorpamplona.amethyst.model.UrlCachedPreviewer import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.theme.HalfVertPadding -import kotlinx.collections.immutable.persistentListOf @Composable fun LoadUrlPreview( @@ -68,19 +67,17 @@ fun LoadUrlPreview( if (state.previewInfo.mimeType.type == "image") { Box(modifier = HalfVertPadding) { ZoomableContentView( - ZoomableUrlImage(url), - persistentListOf(), + content = ZoomableUrlImage(url), roundedCorner = true, - accountViewModel, + accountViewModel = accountViewModel, ) } } else if (state.previewInfo.mimeType.type == "video") { Box(modifier = HalfVertPadding) { ZoomableContentView( - ZoomableUrlVideo(url), - persistentListOf(), + content = ZoomableUrlVideo(url), roundedCorner = true, - accountViewModel, + accountViewModel = accountViewModel, ) } } else { 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 c2c01f1470..50a308be7c 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 @@ -229,12 +229,12 @@ fun figureOutMimeType(fullUrl: String): ZoomableContent { @OptIn(ExperimentalFoundationApi::class) fun ZoomableContentView( content: ZoomableContent, - images: ImmutableList = listOf(content).toImmutableList(), + images: ImmutableList = remember(content) { listOf(content).toImmutableList() }, roundedCorner: Boolean, accountViewModel: AccountViewModel, ) { // store the dialog open or close state - var dialogOpen by remember { mutableStateOf(false) } + var dialogOpen by remember(content) { mutableStateOf(false) } // store the dialog open or close state val shareOpen = remember { mutableStateOf(false) } @@ -847,14 +847,16 @@ private fun DialogContent( SlidingCarousel( pagerState = pagerState, ) { index -> - RenderImageOrVideo( - content = allImages[index], - roundedCorner = false, - topPaddingForControllers = Size55dp, - onControllerVisibilityChanged = { controllerVisible.value = it }, - onToggleControllerVisibility = { controllerVisible.value = !controllerVisible.value }, - accountViewModel = accountViewModel, - ) + allImages.getOrNull(index)?.let { + RenderImageOrVideo( + content = it, + roundedCorner = false, + topPaddingForControllers = Size55dp, + onControllerVisibilityChanged = { controllerVisible.value = it }, + onToggleControllerVisibility = { controllerVisible.value = !controllerVisible.value }, + accountViewModel = accountViewModel, + ) + } } } else { RenderImageOrVideo( @@ -879,18 +881,19 @@ private fun DialogContent( ) { CloseButton(onPress = onDismiss) - val myContent = allImages[pagerState.currentPage] - if (myContent is ZoomableUrlContent) { - Row { - CopyToClipboard(content = myContent) - Spacer(modifier = StdHorzSpacer) - SaveToGallery(url = myContent.url) + allImages.getOrNull(pagerState.currentPage)?.let { myContent -> + if (myContent is ZoomableUrlContent) { + Row { + CopyToClipboard(content = myContent) + Spacer(modifier = StdHorzSpacer) + SaveToGallery(url = myContent.url) + } + } else if (myContent is ZoomableLocalImage && myContent.localFile != null) { + SaveToGallery( + localFile = myContent.localFile, + mimeType = myContent.mimeType, + ) } - } else if (myContent is ZoomableLocalImage && myContent.localFile != null) { - SaveToGallery( - localFile = myContent.localFile, - mimeType = myContent.mimeType, - ) } } }