|
@@ -2,7 +2,6 @@ package io.nexilis.alpha.ui.components
|
|
|
|
|
|
import android.content.Intent
|
|
import android.content.Intent
|
|
import android.graphics.BitmapFactory
|
|
import android.graphics.BitmapFactory
|
|
-import android.net.Uri
|
|
|
|
import androidx.compose.foundation.Image
|
|
import androidx.compose.foundation.Image
|
|
import androidx.compose.foundation.background
|
|
import androidx.compose.foundation.background
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.Column
|
|
@@ -15,12 +14,10 @@ import androidx.compose.foundation.layout.widthIn
|
|
import androidx.compose.foundation.selection.selectable
|
|
import androidx.compose.foundation.selection.selectable
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
import androidx.compose.material.icons.Icons
|
|
import androidx.compose.material.icons.Icons
|
|
-import androidx.compose.material.icons.filled.DownloadForOffline
|
|
|
|
import androidx.compose.material.icons.filled.Headset
|
|
import androidx.compose.material.icons.filled.Headset
|
|
import androidx.compose.material.icons.filled.PlayArrow
|
|
import androidx.compose.material.icons.filled.PlayArrow
|
|
import androidx.compose.material3.CircularProgressIndicator
|
|
import androidx.compose.material3.CircularProgressIndicator
|
|
import androidx.compose.material3.Icon
|
|
import androidx.compose.material3.Icon
|
|
-import androidx.compose.material3.IconButton
|
|
|
|
import androidx.compose.material3.LinearProgressIndicator
|
|
import androidx.compose.material3.LinearProgressIndicator
|
|
import androidx.compose.material3.ListItem
|
|
import androidx.compose.material3.ListItem
|
|
import androidx.compose.material3.ListItemDefaults
|
|
import androidx.compose.material3.ListItemDefaults
|
|
@@ -61,6 +58,7 @@ import java.io.FileInputStream
|
|
fun ContentChat(modifier: Modifier = Modifier, message: Message) {
|
|
fun ContentChat(modifier: Modifier = Modifier, message: Message) {
|
|
val context = LocalContext.current
|
|
val context = LocalContext.current
|
|
var selectedItem by remember { mutableStateOf("") }
|
|
var selectedItem by remember { mutableStateOf("") }
|
|
|
|
+ val progressViewModel: ProgressViewModel = hiltViewModel()
|
|
if (message.image_id.isNotEmpty()) {
|
|
if (message.image_id.isNotEmpty()) {
|
|
Column(modifier = Modifier.padding(2.dp)) {
|
|
Column(modifier = Modifier.padding(2.dp)) {
|
|
val file = File(context.filesDir, message.image_id)
|
|
val file = File(context.filesDir, message.image_id)
|
|
@@ -134,16 +132,21 @@ fun ContentChat(modifier: Modifier = Modifier, message: Message) {
|
|
.fillMaxWidth(0.76f)
|
|
.fillMaxWidth(0.76f)
|
|
.selectable(selected = selectedItem == message.message_id, onClick = {
|
|
.selectable(selected = selectedItem == message.message_id, onClick = {
|
|
selectedItem = message.message_id
|
|
selectedItem = message.message_id
|
|
- val file = File(context.filesDir, message.file_id)
|
|
|
|
- val uri = FileProvider.getUriForFile(
|
|
|
|
- context, context.applicationContext.packageName + ".provider", file
|
|
|
|
- )
|
|
|
|
- context.startActivity(
|
|
|
|
- Intent(
|
|
|
|
- Intent.ACTION_VIEW,
|
|
|
|
- uri
|
|
|
|
- ).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
|
|
- )
|
|
|
|
|
|
+ File(context.filesDir, message.file_id).also {
|
|
|
|
+ if (it.exists()) {
|
|
|
|
+ val uri = FileProvider.getUriForFile(
|
|
|
|
+ context, context.applicationContext.packageName + ".provider", it
|
|
|
|
+ )
|
|
|
|
+ context.startActivity(
|
|
|
|
+ Intent(
|
|
|
|
+ Intent.ACTION_VIEW,
|
|
|
|
+ uri
|
|
|
|
+ ).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
|
|
+ )
|
|
|
|
+ } else {
|
|
|
|
+ progressViewModel.download(context, message)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}),
|
|
}),
|
|
supportingContent = {
|
|
supportingContent = {
|
|
FileDesc(file = message.file_id)
|
|
FileDesc(file = message.file_id)
|
|
@@ -279,7 +282,6 @@ fun FileDesc(file: String, modifier: Modifier = Modifier) {
|
|
|
|
|
|
@Composable
|
|
@Composable
|
|
fun FileProgress(message: Message, modifier: Modifier = Modifier) {
|
|
fun FileProgress(message: Message, modifier: Modifier = Modifier) {
|
|
- val context = LocalContext.current
|
|
|
|
val progressViewModel: ProgressViewModel = hiltViewModel()
|
|
val progressViewModel: ProgressViewModel = hiltViewModel()
|
|
val progress by progressViewModel.get(message.message_id).observeAsState()
|
|
val progress by progressViewModel.get(message.message_id).observeAsState()
|
|
progress?.let {
|
|
progress?.let {
|
|
@@ -291,21 +293,4 @@ fun FileProgress(message: Message, modifier: Modifier = Modifier) {
|
|
)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- val file = File(context.filesDir, message.file_id)
|
|
|
|
- if (!file.exists()) {
|
|
|
|
- IconButton(
|
|
|
|
- onClick = { /*TODO*/ },
|
|
|
|
- modifier = modifier
|
|
|
|
- ) {
|
|
|
|
- Icon(
|
|
|
|
- imageVector = Icons.Default.DownloadForOffline,
|
|
|
|
- contentDescription = null,
|
|
|
|
- tint = Color.LightGray
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-fun Intent.getActionView(uri: Uri): Intent {
|
|
|
|
- return Intent(Intent.ACTION_VIEW, uri).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
|
|
}
|
|
}
|