Simplifies the drawing of gallery entires without e tags.

This commit is contained in:
Vitor Pamplona 2024-07-31 16:02:18 -04:00
parent 42ceb0c404
commit 3bbb780d2b
3 changed files with 52 additions and 40 deletions

View File

@ -65,7 +65,7 @@ class UserProfileGalleryFeedFilter(
): Boolean {
val noteEvent = it.event
return (
(it.event?.pubKey() == user.pubkeyHex && noteEvent is ProfileGalleryEntryEvent) && noteEvent.hasUrl() && noteEvent.hasEvent() // && noteEvent.isOneOf(SUPPORTED_VIDEO_FEED_MIME_TYPES_SET))
(it.event?.pubKey() == user.pubkeyHex && noteEvent is ProfileGalleryEntryEvent) && noteEvent.hasUrl() && noteEvent.hasFromEvent() // && noteEvent.isOneOf(SUPPORTED_VIDEO_FEED_MIME_TYPES_SET))
) &&
params.match(noteEvent) &&
account.isAcceptable(it)

View File

@ -175,29 +175,49 @@ fun GalleryCardCompose(
nav = nav,
) { canPreview ->
(baseNote.event as ProfileGalleryEntryEvent).event()?.let {
LoadNote(baseNoteHex = it, accountViewModel = accountViewModel) { note ->
note?.let {
(baseNote.event as ProfileGalleryEntryEvent).url()?.let { image ->
GalleryCard(
val galleryEvent = (baseNote.event as? ProfileGalleryEntryEvent) ?: return@CheckHiddenFeedWatchBlockAndReport
galleryEvent.url()?.let { image ->
val sourceEvent = galleryEvent.fromEvent()
if (sourceEvent != null) {
LoadNote(baseNoteHex = sourceEvent, accountViewModel = accountViewModel) { sourceNote ->
if (sourceNote != null) {
ClickableGalleryCard(
galleryNote = baseNote,
baseNote = it,
baseNote = sourceNote,
image = image,
modifier = modifier,
parentBackgroundColor = parentBackgroundColor,
accountViewModel = accountViewModel,
nav = nav,
)
} else {
GalleryCard(
galleryNote = baseNote,
image = image,
modifier = modifier,
accountViewModel = accountViewModel,
nav = nav,
)
}
}
} else {
GalleryCard(
galleryNote = baseNote,
image = image,
modifier = modifier,
accountViewModel = accountViewModel,
nav = nav,
)
}
}
}
}
}
}
}
@Composable
fun GalleryCard(
fun ClickableGalleryCard(
galleryNote: Note,
baseNote: Note,
image: String,
@ -208,30 +228,6 @@ fun GalleryCard(
) {
// baseNote.event?.let { Text(text = it.pubKey()) }
LongPressToQuickActionGallery(baseNote = galleryNote, accountViewModel = accountViewModel) { showPopup ->
CheckNewAndRenderChannelCard(
baseNote,
galleryNote,
image,
modifier,
parentBackgroundColor,
accountViewModel,
showPopup,
nav,
)
}
}
@Composable
private fun CheckNewAndRenderChannelCard(
baseNote: Note,
galleryNote: Note,
image: String,
modifier: Modifier = Modifier,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
showPopup: () -> Unit,
nav: (String) -> Unit,
) {
val backgroundColor =
calculateBackgroundColor(
createdAt = baseNote.createdAt(),
@ -250,6 +246,22 @@ private fun CheckNewAndRenderChannelCard(
InnerGalleryCardBox(galleryNote, image, accountViewModel, nav)
}
}
}
@Composable
fun GalleryCard(
galleryNote: Note,
image: String,
modifier: Modifier = Modifier,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
) {
LongPressToQuickActionGallery(baseNote = galleryNote, accountViewModel = accountViewModel) { showPopup ->
Column(modifier = modifier) {
InnerGalleryCardBox(galleryNote, image, accountViewModel, nav)
}
}
}
@Composable
fun InnerGalleryCardBox(

View File

@ -58,9 +58,9 @@ class ProfileGalleryEntryEvent(
fun hasUrl() = tags.any { it.size > 1 && it[0] == URL }
fun event() = tags.firstOrNull { it.size > 1 && it[0] == "e" }?.get(1)
fun fromEvent() = tags.firstOrNull { it.size > 1 && it[0] == "e" }?.get(1)
fun hasEvent() = tags.any { it.size > 1 && it[0] == "e" }
fun hasFromEvent() = tags.any { it.size > 1 && it[0] == "e" }
fun isOneOf(mimeTypes: Set<String>) = tags.any { it.size > 1 && it[0] == MIME_TYPE && mimeTypes.contains(it[1]) }