Правка ответов, локализация, поддержка медиа

This commit is contained in:
Халимов Рустам
2026-04-17 22:07:33 +03:00
parent bef30c2c86
commit ed7521a563
11 changed files with 100 additions and 4 deletions

View File

@@ -53,4 +53,11 @@
<string name="message_placeholder">Message...</string>
<string name="voice_message">Voice Message</string>
<string name="send">Send</string>
<string name="reply_photo">Photo</string>
<string name="reply_video">Video</string>
<string name="reply_audio">Audio</string>
<string name="reply_file">File</string>
<string name="reply_gif">GIF</string>
<string name="reply_prefix">Reply to </string>
<string name="reply_self">yourself</string>
</resources>

View File

@@ -75,4 +75,11 @@
<string name="contacts_tab">Контакты</string>
<string name="profile_tab">Профиль</string>
<string name="saving">Сохранение...</string>
<string name="reply_photo">Фото</string>
<string name="reply_video">Видео</string>
<string name="reply_audio">Аудио</string>
<string name="reply_file">Файл</string>
<string name="reply_gif">GIF</string>
<string name="reply_prefix">Ответ </string>
<string name="reply_self">самому себе</string>
</resources>

View File

@@ -640,20 +640,63 @@ fun ChatDetailScreen(
.weight(1f)
.padding(horizontal = 8.dp, vertical = 2.dp)
) {
val replyPrefix = stringResource(R.string.reply_prefix)
val replySelf = stringResource(R.string.reply_self)
Text(
text = "Ответ " + (if (replyMsg.senderId == viewModel.getCurrentUserId()) "самом себе" else replyMsg.senderName),
text = replyPrefix + (if (replyMsg.senderId == viewModel.getCurrentUserId()) replySelf else replyMsg.senderName),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary,
fontWeight = FontWeight.Bold
)
val photoText = stringResource(R.string.reply_photo)
val videoText = stringResource(R.string.reply_video)
val voiceText = stringResource(R.string.voice_message)
val audioText = stringResource(R.string.reply_audio)
val fileText = stringResource(R.string.reply_file)
val gifText = stringResource(R.string.reply_gif)
val mediaText = stringResource(R.string.media)
val replyText = remember(replyMsg) {
if (!replyMsg.content.isNullOrEmpty()) {
replyMsg.content
} else {
when (replyMsg.mediaType) {
chats.domain.model.MediaType.IMAGE -> photoText
chats.domain.model.MediaType.VIDEO -> videoText
chats.domain.model.MediaType.AUDIO -> if (replyMsg.media.any { it.type == "voice" }) voiceText else audioText
chats.domain.model.MediaType.FILE -> fileText
chats.domain.model.MediaType.GIF -> gifText
else -> mediaText
}
}
}
Text(
text = replyMsg.content ?: if (replyMsg.media.isNotEmpty()) "Медиа" else "...",
text = replyText,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
if ((replyMsg.mediaType == chats.domain.model.MediaType.IMAGE ||
replyMsg.mediaType == chats.domain.model.MediaType.VIDEO ||
replyMsg.mediaType == chats.domain.model.MediaType.GIF) &&
replyMsg.media.isNotEmpty()) {
androidx.compose.foundation.Image(
painter = rememberAsyncImagePainter(replyMsg.media.first().url),
contentDescription = null,
modifier = Modifier
.padding(end = 4.dp)
.size(36.dp)
.clip(RoundedCornerShape(4.dp)),
contentScale = androidx.compose.ui.layout.ContentScale.Crop
)
}
IconButton(onClick = { viewModel.cancelReply() }) {
Icon(Icons.Default.Close, contentDescription = "Cancel", modifier = Modifier.size(20.dp), tint = Color.Gray)
}

View File

@@ -123,7 +123,22 @@ fun MessageBubble(
.width(2.dp)
.background(if (isCurrentUser) Color.White else Color(0xFF3096E5))
)
Column(modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp)) {
val context = androidx.compose.ui.platform.LocalContext.current
val isReplyImage = reply.mediaType == MediaType.IMAGE || reply.mediaType == MediaType.VIDEO || reply.mediaType == MediaType.GIF
if (isReplyImage && reply.media.isNotEmpty()) {
AsyncImage(
model = reply.media.first().url,
contentDescription = null,
modifier = Modifier
.fillMaxHeight()
.width(40.dp)
.clip(RoundedCornerShape(0.dp, 4.dp, 4.dp, 0.dp)),
contentScale = ContentScale.Crop
)
}
Column(modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp).weight(1f)) {
val accentColor = if (isCurrentUser) Color.White else Color(0xFF3096E5)
Text(
text = reply.senderName,
@@ -132,8 +147,32 @@ fun MessageBubble(
maxLines = 1,
fontWeight = androidx.compose.ui.text.font.FontWeight.Bold
)
val photoText = androidx.compose.ui.res.stringResource(ru.knot.messager.R.string.reply_photo)
val videoText = androidx.compose.ui.res.stringResource(ru.knot.messager.R.string.reply_video)
val voiceText = androidx.compose.ui.res.stringResource(ru.knot.messager.R.string.voice_message)
val audioText = androidx.compose.ui.res.stringResource(ru.knot.messager.R.string.reply_audio)
val fileText = androidx.compose.ui.res.stringResource(ru.knot.messager.R.string.reply_file)
val gifText = androidx.compose.ui.res.stringResource(ru.knot.messager.R.string.reply_gif)
val mediaText = androidx.compose.ui.res.stringResource(ru.knot.messager.R.string.media)
val replyText = remember(reply) {
if (!reply.content.isNullOrEmpty()) {
reply.content
} else {
when (reply.mediaType) {
MediaType.IMAGE -> photoText
MediaType.VIDEO -> videoText
MediaType.AUDIO -> if (reply.media.any { it.type == "voice" }) voiceText else audioText
MediaType.FILE -> fileText
MediaType.GIF -> gifText
else -> mediaText
}
}
}
Text(
text = reply.content ?: if (reply.media.isNotEmpty()) "\uD83D\uDCCE Media" else "",
text = replyText,
style = MaterialTheme.typography.bodySmall,
color = contentColor.copy(alpha = 0.8f),
maxLines = 1,