mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 20:36:45 +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.model.UrlCachedPreviewer
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.theme.HalfVertPadding
|
import com.vitorpamplona.amethyst.ui.theme.HalfVertPadding
|
||||||
import kotlinx.collections.immutable.persistentListOf
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LoadUrlPreview(
|
fun LoadUrlPreview(
|
||||||
@@ -68,19 +67,17 @@ fun LoadUrlPreview(
|
|||||||
if (state.previewInfo.mimeType.type == "image") {
|
if (state.previewInfo.mimeType.type == "image") {
|
||||||
Box(modifier = HalfVertPadding) {
|
Box(modifier = HalfVertPadding) {
|
||||||
ZoomableContentView(
|
ZoomableContentView(
|
||||||
ZoomableUrlImage(url),
|
content = ZoomableUrlImage(url),
|
||||||
persistentListOf(),
|
|
||||||
roundedCorner = true,
|
roundedCorner = true,
|
||||||
accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (state.previewInfo.mimeType.type == "video") {
|
} else if (state.previewInfo.mimeType.type == "video") {
|
||||||
Box(modifier = HalfVertPadding) {
|
Box(modifier = HalfVertPadding) {
|
||||||
ZoomableContentView(
|
ZoomableContentView(
|
||||||
ZoomableUrlVideo(url),
|
content = ZoomableUrlVideo(url),
|
||||||
persistentListOf(),
|
|
||||||
roundedCorner = true,
|
roundedCorner = true,
|
||||||
accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -229,12 +229,12 @@ fun figureOutMimeType(fullUrl: String): ZoomableContent {
|
|||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
fun ZoomableContentView(
|
fun ZoomableContentView(
|
||||||
content: ZoomableContent,
|
content: ZoomableContent,
|
||||||
images: ImmutableList<ZoomableContent> = listOf(content).toImmutableList(),
|
images: ImmutableList<ZoomableContent> = remember(content) { listOf(content).toImmutableList() },
|
||||||
roundedCorner: Boolean,
|
roundedCorner: Boolean,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
) {
|
) {
|
||||||
// store the dialog open or close state
|
// 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
|
// store the dialog open or close state
|
||||||
val shareOpen = remember { mutableStateOf(false) }
|
val shareOpen = remember { mutableStateOf(false) }
|
||||||
@@ -847,14 +847,16 @@ private fun DialogContent(
|
|||||||
SlidingCarousel(
|
SlidingCarousel(
|
||||||
pagerState = pagerState,
|
pagerState = pagerState,
|
||||||
) { index ->
|
) { index ->
|
||||||
RenderImageOrVideo(
|
allImages.getOrNull(index)?.let {
|
||||||
content = allImages[index],
|
RenderImageOrVideo(
|
||||||
roundedCorner = false,
|
content = it,
|
||||||
topPaddingForControllers = Size55dp,
|
roundedCorner = false,
|
||||||
onControllerVisibilityChanged = { controllerVisible.value = it },
|
topPaddingForControllers = Size55dp,
|
||||||
onToggleControllerVisibility = { controllerVisible.value = !controllerVisible.value },
|
onControllerVisibilityChanged = { controllerVisible.value = it },
|
||||||
accountViewModel = accountViewModel,
|
onToggleControllerVisibility = { controllerVisible.value = !controllerVisible.value },
|
||||||
)
|
accountViewModel = accountViewModel,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
RenderImageOrVideo(
|
RenderImageOrVideo(
|
||||||
@@ -879,18 +881,19 @@ private fun DialogContent(
|
|||||||
) {
|
) {
|
||||||
CloseButton(onPress = onDismiss)
|
CloseButton(onPress = onDismiss)
|
||||||
|
|
||||||
val myContent = allImages[pagerState.currentPage]
|
allImages.getOrNull(pagerState.currentPage)?.let { myContent ->
|
||||||
if (myContent is ZoomableUrlContent) {
|
if (myContent is ZoomableUrlContent) {
|
||||||
Row {
|
Row {
|
||||||
CopyToClipboard(content = myContent)
|
CopyToClipboard(content = myContent)
|
||||||
Spacer(modifier = StdHorzSpacer)
|
Spacer(modifier = StdHorzSpacer)
|
||||||
SaveToGallery(url = myContent.url)
|
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