From 0d6760360f00fcc2232ecf9412099622ea329e02 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 6 Dec 2024 10:19:55 -0500 Subject: [PATCH] Fixes the bugs from migrating video events to imeta tags --- .../amethyst/ui/components/VideoView.kt | 1 + .../screen/loggedIn/profile/ProfileGallery.kt | 163 ++++++++---------- .../quartz/events/PictureEvent.kt | 18 +- 3 files changed, 80 insertions(+), 102 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/VideoView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/VideoView.kt index 8d576829d..cd774e6eb 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/VideoView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/VideoView.kt @@ -752,6 +752,7 @@ private fun RenderVideoPlayer( modifier = videoModifier, factory = { context: Context -> PlayerView(context).apply { + clipToOutline = true player = controller layoutParams = FrameLayout.LayoutParams( diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/ProfileGallery.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/ProfileGallery.kt index 467bf96da..658790b9c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/ProfileGallery.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/ProfileGallery.kt @@ -33,7 +33,6 @@ import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyGridState import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.itemsIndexed -import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.runtime.Immutable @@ -49,7 +48,6 @@ import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.distinctUntilChanged import androidx.lifecycle.map -import com.vitorpamplona.amethyst.commons.richtext.BaseMediaContent import com.vitorpamplona.amethyst.commons.richtext.MediaUrlImage import com.vitorpamplona.amethyst.commons.richtext.MediaUrlVideo import com.vitorpamplona.amethyst.commons.richtext.RichTextParser.Companion.isVideoUrl @@ -73,11 +71,9 @@ import com.vitorpamplona.amethyst.ui.note.elements.BannerImage import com.vitorpamplona.amethyst.ui.screen.FeedViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.mockAccountViewModel -import com.vitorpamplona.amethyst.ui.theme.DividerThickness import com.vitorpamplona.amethyst.ui.theme.FeedPadding import com.vitorpamplona.amethyst.ui.theme.HalfPadding import com.vitorpamplona.amethyst.ui.theme.QuoteBorder -import com.vitorpamplona.quartz.events.Dimension import com.vitorpamplona.quartz.events.PictureEvent import com.vitorpamplona.quartz.events.ProfileGalleryEntryEvent import com.vitorpamplona.quartz.events.VideoEvent @@ -141,15 +137,11 @@ private fun GalleryFeedLoaded( GalleryCardCompose( baseNote = item, routeForLastRead = routeForLastRead, - modifier = Modifier, + modifier = HalfPadding, accountViewModel = accountViewModel, nav = nav, ) } - - HorizontalDivider( - thickness = DividerThickness, - ) } } } @@ -173,30 +165,22 @@ fun GalleryCardCompose( accountViewModel = accountViewModel, nav = nav, ) { canPreview -> + val (url, sourceEvent) = + when (val galleryEvent = baseNote.event) { + is ProfileGalleryEntryEvent -> Pair(galleryEvent.url(), galleryEvent.fromEvent()) + is PictureEvent -> Pair(galleryEvent.imetaTags().getOrNull(0)?.url, galleryEvent.id()) + is VideoEvent -> Pair(galleryEvent.imetaTags().getOrNull(0)?.url, galleryEvent.id()) + else -> Pair(null, null) + } - var galleryEvent = baseNote.event - var url = "" - var sourceEvent = galleryEvent?.id() - - if (baseNote.event is ProfileGalleryEntryEvent) { - url = (baseNote.event as ProfileGalleryEntryEvent).url().toString() - sourceEvent = (baseNote.event as? ProfileGalleryEntryEvent)?.fromEvent() - } else if (baseNote.event is PictureEvent) { - url = (baseNote.event as PictureEvent).imetaTags()[0].url - sourceEvent = (baseNote.event as PictureEvent).id() - } else if (baseNote.event is VideoEvent) { - url = (baseNote.event as VideoEvent).url().toString() - sourceEvent = (baseNote.event as VideoEvent).id() - } - - url.let { image -> + url?.let { imageUrl -> if (sourceEvent != null) { LoadNote(baseNoteHex = sourceEvent, accountViewModel = accountViewModel) { sourceNote -> if (sourceNote != null) { ClickableGalleryCard( galleryNote = baseNote, baseNote = sourceNote, - image = image, + image = imageUrl, modifier = modifier, parentBackgroundColor = parentBackgroundColor, accountViewModel = accountViewModel, @@ -205,7 +189,7 @@ fun GalleryCardCompose( } else { GalleryCard( galleryNote = baseNote, - image = image, + image = imageUrl, modifier = modifier, accountViewModel = accountViewModel, nav = nav, @@ -215,7 +199,7 @@ fun GalleryCardCompose( } else { GalleryCard( galleryNote = baseNote, - image = image, + image = imageUrl, modifier = modifier, accountViewModel = accountViewModel, nav = nav, @@ -280,13 +264,11 @@ fun InnerGalleryCardBox( accountViewModel: AccountViewModel, nav: INav, ) { - Column(HalfPadding) { - SensitivityWarning( - note = baseNote, - accountViewModel = accountViewModel, - ) { - RenderGalleryThumb(baseNote, image, accountViewModel, nav) - } + SensitivityWarning( + note = baseNote, + accountViewModel = accountViewModel, + ) { + RenderGalleryThumb(baseNote, image, accountViewModel, nav) } } @@ -352,74 +334,69 @@ fun InnerRenderGalleryThumb( note: Note, accountViewModel: AccountViewModel, ) { - var noteEvent = note.event - var blurHash = "" - var description = "" - var dimensions: Dimension? = null - var mimeType = "" - if (note.event is ProfileGalleryEntryEvent) { - noteEvent = (note.event as ProfileGalleryEntryEvent) - blurHash = noteEvent.blurhash().toString() - description = noteEvent.content - // var hash = (note.event as ProfileGalleryEntryEvent).hash() - dimensions = noteEvent.dimensions() - mimeType = noteEvent.mimeType().toString() - } else if (note.event is PictureEvent) { - noteEvent = (note.event as PictureEvent) - blurHash = noteEvent.blurhash().toString() - description = noteEvent.content - dimensions = noteEvent.dimensions() - mimeType = noteEvent.mimeType().toString() - } else if (note.event is VideoEvent) { - noteEvent = (note.event as VideoEvent) - blurHash = noteEvent.blurhash().toString() - description = noteEvent.content - dimensions = noteEvent.dimensions() - mimeType = noteEvent.mimeType().toString() - } - - Box( - Modifier - .fillMaxWidth() - .aspectRatio(1f), - contentAlignment = BottomStart, - ) { - card.image?.let { - var content: BaseMediaContent? = null - - if (isVideoUrl(it)) { - content = - MediaUrlVideo( - url = it, - description = description, - hash = null, - blurhash = blurHash, - dim = dimensions, - uri = null, - mimeType = mimeType, - ) + val noteEvent = note.event + val content = + if (card.image == null) { + null + } else if (noteEvent is ProfileGalleryEntryEvent) { + if (isVideoUrl(card.image)) { + MediaUrlVideo( + url = card.image, + description = noteEvent.content, + hash = null, + blurhash = noteEvent.blurhash(), + dim = noteEvent.dimensions(), + uri = null, + mimeType = noteEvent.mimeType(), + ) } else { - content = - MediaUrlImage( - url = it, - description = description, - hash = null, // We don't want to show the hash banner here - blurhash = blurHash, - dim = dimensions, - uri = null, - mimeType = mimeType, - ) + MediaUrlImage( + url = card.image, + description = noteEvent.content, + hash = null, // We don't want to show the hash banner here + blurhash = noteEvent.blurhash(), + dim = noteEvent.dimensions(), + uri = null, + mimeType = noteEvent.mimeType(), + ) } + } else if (noteEvent is PictureEvent) { + val imeta = noteEvent.imetaTags().firstOrNull() + MediaUrlImage( + url = card.image, + description = noteEvent.content, + hash = null, // We don't want to show the hash banner here + blurhash = imeta?.blurhash, + dim = imeta?.dimension, + uri = null, + mimeType = imeta?.mimeType, + ) + } else if (noteEvent is VideoEvent) { + val imeta = noteEvent.imetaTags().firstOrNull() + MediaUrlVideo( + url = card.image, + description = noteEvent.content, + hash = null, // We don't want to show the hash banner here + blurhash = imeta?.blurhash, + dim = imeta?.dimension, + uri = null, + mimeType = imeta?.mimeType, + ) + } else { + null + } + Box(Modifier.fillMaxWidth().aspectRatio(1f), BottomStart) { + if (content != null) { GalleryContentView( content = content, roundedCorner = false, isFiniteHeight = false, accountViewModel = accountViewModel, ) + } else { + DisplayGalleryAuthorBanner(note) } - // } - ?: run { DisplayGalleryAuthorBanner(note) } } } diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/events/PictureEvent.kt b/quartz/src/main/java/com/vitorpamplona/quartz/events/PictureEvent.kt index 75048d080..26651b879 100644 --- a/quartz/src/main/java/com/vitorpamplona/quartz/events/PictureEvent.kt +++ b/quartz/src/main/java/com/vitorpamplona/quartz/events/PictureEvent.kt @@ -46,23 +46,23 @@ class PictureEvent( fun title() = tags.firstOrNull { it.size > 1 && it[0] == TITLE }?.get(1) - fun url() = tags.firstOrNull { it.size > 1 && it[0] == PictureMeta.URL }?.get(1) + private fun url() = tags.firstOrNull { it.size > 1 && it[0] == PictureMeta.URL }?.get(1) - fun urls() = tags.filter { it.size > 1 && it[0] == PictureMeta.URL }.map { it[1] } + private fun urls() = tags.filter { it.size > 1 && it[0] == PictureMeta.URL }.map { it[1] } - fun mimeType() = tags.firstOrNull { it.size > 1 && it[0] == PictureMeta.MIME_TYPE }?.get(1) + private fun mimeType() = tags.firstOrNull { it.size > 1 && it[0] == PictureMeta.MIME_TYPE }?.get(1) - fun hash() = tags.firstOrNull { it.size > 1 && it[0] == PictureMeta.HASH }?.get(1) + private fun hash() = tags.firstOrNull { it.size > 1 && it[0] == PictureMeta.HASH }?.get(1) - fun size() = tags.firstOrNull { it.size > 1 && it[0] == PictureMeta.FILE_SIZE }?.get(1) + private fun size() = tags.firstOrNull { it.size > 1 && it[0] == PictureMeta.FILE_SIZE }?.get(1) - fun alt() = tags.firstOrNull { it.size > 1 && it[0] == PictureMeta.ALT }?.get(1) + private fun alt() = tags.firstOrNull { it.size > 1 && it[0] == PictureMeta.ALT }?.get(1) - fun dimensions() = tags.firstOrNull { it.size > 1 && it[0] == PictureMeta.DIMENSION }?.get(1)?.let { Dimension.parse(it) } + private fun dimensions() = tags.firstOrNull { it.size > 1 && it[0] == PictureMeta.DIMENSION }?.get(1)?.let { Dimension.parse(it) } - fun blurhash() = tags.firstOrNull { it.size > 1 && it[0] == PictureMeta.BLUR_HASH }?.get(1) + private fun blurhash() = tags.firstOrNull { it.size > 1 && it[0] == PictureMeta.BLUR_HASH }?.get(1) - fun hasUrl() = tags.any { it.size > 1 && it[0] == PictureMeta.URL } + private fun hasUrl() = tags.any { it.size > 1 && it[0] == PictureMeta.URL } // hack to fix pablo's bug fun rootImage() =