Videos now go full screen.

This commit is contained in:
Vitor Pamplona
2023-03-25 16:51:37 -04:00
parent 7e89822cbf
commit 4a77d8b134
3 changed files with 54 additions and 41 deletions
@@ -141,6 +141,9 @@ fun RichTextViewer(
if (imageExtension.matcher(removedParamsFromUrl).matches()) { if (imageExtension.matcher(removedParamsFromUrl).matches()) {
imagesForPager.add(word) imagesForPager.add(word)
} }
if (videoExtension.matcher(removedParamsFromUrl).matches()) {
imagesForPager.add(word)
}
} }
} }
} }
@@ -160,7 +163,7 @@ fun RichTextViewer(
if (imageExtension.matcher(removedParamsFromUrl).matches()) { if (imageExtension.matcher(removedParamsFromUrl).matches()) {
ZoomableImageView(word, imagesForPager) ZoomableImageView(word, imagesForPager)
} else if (videoExtension.matcher(removedParamsFromUrl).matches()) { } else if (videoExtension.matcher(removedParamsFromUrl).matches()) {
VideoView(word) ZoomableImageView(word, imagesForPager)
} else { } else {
UrlPreview(word, "$word ") UrlPreview(word, "$word ")
} }
@@ -19,7 +19,7 @@ import com.google.android.exoplayer2.ui.StyledPlayerView
import com.vitorpamplona.amethyst.VideoCache import com.vitorpamplona.amethyst.VideoCache
@Composable @Composable
fun VideoView(videoUri: String) { fun VideoView(videoUri: String, onDialog: ((Boolean) -> Unit)? = null) {
val context = LocalContext.current val context = LocalContext.current
val exoPlayer = remember { val exoPlayer = remember {
@@ -49,6 +49,11 @@ fun VideoView(videoUri: String) {
ViewGroup.LayoutParams.WRAP_CONTENT ViewGroup.LayoutParams.WRAP_CONTENT
) )
resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIXED_WIDTH resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIXED_WIDTH
onDialog?.let { innerOnDialog ->
setFullscreenButtonClickListener {
innerOnDialog(it)
}
}
} }
} }
) )
@@ -46,6 +46,7 @@ fun ZoomableImageView(word: String, images: List<String> = listOf(word)) {
mutableStateOf(false) mutableStateOf(false)
} }
if (imageExtension.matcher(word).matches()) {
AsyncImage( AsyncImage(
model = word, model = word,
contentDescription = word, contentDescription = word,
@@ -64,6 +65,9 @@ fun ZoomableImageView(word: String, images: List<String> = listOf(word)) {
onLongClick = { clipboardManager.setText(AnnotatedString(word)) } onLongClick = { clipboardManager.setText(AnnotatedString(word)) }
) )
) )
} else {
VideoView(word) { dialogOpen = true }
}
if (dialogOpen) { if (dialogOpen) {
ZoomableImageDialog(word, images, onDismiss = { dialogOpen = false }) ZoomableImageDialog(word, images, onDismiss = { dialogOpen = false })
@@ -78,14 +82,11 @@ fun ZoomableImageDialog(imageUrl: String, allImages: List<String> = listOf(image
properties = DialogProperties(usePlatformDefaultWidth = false) properties = DialogProperties(usePlatformDefaultWidth = false)
) { ) {
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colors.background) { Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colors.background) {
Column( Column() {
modifier = Modifier.padding(10.dp)
) {
var pagerState: PagerState = remember { PagerState() } var pagerState: PagerState = remember { PagerState() }
Row( Row(
modifier = Modifier modifier = Modifier.padding(10.dp).fillMaxWidth(),
.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
@@ -99,17 +100,20 @@ fun ZoomableImageDialog(imageUrl: String, allImages: List<String> = listOf(image
pagerState = pagerState, pagerState = pagerState,
itemsCount = allImages.size, itemsCount = allImages.size,
itemContent = { index -> itemContent = { index ->
AsyncImage( RenderImageOrVideo(allImages[index])
model = allImages[index],
contentDescription = stringResource(id = R.string.profile_image),
contentScale = ContentScale.FillWidth,
modifier = Modifier
.fillMaxSize()
.zoomable(rememberZoomState())
)
} }
) )
} else { } else {
RenderImageOrVideo(imageUrl)
}
}
}
}
}
@Composable
private fun RenderImageOrVideo(imageUrl: String) {
if (imageExtension.matcher(imageUrl).matches()) {
AsyncImage( AsyncImage(
model = imageUrl, model = imageUrl,
contentDescription = stringResource(id = R.string.profile_image), contentDescription = stringResource(id = R.string.profile_image),
@@ -118,8 +122,9 @@ fun ZoomableImageDialog(imageUrl: String, allImages: List<String> = listOf(image
.fillMaxSize() .fillMaxSize()
.zoomable(rememberZoomState()) .zoomable(rememberZoomState())
) )
} } else {
} Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxSize(1f)) {
VideoView(imageUrl)
} }
} }
} }