Fixes the crash on images not being present in the image pager.

This commit is contained in:
Vitor Pamplona
2024-02-20 16:51:18 -05:00
parent b70407f447
commit f4cee92702
2 changed files with 28 additions and 28 deletions

View File

@@ -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 {

View File

@@ -229,12 +229,12 @@ fun figureOutMimeType(fullUrl: String): ZoomableContent {
@OptIn(ExperimentalFoundationApi::class)
fun ZoomableContentView(
content: ZoomableContent,
images: ImmutableList<ZoomableContent> = listOf(content).toImmutableList(),
images: ImmutableList<ZoomableContent> = 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,8 +847,9 @@ private fun DialogContent(
SlidingCarousel(
pagerState = pagerState,
) { index ->
allImages.getOrNull(index)?.let {
RenderImageOrVideo(
content = allImages[index],
content = it,
roundedCorner = false,
topPaddingForControllers = Size55dp,
onControllerVisibilityChanged = { controllerVisible.value = it },
@@ -856,6 +857,7 @@ private fun DialogContent(
accountViewModel = accountViewModel,
)
}
}
} else {
RenderImageOrVideo(
content = imageUrl,
@@ -879,7 +881,7 @@ private fun DialogContent(
) {
CloseButton(onPress = onDismiss)
val myContent = allImages[pagerState.currentPage]
allImages.getOrNull(pagerState.currentPage)?.let { myContent ->
if (myContent is ZoomableUrlContent) {
Row {
CopyToClipboard(content = myContent)
@@ -895,6 +897,7 @@ private fun DialogContent(
}
}
}
}
@Composable
@OptIn(ExperimentalFoundationApi::class)