mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-20 18:51:12 +02:00
use GalleryContentView instead of
This commit is contained in:
@@ -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
|
@Composable
|
||||||
fun TwoSecondController(
|
fun TwoSecondController(
|
||||||
content: BaseMediaContent,
|
content: BaseMediaContent,
|
||||||
@@ -303,6 +367,7 @@ fun UrlImageView(
|
|||||||
isFiniteHeight: Boolean,
|
isFiniteHeight: Boolean,
|
||||||
controllerVisible: MutableState<Boolean>,
|
controllerVisible: MutableState<Boolean>,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
|
gallery: Boolean = false,
|
||||||
alwayShowImage: Boolean = false,
|
alwayShowImage: Boolean = false,
|
||||||
) {
|
) {
|
||||||
Box(contentAlignment = Alignment.Center) {
|
Box(contentAlignment = Alignment.Center) {
|
||||||
@@ -319,7 +384,14 @@ fun UrlImageView(
|
|||||||
SubcomposeAsyncImage(
|
SubcomposeAsyncImage(
|
||||||
model = content.url,
|
model = content.url,
|
||||||
contentDescription = content.description,
|
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,
|
modifier = mainImageModifier,
|
||||||
) {
|
) {
|
||||||
when (painter.state) {
|
when (painter.state) {
|
||||||
|
@@ -45,18 +45,19 @@ import androidx.compose.ui.Alignment.Companion.BottomStart
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.layout.ContentScale
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.lifecycle.distinctUntilChanged
|
import androidx.lifecycle.distinctUntilChanged
|
||||||
import androidx.lifecycle.map
|
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.commons.richtext.RichTextParser.Companion.isVideoUrl
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.ui.actions.CrossfadeIfEnabled
|
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.SensitivityWarning
|
||||||
import com.vitorpamplona.amethyst.ui.components.VideoView
|
|
||||||
import com.vitorpamplona.amethyst.ui.note.CheckHiddenFeedWatchBlockAndReport
|
import com.vitorpamplona.amethyst.ui.note.CheckHiddenFeedWatchBlockAndReport
|
||||||
import com.vitorpamplona.amethyst.ui.note.ClickableNote
|
import com.vitorpamplona.amethyst.ui.note.ClickableNote
|
||||||
import com.vitorpamplona.amethyst.ui.note.LongPressToQuickActionGallery
|
import com.vitorpamplona.amethyst.ui.note.LongPressToQuickActionGallery
|
||||||
@@ -332,27 +333,53 @@ fun InnerRenderGalleryThumb(
|
|||||||
contentAlignment = BottomStart,
|
contentAlignment = BottomStart,
|
||||||
) {
|
) {
|
||||||
card.image?.let {
|
card.image?.let {
|
||||||
if (isVideoUrl(it)) {
|
var blurHash: String? = null
|
||||||
VideoView(
|
if ((note.associatedNote?.event as ProfileGalleryEntryEvent).blurhash() != null) {
|
||||||
videoUri = it,
|
blurHash = (note.associatedNote?.event as ProfileGalleryEntryEvent).blurhash()
|
||||||
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 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) }
|
?: run { DisplayGalleryAuthorBanner(note) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user