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

View File

@ -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,35 +84,31 @@ 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 MediaUrlVideo(
} else if (isVideoUrl(url)) { url = url,
MediaUrlVideo( description = noteEvent.content,
url = url, hash = null,
description = noteEvent.content, blurhash = noteEvent.blurhash(),
hash = null, dim = noteEvent.dimensions(),
blurhash = noteEvent.blurhash(), uri = null,
dim = noteEvent.dimensions(), mimeType = noteEvent.mimeType(),
uri = null, )
mimeType = noteEvent.mimeType(), } else {
) MediaUrlImage(
} else { url = url,
MediaUrlImage( description = noteEvent.content,
url = url, hash = null, // We don't want to show the hash banner here
description = noteEvent.content, blurhash = noteEvent.blurhash(),
hash = null, // We don't want to show the hash banner here dim = noteEvent.dimensions(),
blurhash = noteEvent.blurhash(), uri = null,
dim = noteEvent.dimensions(), mimeType = noteEvent.mimeType(),
uri = null, )
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,18 +161,20 @@ 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 ->
is MediaUrlImage -> when (val content = contentList[contentIndex]) {
SensitivityWarning(content.contentWarning != null, accountViewModel) { is MediaUrlImage ->
UrlImageView(content, accountViewModel) SensitivityWarning(content.contentWarning != null, accountViewModel) {
} UrlImageView(content, accountViewModel)
is MediaUrlVideo -> }
SensitivityWarning(content.contentWarning != null, accountViewModel) { is MediaUrlVideo ->
UrlVideoView(content, accountViewModel) SensitivityWarning(content.contentWarning != null, accountViewModel) {
} UrlVideoView(content, accountViewModel)
}
}
} }
} }