From 3bbb780d2bacbe16a46206f4e468df59012568b5 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Wed, 31 Jul 2024 16:02:18 -0400 Subject: [PATCH] Simplifies the drawing of gallery entires without e tags. --- .../ui/dal/UserProfileGalleryFeedFilter.kt | 2 +- .../ui/screen/loggedIn/ProfileGallery.kt | 86 +++++++++++-------- .../quartz/events/ProfileGalleryEntryEvent.kt | 4 +- 3 files changed, 52 insertions(+), 40 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/UserProfileGalleryFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/UserProfileGalleryFeedFilter.kt index 9ee41fac6..9a595f277 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/UserProfileGalleryFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/UserProfileGalleryFeedFilter.kt @@ -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) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileGallery.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileGallery.kt index 1eb43142a..b72c6913e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileGallery.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileGallery.kt @@ -175,21 +175,41 @@ 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, + ) } } } @@ -197,7 +217,7 @@ fun GalleryCardCompose( } @Composable -fun GalleryCard( +fun ClickableGalleryCard( galleryNote: Note, baseNote: Note, image: String, @@ -208,46 +228,38 @@ fun GalleryCard( ) { // baseNote.event?.let { Text(text = it.pubKey()) } LongPressToQuickActionGallery(baseNote = galleryNote, accountViewModel = accountViewModel) { showPopup -> - CheckNewAndRenderChannelCard( - baseNote, - galleryNote, - image, - modifier, - parentBackgroundColor, - accountViewModel, - showPopup, - nav, - ) + val backgroundColor = + calculateBackgroundColor( + createdAt = baseNote.createdAt(), + parentBackgroundColor = parentBackgroundColor, + accountViewModel = accountViewModel, + ) + + ClickableNote( + baseNote = baseNote, + backgroundColor = backgroundColor, + modifier = modifier, + accountViewModel = accountViewModel, + showPopup = showPopup, + nav = nav, + ) { + InnerGalleryCardBox(galleryNote, image, accountViewModel, nav) + } } } @Composable -private fun CheckNewAndRenderChannelCard( - baseNote: Note, +fun GalleryCard( galleryNote: Note, image: String, modifier: Modifier = Modifier, - parentBackgroundColor: MutableState? = null, accountViewModel: AccountViewModel, - showPopup: () -> Unit, nav: (String) -> Unit, ) { - val backgroundColor = - calculateBackgroundColor( - createdAt = baseNote.createdAt(), - parentBackgroundColor = parentBackgroundColor, - accountViewModel = accountViewModel, - ) - - ClickableNote( - baseNote = baseNote, - backgroundColor = backgroundColor, - modifier = modifier, - accountViewModel = accountViewModel, - showPopup = showPopup, - nav = nav, - ) { - InnerGalleryCardBox(galleryNote, image, accountViewModel, nav) + LongPressToQuickActionGallery(baseNote = galleryNote, accountViewModel = accountViewModel) { showPopup -> + Column(modifier = modifier) { + InnerGalleryCardBox(galleryNote, image, accountViewModel, nav) + } } } diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/events/ProfileGalleryEntryEvent.kt b/quartz/src/main/java/com/vitorpamplona/quartz/events/ProfileGalleryEntryEvent.kt index 2ca7960cc..a46d5a613 100644 --- a/quartz/src/main/java/com/vitorpamplona/quartz/events/ProfileGalleryEntryEvent.kt +++ b/quartz/src/main/java/com/vitorpamplona/quartz/events/ProfileGalleryEntryEvent.kt @@ -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) = tags.any { it.size > 1 && it[0] == MIME_TYPE && mimeTypes.contains(it[1]) }