mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 11:57:29 +01:00
Fixes the crash on images not being present in the image pager.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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,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,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user