|
@@ -1,6 +1,8 @@
|
|
|
package io.nexilis.alpha.ui.components
|
|
|
|
|
|
+import android.content.Intent
|
|
|
import android.graphics.BitmapFactory
|
|
|
+import android.net.Uri
|
|
|
import androidx.compose.foundation.Image
|
|
|
import androidx.compose.foundation.background
|
|
|
import androidx.compose.foundation.layout.Column
|
|
@@ -10,6 +12,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
import androidx.compose.foundation.layout.size
|
|
|
import androidx.compose.foundation.layout.widthIn
|
|
|
+import androidx.compose.foundation.selection.selectable
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
import androidx.compose.material.icons.filled.DownloadForOffline
|
|
@@ -20,13 +23,15 @@ import androidx.compose.material3.Icon
|
|
|
import androidx.compose.material3.IconButton
|
|
|
import androidx.compose.material3.LinearProgressIndicator
|
|
|
import androidx.compose.material3.ListItem
|
|
|
-import androidx.compose.material3.ListItemColors
|
|
|
import androidx.compose.material3.ListItemDefaults
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
import androidx.compose.material3.Text
|
|
|
import androidx.compose.runtime.Composable
|
|
|
import androidx.compose.runtime.getValue
|
|
|
import androidx.compose.runtime.livedata.observeAsState
|
|
|
+import androidx.compose.runtime.mutableStateOf
|
|
|
+import androidx.compose.runtime.remember
|
|
|
+import androidx.compose.runtime.setValue
|
|
|
import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.graphics.Color
|
|
@@ -55,6 +60,7 @@ import java.io.FileInputStream
|
|
|
@Composable
|
|
|
fun ContentChat(modifier: Modifier = Modifier, message: Message) {
|
|
|
val context = LocalContext.current
|
|
|
+ var selectedItem by remember { mutableStateOf("") }
|
|
|
if (message.image_id.isNotEmpty()) {
|
|
|
Column(modifier = Modifier.padding(2.dp)) {
|
|
|
val file = File(context.filesDir, message.image_id)
|
|
@@ -88,6 +94,15 @@ fun ContentChat(modifier: Modifier = Modifier, message: Message) {
|
|
|
painter = rememberAsyncImagePainter(uri),
|
|
|
contentDescription = "",
|
|
|
modifier = modifier
|
|
|
+ .selectable(selected = selectedItem == message.message_id, onClick = {
|
|
|
+ selectedItem = message.message_id
|
|
|
+ context.startActivity(
|
|
|
+ Intent(
|
|
|
+ Intent.ACTION_VIEW,
|
|
|
+ uri
|
|
|
+ ).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
|
+ )
|
|
|
+ })
|
|
|
.aspectRatio(aspectRatio)
|
|
|
.graphicsLayer {
|
|
|
shape = RoundedCornerShape(12.dp)
|
|
@@ -115,7 +130,21 @@ fun ContentChat(modifier: Modifier = Modifier, message: Message) {
|
|
|
overflow = TextOverflow.Ellipsis
|
|
|
)
|
|
|
},
|
|
|
- modifier = Modifier.fillMaxWidth(0.76f),
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth(0.76f)
|
|
|
+ .selectable(selected = selectedItem == message.message_id, onClick = {
|
|
|
+ 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)
|
|
|
+ )
|
|
|
+ }),
|
|
|
supportingContent = {
|
|
|
FileDesc(file = message.file_id)
|
|
|
},
|
|
@@ -275,4 +304,8 @@ fun FileProgress(message: Message, modifier: Modifier = Modifier) {
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+fun Intent.getActionView(uri: Uri): Intent {
|
|
|
+ return Intent(Intent.ACTION_VIEW, uri).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
|
}
|