Чат, вложения
This commit is contained in:
@@ -11,6 +11,7 @@ import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Download
|
||||
import androidx.compose.material.icons.filled.InsertDriveFile
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
@@ -28,6 +29,9 @@ import coil.compose.AsyncImage
|
||||
import chats.domain.model.Media
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
@@ -36,6 +40,8 @@ fun AppMediaLightbox(
|
||||
initialIndex: Int = 0,
|
||||
onClose: () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val scope = rememberCoroutineScope()
|
||||
val pagerState = rememberPagerState(initialPage = initialIndex, pageCount = { mediaList.size })
|
||||
|
||||
Dialog(
|
||||
@@ -70,7 +76,7 @@ fun AppMediaLightbox(
|
||||
useController = true,
|
||||
autoPlay = isCurrentPage // Только если страница активна
|
||||
)
|
||||
} else {
|
||||
} else if (media.type.startsWith("image") || media.type.contains("gif")) {
|
||||
var scale by remember { mutableFloatStateOf(1f) }
|
||||
var offset by remember { mutableStateOf(androidx.compose.ui.geometry.Offset.Zero) }
|
||||
|
||||
@@ -88,6 +94,41 @@ fun AppMediaLightbox(
|
||||
),
|
||||
contentScale = ContentScale.Fit
|
||||
)
|
||||
} else {
|
||||
// Document / File placeholder in Lightbox
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize().padding(32.dp),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.InsertDriveFile,
|
||||
contentDescription = null,
|
||||
tint = Color.White,
|
||||
modifier = Modifier.size(100.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
Text(
|
||||
text = media.filename ?: "File",
|
||||
color = Color.White,
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
textAlign = androidx.compose.ui.text.style.TextAlign.Center
|
||||
)
|
||||
Spacer(modifier = Modifier.height(32.dp))
|
||||
Button(
|
||||
onClick = {
|
||||
try {
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(media.url))
|
||||
context.startActivity(intent)
|
||||
} catch (e: Exception) {
|
||||
// Handle error (no app to open)
|
||||
}
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(containerColor = Color.White, contentColor = Color.Black)
|
||||
) {
|
||||
Text("Открыть в приложении")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,7 +160,12 @@ fun AppMediaLightbox(
|
||||
}
|
||||
|
||||
IconButton(
|
||||
onClick = { /* Handle download of mediaList[pagerState.currentPage] */ },
|
||||
onClick = {
|
||||
val currentMedia = mediaList[pagerState.currentPage]
|
||||
scope.launch {
|
||||
core.utils.DownloadUtils.downloadMedia(context, currentMedia.url, currentMedia.filename)
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.clip(CircleShape)
|
||||
.background(Color.Black.copy(alpha = 0.5f))
|
||||
|
||||
Reference in New Issue
Block a user