From a3257a365b72f969ef20f43de2be4fc035bf84fd Mon Sep 17 00:00:00 2001 From: Believethehype <1097224+believethehype@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:56:06 +0100 Subject: [PATCH 1/2] hybrid solution nip68 / nip93 it keeps the nip93 gallery as before, but also adds all nip68 media to the gallery --- .../vitorpamplona/amethyst/model/Account.kt | 1 + .../amethyst/ui/components/VideoView.kt | 2 + .../ui/components/ZoomableContentView.kt | 7 ++- .../ui/dal/UserProfileGalleryFeedFilter.kt | 4 +- .../screen/loggedIn/profile/ProfileGallery.kt | 51 +++++++++++++++---- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt index a5b2995d4..239a9b19e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt @@ -1962,6 +1962,7 @@ class Account( if (isImage) { PictureEvent.create( url = url, + msg = alt, mimeType = headerInfo.mimeType, hash = headerInfo.hash, size = headerInfo.size.toLong(), 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 fc6efef08..8d576829d 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 @@ -250,6 +250,7 @@ fun VideoView( onControllerVisibilityChanged: ((Boolean) -> Unit)? = null, accountViewModel: AccountViewModel, alwaysShowVideo: Boolean = false, + showControls: Boolean = true, ) { val defaultToStart by remember(videoUri) { mutableStateOf(DEFAULT_MUTED_SETTING.value) } @@ -337,6 +338,7 @@ fun VideoView( onControllerVisibilityChanged = onControllerVisibilityChanged, onDialog = onDialog, accountViewModel = accountViewModel, + showControls = showControls, ) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt index 45afda9c5..8394b3199 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt @@ -27,6 +27,7 @@ import androidx.compose.animation.fadeOut import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.size import androidx.compose.foundation.text.InlineTextContent @@ -222,7 +223,7 @@ fun GalleryContentView( } is MediaUrlVideo -> SensitivityWarning(content.contentWarning != null, accountViewModel) { - Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { + Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { VideoView( videoUri = content.url, mimeType = content.mimeType, @@ -230,11 +231,13 @@ fun GalleryContentView( artworkUri = content.artworkUri, borderModifier = MaterialTheme.colorScheme.videoGalleryModifier, authorName = content.authorName, - dimensions = content.dim, + dimensions = Dimension(1, 1), // fit video in 1:1 ratio blurhash = content.blurhash, isFiniteHeight = isFiniteHeight, nostrUriCallback = content.uri, accountViewModel = accountViewModel, + alwaysShowVideo = true, + showControls = false, ) } } 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 34693e20f..9d1cc1e5e 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 @@ -26,7 +26,9 @@ import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.quartz.events.MuteListEvent import com.vitorpamplona.quartz.events.PeopleListEvent +import com.vitorpamplona.quartz.events.PictureEvent import com.vitorpamplona.quartz.events.ProfileGalleryEntryEvent +import com.vitorpamplona.quartz.events.VideoEvent class UserProfileGalleryFeedFilter( val user: User, @@ -65,7 +67,7 @@ class UserProfileGalleryFeedFilter( ): Boolean { val noteEvent = it.event return ( - (it.event?.pubKey() == user.pubkeyHex && noteEvent is ProfileGalleryEntryEvent) && noteEvent.hasUrl() && noteEvent.hasFromEvent() // && noteEvent.isOneOf(SUPPORTED_VIDEO_FEED_MIME_TYPES_SET)) + (it.event?.pubKey() == user.pubkeyHex && (noteEvent is PictureEvent || noteEvent is VideoEvent || (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/profile/ProfileGallery.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/ProfileGallery.kt index 887a8d186..467bf96da 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 @@ -77,7 +77,10 @@ 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 @Composable fun RenderGalleryFeed( @@ -171,11 +174,22 @@ fun GalleryCardCompose( nav = nav, ) { canPreview -> - val galleryEvent = (baseNote.event as? ProfileGalleryEntryEvent) ?: return@CheckHiddenFeedWatchBlockAndReport + var galleryEvent = baseNote.event + var url = "" + var sourceEvent = galleryEvent?.id() - galleryEvent.url()?.let { image -> - val sourceEvent = galleryEvent.fromEvent() + 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 -> if (sourceEvent != null) { LoadNote(baseNoteHex = sourceEvent, accountViewModel = accountViewModel) { sourceNote -> if (sourceNote != null) { @@ -338,7 +352,31 @@ fun InnerRenderGalleryThumb( note: Note, accountViewModel: AccountViewModel, ) { - val noteEvent = note.event as? ProfileGalleryEntryEvent ?: return + 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 @@ -347,11 +385,6 @@ fun InnerRenderGalleryThumb( contentAlignment = BottomStart, ) { card.image?.let { - val blurHash = noteEvent.blurhash() - val description = noteEvent.content - // var hash = (note.event as ProfileGalleryEntryEvent).hash() - val dimensions = noteEvent.dimensions() - val mimeType = noteEvent.mimeType() var content: BaseMediaContent? = null if (isVideoUrl(it)) { From d2187995b8b04f96eae8805ccdbf28e15860afae Mon Sep 17 00:00:00 2001 From: Believethehype <1097224+believethehype@users.noreply.github.com> Date: Wed, 4 Dec 2024 18:06:33 +0100 Subject: [PATCH 2/2] Update strings.xml --- amethyst/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amethyst/src/main/res/values/strings.xml b/amethyst/src/main/res/values/strings.xml index f3c8d1614..938353738 100644 --- a/amethyst/src/main/res/values/strings.xml +++ b/amethyst/src/main/res/values/strings.xml @@ -285,7 +285,7 @@ Unfollow Follow Delete from Gallery - Remove this media from your Gallery, you can readd it later + Remove this media from your Gallery. Request Deletion Amethyst will request that your note be deleted from the relays you are currently connected to. There is no guarantee that your note will be permanently deleted from those relays, or from other relays where it may be stored. Block