Fixes the bugs from migrating video events to imeta tags

This commit is contained in:
Vitor Pamplona
2024-12-06 10:19:55 -05:00
parent 4610519bb3
commit 0d6760360f
3 changed files with 80 additions and 102 deletions
@@ -752,6 +752,7 @@ private fun RenderVideoPlayer(
modifier = videoModifier, modifier = videoModifier,
factory = { context: Context -> factory = { context: Context ->
PlayerView(context).apply { PlayerView(context).apply {
clipToOutline = true
player = controller player = controller
layoutParams = layoutParams =
FrameLayout.LayoutParams( FrameLayout.LayoutParams(
@@ -33,7 +33,6 @@ import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyGridState import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.itemsIndexed import androidx.compose.foundation.lazy.grid.itemsIndexed
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable import androidx.compose.runtime.Immutable
@@ -49,7 +48,6 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.distinctUntilChanged import androidx.lifecycle.distinctUntilChanged
import androidx.lifecycle.map import androidx.lifecycle.map
import com.vitorpamplona.amethyst.commons.richtext.BaseMediaContent
import com.vitorpamplona.amethyst.commons.richtext.MediaUrlImage import com.vitorpamplona.amethyst.commons.richtext.MediaUrlImage
import com.vitorpamplona.amethyst.commons.richtext.MediaUrlVideo import com.vitorpamplona.amethyst.commons.richtext.MediaUrlVideo
import com.vitorpamplona.amethyst.commons.richtext.RichTextParser.Companion.isVideoUrl 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.FeedViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.mockAccountViewModel 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.FeedPadding
import com.vitorpamplona.amethyst.ui.theme.HalfPadding import com.vitorpamplona.amethyst.ui.theme.HalfPadding
import com.vitorpamplona.amethyst.ui.theme.QuoteBorder import com.vitorpamplona.amethyst.ui.theme.QuoteBorder
import com.vitorpamplona.quartz.events.Dimension
import com.vitorpamplona.quartz.events.PictureEvent import com.vitorpamplona.quartz.events.PictureEvent
import com.vitorpamplona.quartz.events.ProfileGalleryEntryEvent import com.vitorpamplona.quartz.events.ProfileGalleryEntryEvent
import com.vitorpamplona.quartz.events.VideoEvent import com.vitorpamplona.quartz.events.VideoEvent
@@ -141,15 +137,11 @@ private fun GalleryFeedLoaded(
GalleryCardCompose( GalleryCardCompose(
baseNote = item, baseNote = item,
routeForLastRead = routeForLastRead, routeForLastRead = routeForLastRead,
modifier = Modifier, modifier = HalfPadding,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
} }
HorizontalDivider(
thickness = DividerThickness,
)
} }
} }
} }
@@ -173,30 +165,22 @@ fun GalleryCardCompose(
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) { canPreview -> ) { canPreview ->
val (url, sourceEvent) =
var galleryEvent = baseNote.event when (val galleryEvent = baseNote.event) {
var url = "" is ProfileGalleryEntryEvent -> Pair(galleryEvent.url(), galleryEvent.fromEvent())
var sourceEvent = galleryEvent?.id() is PictureEvent -> Pair(galleryEvent.imetaTags().getOrNull(0)?.url, galleryEvent.id())
is VideoEvent -> Pair(galleryEvent.imetaTags().getOrNull(0)?.url, galleryEvent.id())
if (baseNote.event is ProfileGalleryEntryEvent) { else -> Pair(null, null)
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) { if (sourceEvent != null) {
LoadNote(baseNoteHex = sourceEvent, accountViewModel = accountViewModel) { sourceNote -> LoadNote(baseNoteHex = sourceEvent, accountViewModel = accountViewModel) { sourceNote ->
if (sourceNote != null) { if (sourceNote != null) {
ClickableGalleryCard( ClickableGalleryCard(
galleryNote = baseNote, galleryNote = baseNote,
baseNote = sourceNote, baseNote = sourceNote,
image = image, image = imageUrl,
modifier = modifier, modifier = modifier,
parentBackgroundColor = parentBackgroundColor, parentBackgroundColor = parentBackgroundColor,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
@@ -205,7 +189,7 @@ fun GalleryCardCompose(
} else { } else {
GalleryCard( GalleryCard(
galleryNote = baseNote, galleryNote = baseNote,
image = image, image = imageUrl,
modifier = modifier, modifier = modifier,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
@@ -215,7 +199,7 @@ fun GalleryCardCompose(
} else { } else {
GalleryCard( GalleryCard(
galleryNote = baseNote, galleryNote = baseNote,
image = image, image = imageUrl,
modifier = modifier, modifier = modifier,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
@@ -280,14 +264,12 @@ fun InnerGalleryCardBox(
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: INav, nav: INav,
) { ) {
Column(HalfPadding) {
SensitivityWarning( SensitivityWarning(
note = baseNote, note = baseNote,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
) { ) {
RenderGalleryThumb(baseNote, image, accountViewModel, nav) RenderGalleryThumb(baseNote, image, accountViewModel, nav)
} }
}
} }
@Immutable @Immutable
@@ -352,74 +334,69 @@ fun InnerRenderGalleryThumb(
note: Note, note: Note,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
) { ) {
var noteEvent = note.event val noteEvent = note.event
var blurHash = "" val content =
var description = "" if (card.image == null) {
var dimensions: Dimension? = null null
var mimeType = "" } else if (noteEvent is ProfileGalleryEntryEvent) {
if (note.event is ProfileGalleryEntryEvent) { if (isVideoUrl(card.image)) {
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( MediaUrlVideo(
url = it, url = card.image,
description = description, description = noteEvent.content,
hash = null, hash = null,
blurhash = blurHash, blurhash = noteEvent.blurhash(),
dim = dimensions, dim = noteEvent.dimensions(),
uri = null, uri = null,
mimeType = mimeType, mimeType = noteEvent.mimeType(),
) )
} else { } else {
content =
MediaUrlImage( MediaUrlImage(
url = it, url = card.image,
description = description, description = noteEvent.content,
hash = null, // We don't want to show the hash banner here hash = null, // We don't want to show the hash banner here
blurhash = blurHash, blurhash = noteEvent.blurhash(),
dim = dimensions, dim = noteEvent.dimensions(),
uri = null, uri = null,
mimeType = mimeType, 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( GalleryContentView(
content = content, content = content,
roundedCorner = false, roundedCorner = false,
isFiniteHeight = false, isFiniteHeight = false,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
) )
} else {
DisplayGalleryAuthorBanner(note)
} }
// }
?: run { DisplayGalleryAuthorBanner(note) }
} }
} }
@@ -46,23 +46,23 @@ class PictureEvent(
fun title() = tags.firstOrNull { it.size > 1 && it[0] == TITLE }?.get(1) 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 // hack to fix pablo's bug
fun rootImage() = fun rootImage() =