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 { ): Boolean {
val noteEvent = it.event val noteEvent = it.event
return ( 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) && params.match(noteEvent) &&
account.isAcceptable(it) account.isAcceptable(it)

View File

@@ -175,21 +175,41 @@ fun GalleryCardCompose(
nav = nav, nav = nav,
) { canPreview -> ) { canPreview ->
(baseNote.event as ProfileGalleryEntryEvent).event()?.let { val galleryEvent = (baseNote.event as? ProfileGalleryEntryEvent) ?: return@CheckHiddenFeedWatchBlockAndReport
LoadNote(baseNoteHex = it, accountViewModel = accountViewModel) { note ->
note?.let { galleryEvent.url()?.let { image ->
(baseNote.event as ProfileGalleryEntryEvent).url()?.let { image -> val sourceEvent = galleryEvent.fromEvent()
GalleryCard(
if (sourceEvent != null) {
LoadNote(baseNoteHex = sourceEvent, accountViewModel = accountViewModel) { sourceNote ->
if (sourceNote != null) {
ClickableGalleryCard(
galleryNote = baseNote, galleryNote = baseNote,
baseNote = it, baseNote = sourceNote,
image = image, image = image,
modifier = modifier, modifier = modifier,
parentBackgroundColor = parentBackgroundColor, parentBackgroundColor = parentBackgroundColor,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, 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,
)
} }
} }
} }
@@ -197,7 +217,7 @@ fun GalleryCardCompose(
} }
@Composable @Composable
fun GalleryCard( fun ClickableGalleryCard(
galleryNote: Note, galleryNote: Note,
baseNote: Note, baseNote: Note,
image: String, image: String,
@@ -208,46 +228,38 @@ fun GalleryCard(
) { ) {
// baseNote.event?.let { Text(text = it.pubKey()) } // baseNote.event?.let { Text(text = it.pubKey()) }
LongPressToQuickActionGallery(baseNote = galleryNote, accountViewModel = accountViewModel) { showPopup -> LongPressToQuickActionGallery(baseNote = galleryNote, accountViewModel = accountViewModel) { showPopup ->
CheckNewAndRenderChannelCard( val backgroundColor =
baseNote, calculateBackgroundColor(
galleryNote, createdAt = baseNote.createdAt(),
image, parentBackgroundColor = parentBackgroundColor,
modifier, accountViewModel = accountViewModel,
parentBackgroundColor, )
accountViewModel,
showPopup, ClickableNote(
nav, baseNote = baseNote,
) backgroundColor = backgroundColor,
modifier = modifier,
accountViewModel = accountViewModel,
showPopup = showPopup,
nav = nav,
) {
InnerGalleryCardBox(galleryNote, image, accountViewModel, nav)
}
} }
} }
@Composable @Composable
private fun CheckNewAndRenderChannelCard( fun GalleryCard(
baseNote: Note,
galleryNote: Note, galleryNote: Note,
image: String, image: String,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
showPopup: () -> Unit,
nav: (String) -> Unit, nav: (String) -> Unit,
) { ) {
val backgroundColor = LongPressToQuickActionGallery(baseNote = galleryNote, accountViewModel = accountViewModel) { showPopup ->
calculateBackgroundColor( Column(modifier = modifier) {
createdAt = baseNote.createdAt(), InnerGalleryCardBox(galleryNote, image, accountViewModel, nav)
parentBackgroundColor = parentBackgroundColor, }
accountViewModel = accountViewModel,
)
ClickableNote(
baseNote = baseNote,
backgroundColor = backgroundColor,
modifier = modifier,
accountViewModel = accountViewModel,
showPopup = showPopup,
nav = nav,
) {
InnerGalleryCardBox(galleryNote, image, accountViewModel, nav)
} }
} }

View File

@@ -58,9 +58,9 @@ class ProfileGalleryEntryEvent(
fun hasUrl() = tags.any { it.size > 1 && it[0] == URL } 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]) } fun isOneOf(mimeTypes: Set<String>) = tags.any { it.size > 1 && it[0] == MIME_TYPE && mimeTypes.contains(it[1]) }