From ceaeb8e0b9aa960fb558bd83a20c4d251cbf8555 Mon Sep 17 00:00:00 2001 From: Believethehype <1097224+believethehype@users.noreply.github.com> Date: Wed, 31 Jul 2024 11:24:05 +0200 Subject: [PATCH] use GalleryContentView instead of --- .../ui/components/ZoomableContentView.kt | 74 ++++++++++++++++++- .../ui/screen/loggedIn/ProfileGallery.kt | 71 ++++++++++++------ 2 files changed, 122 insertions(+), 23 deletions(-) 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 764680fb5..61bde3ef5 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 @@ -176,6 +176,70 @@ fun ZoomableContentView( } } +@Composable +fun GalleryContentView( + content: BaseMediaContent, + roundedCorner: Boolean, + isFiniteHeight: Boolean, + isFiniteWidth: Boolean, + accountViewModel: AccountViewModel, +) { + when (content) { + is MediaUrlImage -> + SensitivityWarning(content.contentWarning != null, accountViewModel) { + TwoSecondController(content) { controllerVisible -> + val mainImageModifier = Modifier.fillMaxWidth() + val loadedImageModifier = if (roundedCorner) MaterialTheme.colorScheme.imageModifier else Modifier.fillMaxWidth() + + UrlImageView(content, mainImageModifier, loadedImageModifier, isFiniteHeight, controllerVisible, accountViewModel = accountViewModel, gallery = true) + } + } + is MediaUrlVideo -> + SensitivityWarning(content.contentWarning != null, accountViewModel) { + Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { + VideoView( + videoUri = content.url, + mimeType = content.mimeType, + title = content.description, + artworkUri = content.artworkUri, + gallery = true, + authorName = content.authorName, + dimensions = content.dim, + blurhash = content.blurhash, + roundedCorner = roundedCorner, + isFiniteHeight = isFiniteHeight, + nostrUriCallback = content.uri, + accountViewModel = accountViewModel, + ) + } + } + is MediaLocalImage -> + TwoSecondController(content) { controllerVisible -> + val mainImageModifier = Modifier.fillMaxWidth() + val loadedImageModifier = if (roundedCorner) MaterialTheme.colorScheme.imageModifier else Modifier.fillMaxWidth() + + LocalImageView(content, mainImageModifier, loadedImageModifier, isFiniteHeight, controllerVisible, accountViewModel = accountViewModel) + } + is MediaLocalVideo -> + content.localFile?.let { + Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { + VideoView( + videoUri = it.toUri().toString(), + mimeType = content.mimeType, + title = content.description, + artworkUri = content.artworkUri, + authorName = content.authorName, + gallery = true, + roundedCorner = roundedCorner, + isFiniteHeight = isFiniteHeight, + nostrUriCallback = content.uri, + accountViewModel = accountViewModel, + ) + } + } + } +} + @Composable fun TwoSecondController( content: BaseMediaContent, @@ -303,6 +367,7 @@ fun UrlImageView( isFiniteHeight: Boolean, controllerVisible: MutableState, accountViewModel: AccountViewModel, + gallery: Boolean = false, alwayShowImage: Boolean = false, ) { Box(contentAlignment = Alignment.Center) { @@ -319,7 +384,14 @@ fun UrlImageView( SubcomposeAsyncImage( model = content.url, contentDescription = content.description, - contentScale = if (isFiniteHeight) ContentScale.Fit else ContentScale.FillWidth, + contentScale = + if (gallery) { + ContentScale.Crop + } else if (isFiniteHeight) { + ContentScale.Fit + } else { + ContentScale.FillWidth + }, modifier = mainImageModifier, ) { when (painter.state) { 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 fbf2af6a8..f35a46f32 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 @@ -45,18 +45,19 @@ import androidx.compose.ui.Alignment.Companion.BottomStart import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color -import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.distinctUntilChanged import androidx.lifecycle.map -import coil.compose.AsyncImage +import com.vitorpamplona.amethyst.commons.richtext.BaseMediaContent +import com.vitorpamplona.amethyst.commons.richtext.MediaUrlImage +import com.vitorpamplona.amethyst.commons.richtext.MediaUrlVideo import com.vitorpamplona.amethyst.commons.richtext.RichTextParser.Companion.isVideoUrl import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.ui.actions.CrossfadeIfEnabled +import com.vitorpamplona.amethyst.ui.components.GalleryContentView import com.vitorpamplona.amethyst.ui.components.SensitivityWarning -import com.vitorpamplona.amethyst.ui.components.VideoView import com.vitorpamplona.amethyst.ui.note.CheckHiddenFeedWatchBlockAndReport import com.vitorpamplona.amethyst.ui.note.ClickableNote import com.vitorpamplona.amethyst.ui.note.LongPressToQuickActionGallery @@ -332,27 +333,53 @@ fun InnerRenderGalleryThumb( contentAlignment = BottomStart, ) { card.image?.let { - if (isVideoUrl(it)) { - VideoView( - videoUri = it, - mimeType = null, - title = "", - authorName = note.author?.toBestDisplayName(), - roundedCorner = false, - gallery = true, - isFiniteHeight = false, - alwaysShowVideo = true, - accountViewModel = accountViewModel, - ) - } else { - AsyncImage( - model = it, - contentDescription = null, - contentScale = ContentScale.Crop, - modifier = Modifier.fillMaxSize(), - ) + var blurHash: String? = null + if ((note.associatedNote?.event as ProfileGalleryEntryEvent).blurhash() != null) { + blurHash = (note.associatedNote?.event as ProfileGalleryEntryEvent).blurhash() } + + var fullUrl = it + var description = (note.associatedNote?.event as ProfileGalleryEntryEvent).content + var hash = (note.associatedNote?.event as ProfileGalleryEntryEvent).hash() + var dimensions = (note.associatedNote?.event as ProfileGalleryEntryEvent).dimensions() + var mimeType = (note.associatedNote?.event as ProfileGalleryEntryEvent).mimeType() + + // var content = Im(null, "10x10", blurhash = blurhash) + var content: BaseMediaContent? = null + + if (isVideoUrl(it)) { + content = + MediaUrlVideo( + url = fullUrl, + description = description, + hash = null, + blurhash = blurHash, + dim = dimensions, + uri = null, + mimeType = mimeType, + ) + } else { + content = + MediaUrlImage( + url = fullUrl, + description = description, + hash = null, // We don't want to show the hash banner here + blurhash = blurHash, + dim = dimensions, + uri = null, + mimeType = mimeType, + ) + } + + GalleryContentView( + content = content, + roundedCorner = false, + isFiniteHeight = false, + isFiniteWidth = false, + accountViewModel = accountViewModel, + ) } + // } ?: run { DisplayGalleryAuthorBanner(note) } } }