|
@@ -1,5 +1,6 @@
|
|
|
package io.nexilis.alpha.ui.components
|
|
|
|
|
|
+import android.graphics.BitmapFactory
|
|
|
import androidx.compose.foundation.Image
|
|
|
import androidx.compose.foundation.background
|
|
|
import androidx.compose.foundation.layout.Column
|
|
@@ -33,6 +34,7 @@ import androidx.compose.ui.text.style.TextOverflow
|
|
|
import androidx.compose.ui.text.toUpperCase
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.core.content.FileProvider
|
|
|
+import androidx.exifinterface.media.ExifInterface
|
|
|
import coil.compose.rememberAsyncImagePainter
|
|
|
import io.nexilis.alpha.BuildConfig
|
|
|
import io.nexilis.alpha.R
|
|
@@ -41,9 +43,10 @@ import io.nexilis.service.core.extension
|
|
|
import io.nexilis.service.core.toHumanStandard
|
|
|
import io.nexilis.service.data.entities.Message
|
|
|
import java.io.File
|
|
|
+import java.io.FileInputStream
|
|
|
|
|
|
@Composable
|
|
|
-fun ContentChat(modifier: Modifier, message: Message) {
|
|
|
+fun ContentChat(modifier: Modifier = Modifier, message: Message) {
|
|
|
val context = LocalContext.current
|
|
|
if (message.image_id.isNotEmpty()) {
|
|
|
Column(modifier = Modifier.padding(2.dp)) {
|
|
@@ -51,16 +54,31 @@ fun ContentChat(modifier: Modifier, message: Message) {
|
|
|
val uri = FileProvider.getUriForFile(
|
|
|
context, BuildConfig.APPLICATION_ID + ".provider", file
|
|
|
)
|
|
|
+ var width: Int
|
|
|
+ var height: Int
|
|
|
+ FileInputStream(file).use {
|
|
|
+ val exif = ExifInterface(it)
|
|
|
+ width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 1)
|
|
|
+ height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 1)
|
|
|
+ }
|
|
|
+ if (width == 0) {
|
|
|
+ FileInputStream(file).use {
|
|
|
+ val bitmap = BitmapFactory.decodeStream(it)
|
|
|
+ width = bitmap.width
|
|
|
+ if (height == 0) height = bitmap.height
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val aspectRatio = width / height.toFloat()
|
|
|
Image(
|
|
|
painter = rememberAsyncImagePainter(uri),
|
|
|
contentDescription = "",
|
|
|
modifier = modifier
|
|
|
- .aspectRatio(3f / 4f)
|
|
|
+ .aspectRatio(aspectRatio)
|
|
|
.graphicsLayer {
|
|
|
shape = RoundedCornerShape(12.dp)
|
|
|
clip = true
|
|
|
},
|
|
|
- contentScale = ContentScale.Crop
|
|
|
+ contentScale = ContentScale.Fit
|
|
|
)
|
|
|
if (message.message_text.isNotEmpty()) {
|
|
|
Text(
|