Ответы, аудио, голосовые
This commit is contained in:
@@ -22,13 +22,19 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import coil.compose.AsyncImage
|
||||
import chats.domain.model.Media
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
|
||||
@OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun AppMediaLightbox(
|
||||
url: String,
|
||||
type: String = "image",
|
||||
mediaList: List<Media>,
|
||||
initialIndex: Int = 0,
|
||||
onClose: () -> Unit
|
||||
) {
|
||||
val pagerState = rememberPagerState(initialPage = initialIndex, pageCount = { mediaList.size })
|
||||
|
||||
Dialog(
|
||||
onDismissRequest = onClose,
|
||||
properties = DialogProperties(
|
||||
@@ -36,41 +42,61 @@ fun AppMediaLightbox(
|
||||
decorFitsSystemWindows = false
|
||||
)
|
||||
) {
|
||||
var scale by remember { mutableFloatStateOf(1f) }
|
||||
var offset by remember { mutableStateOf(androidx.compose.ui.geometry.Offset.Zero) }
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.Black)
|
||||
.pointerInput(Unit) {
|
||||
detectTransformGestures { _, pan, zoom, _ ->
|
||||
scale = (scale * zoom).coerceIn(1f, 5f)
|
||||
offset += pan
|
||||
) {
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
pageSpacing = 16.dp,
|
||||
beyondBoundsPageCount = 1
|
||||
) { page ->
|
||||
val media = mediaList[page]
|
||||
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
if (media.type.startsWith("video")) {
|
||||
AppVideoPlayer(
|
||||
url = media.url,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
useController = true,
|
||||
autoPlay = true
|
||||
)
|
||||
} else {
|
||||
var scale by remember { mutableFloatStateOf(1f) }
|
||||
var offset by remember { mutableStateOf(androidx.compose.ui.geometry.Offset.Zero) }
|
||||
|
||||
AsyncImage(
|
||||
model = media.url,
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.pointerInput(Unit) {
|
||||
detectTransformGestures(
|
||||
onGesture = { _, pan, zoom, _ ->
|
||||
scale = (scale * zoom).coerceIn(1f, 5f)
|
||||
if (scale > 1f) {
|
||||
offset += pan
|
||||
} else {
|
||||
offset = androidx.compose.ui.geometry.Offset.Zero
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
.graphicsLayer(
|
||||
scaleX = scale,
|
||||
scaleY = scale,
|
||||
translationX = offset.x,
|
||||
translationY = offset.y
|
||||
),
|
||||
contentScale = ContentScale.Fit
|
||||
)
|
||||
}
|
||||
}
|
||||
) {
|
||||
if (type == "video") {
|
||||
AppVideoPlayer(
|
||||
url = url,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
useController = true,
|
||||
autoPlay = true
|
||||
)
|
||||
} else {
|
||||
AsyncImage(
|
||||
model = url,
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.graphicsLayer(
|
||||
scaleX = scale,
|
||||
scaleY = scale,
|
||||
translationX = offset.x,
|
||||
translationY = offset.y
|
||||
),
|
||||
contentScale = ContentScale.Fit
|
||||
)
|
||||
}
|
||||
|
||||
// Top Bar
|
||||
@@ -91,8 +117,16 @@ fun AppMediaLightbox(
|
||||
Icon(Icons.Default.Close, contentDescription = null, tint = Color.White)
|
||||
}
|
||||
|
||||
if (mediaList.isNotEmpty()) {
|
||||
Text(
|
||||
text = "${pagerState.currentPage + 1} / ${mediaList.size}",
|
||||
color = Color.White,
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
}
|
||||
|
||||
IconButton(
|
||||
onClick = { /* Handle download */ },
|
||||
onClick = { /* Handle download of mediaList[pagerState.currentPage] */ },
|
||||
modifier = Modifier
|
||||
.clip(CircleShape)
|
||||
.background(Color.Black.copy(alpha = 0.5f))
|
||||
|
||||
Reference in New Issue
Block a user