Allowing multiple images on a single event to be displayed in the Profile gallery

This commit is contained in:
Vitor Pamplona
2025-01-03 10:11:10 -05:00
parent 4bfacbc11e
commit 5c0c1acc4a
@@ -53,6 +53,7 @@ import com.vitorpamplona.amethyst.commons.richtext.RichTextParser.Companion.isVi
import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.service.okhttp.HttpClientManager import com.vitorpamplona.amethyst.service.okhttp.HttpClientManager
import com.vitorpamplona.amethyst.ui.actions.CrossfadeIfEnabled import com.vitorpamplona.amethyst.ui.actions.CrossfadeIfEnabled
import com.vitorpamplona.amethyst.ui.components.AutoNonlazyGrid
import com.vitorpamplona.amethyst.ui.components.ClickableUrl import com.vitorpamplona.amethyst.ui.components.ClickableUrl
import com.vitorpamplona.amethyst.ui.components.DisplayBlurHash import com.vitorpamplona.amethyst.ui.components.DisplayBlurHash
import com.vitorpamplona.amethyst.ui.components.DisplayUrlWithLoadingSymbol import com.vitorpamplona.amethyst.ui.components.DisplayUrlWithLoadingSymbol
@@ -60,6 +61,7 @@ import com.vitorpamplona.amethyst.ui.components.GetMediaItem
import com.vitorpamplona.amethyst.ui.components.GetVideoController import com.vitorpamplona.amethyst.ui.components.GetVideoController
import com.vitorpamplona.amethyst.ui.components.ImageUrlWithDownloadButton import com.vitorpamplona.amethyst.ui.components.ImageUrlWithDownloadButton
import com.vitorpamplona.amethyst.ui.components.SensitivityWarning import com.vitorpamplona.amethyst.ui.components.SensitivityWarning
import com.vitorpamplona.amethyst.ui.components.UrlImageView
import com.vitorpamplona.amethyst.ui.navigation.INav import com.vitorpamplona.amethyst.ui.navigation.INav
import com.vitorpamplona.amethyst.ui.note.DownloadForOfflineIcon import com.vitorpamplona.amethyst.ui.note.DownloadForOfflineIcon
import com.vitorpamplona.amethyst.ui.note.WatchAuthor import com.vitorpamplona.amethyst.ui.note.WatchAuthor
@@ -82,10 +84,8 @@ fun GalleryThumbnail(
val content = val content =
if (noteEvent is ProfileGalleryEntryEvent) { if (noteEvent is ProfileGalleryEntryEvent) {
val url = noteEvent.url() noteEvent.urls().map { url ->
if (url == null) { if (isVideoUrl(url)) {
null
} else if (isVideoUrl(url)) {
MediaUrlVideo( MediaUrlVideo(
url = url, url = url,
description = noteEvent.content, description = noteEvent.content,
@@ -106,11 +106,9 @@ fun GalleryThumbnail(
mimeType = noteEvent.mimeType(), mimeType = noteEvent.mimeType(),
) )
} }
}
} else if (noteEvent is PictureEvent) { } else if (noteEvent is PictureEvent) {
val imeta = noteEvent.imetaTags().firstOrNull() noteEvent.imetaTags().map { imeta ->
if (imeta?.url == null) {
null
} else {
MediaUrlImage( MediaUrlImage(
url = imeta.url, url = imeta.url,
description = noteEvent.content, description = noteEvent.content,
@@ -122,11 +120,7 @@ fun GalleryThumbnail(
) )
} }
} else if (noteEvent is VideoEvent) { } else if (noteEvent is VideoEvent) {
val imeta = noteEvent.imetaTags().firstOrNull() noteEvent.imetaTags().map { imeta ->
if (imeta?.url == null) {
null
} else {
MediaUrlVideo( MediaUrlVideo(
url = imeta.url, url = imeta.url,
description = noteEvent.content, description = noteEvent.content,
@@ -138,7 +132,7 @@ fun GalleryThumbnail(
) )
} }
} else { } else {
null emptyList()
} }
InnerRenderGalleryThumb(content, baseNote, accountViewModel) InnerRenderGalleryThumb(content, baseNote, accountViewModel)
@@ -146,15 +140,12 @@ fun GalleryThumbnail(
@Composable @Composable
fun InnerRenderGalleryThumb( fun InnerRenderGalleryThumb(
content: MediaUrlContent?, content: List<MediaUrlContent>,
note: Note, note: Note,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
) { ) {
if (content != null) { if (content.isNotEmpty()) {
GalleryContentView( GalleryContentView(content, accountViewModel)
content = content,
accountViewModel = accountViewModel,
)
} else { } else {
DisplayGalleryAuthorBanner(note) DisplayGalleryAuthorBanner(note)
} }
@@ -170,10 +161,11 @@ fun DisplayGalleryAuthorBanner(note: Note) {
@androidx.annotation.OptIn(UnstableApi::class) @androidx.annotation.OptIn(UnstableApi::class)
@Composable @Composable
fun GalleryContentView( fun GalleryContentView(
content: MediaUrlContent, contentList: List<MediaUrlContent>,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
) { ) {
when (content) { AutoNonlazyGrid(contentList.size) { contentIndex ->
when (val content = contentList[contentIndex]) {
is MediaUrlImage -> is MediaUrlImage ->
SensitivityWarning(content.contentWarning != null, accountViewModel) { SensitivityWarning(content.contentWarning != null, accountViewModel) {
UrlImageView(content, accountViewModel) UrlImageView(content, accountViewModel)
@@ -183,6 +175,7 @@ fun GalleryContentView(
UrlVideoView(content, accountViewModel) UrlVideoView(content, accountViewModel)
} }
} }
}
} }
@Composable @Composable