79 lines
2.5 KiB
Kotlin
79 lines
2.5 KiB
Kotlin
package chats.presentation.components
|
|
|
|
import androidx.compose.foundation.background
|
|
import androidx.compose.foundation.clickable
|
|
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
import androidx.compose.material3.MaterialTheme
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.draw.clip
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.layout.ContentScale
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
import androidx.compose.ui.text.style.TextOverflow
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.compose.ui.unit.sp
|
|
import coil.compose.AsyncImage
|
|
import core.utils.LinkMetadata
|
|
|
|
@Composable
|
|
fun LinkPreview(
|
|
metadata: LinkMetadata,
|
|
onClick: () -> Unit,
|
|
modifier: Modifier = Modifier,
|
|
contentColor: Color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
) {
|
|
Column(
|
|
modifier = modifier
|
|
.fillMaxWidth()
|
|
.clip(RoundedCornerShape(12.dp))
|
|
.background(contentColor.copy(alpha = 0.05f))
|
|
.clickable(onClick = onClick)
|
|
.padding(8.dp)
|
|
) {
|
|
if (metadata.imageUrl != null) {
|
|
AsyncImage(
|
|
model = metadata.imageUrl,
|
|
contentDescription = null,
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.height(140.dp)
|
|
.clip(RoundedCornerShape(8.dp)),
|
|
contentScale = ContentScale.Crop
|
|
)
|
|
Spacer(modifier = Modifier.height(8.dp))
|
|
}
|
|
|
|
metadata.title?.let {
|
|
Text(
|
|
text = it,
|
|
style = MaterialTheme.typography.bodyMedium,
|
|
fontWeight = FontWeight.Bold,
|
|
color = contentColor,
|
|
maxLines = 1,
|
|
overflow = TextOverflow.Ellipsis
|
|
)
|
|
}
|
|
|
|
metadata.description?.let {
|
|
Text(
|
|
text = it,
|
|
style = MaterialTheme.typography.bodySmall,
|
|
color = contentColor.copy(alpha = 0.8f),
|
|
maxLines = 2,
|
|
overflow = TextOverflow.Ellipsis,
|
|
lineHeight = 16.sp
|
|
)
|
|
}
|
|
|
|
Text(
|
|
text = metadata.url.removePrefix("https://").removePrefix("http://").split("/")[0],
|
|
style = MaterialTheme.typography.labelSmall,
|
|
color = MaterialTheme.colorScheme.primary,
|
|
modifier = Modifier.padding(top = 4.dp)
|
|
)
|
|
}
|
|
}
|