Chat Preview text bug fix

This commit is contained in:
DarkKnight2122
2026-04-25 05:20:16 +05:30
parent 347115f8d3
commit f3fb9667d8

View File

@@ -9,6 +9,8 @@ import android.text.TextPaint
import android.view.View
import android.view.ViewGroup
import android.graphics.Typeface
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
@@ -78,9 +80,10 @@ class FriendFeedMessagePreview : Feature("FriendFeedMessagePreview") {
val ffSdlPrimaryTextStartMargin = 6 * density
val feedEntryHeight = ffSdlAvatarSize + ffSdlAvatarMargin * 2 + (4 * density).toInt()
val separatorHeight = (density * 2).toInt()
val safetyGap = (12 * density).toInt()
val textPaint = TextPaint().apply {
textSize = secondaryTextSize
isAntiAlias = true
}
context.event.subscribe(BuildMessageEvent::class) { param ->
@@ -105,14 +108,14 @@ class FriendFeedMessagePreview : Feature("FriendFeedMessagePreview") {
}
fetchMessages(conversationId) {
var maxTextHeight = 0
val previewContainerHeight = messageCache[conversationId]?.sumOf { msg ->
val rect = Rect()
textPaint.getTextBounds(msg, 0, msg.length, rect)
rect.height().also {
if (it > maxTextHeight) maxTextHeight = it
}.plus(separatorHeight)
} ?: run {
val fontMetrics = textPaint.fontMetrics
val lineHeight = (fontMetrics.descent - fontMetrics.ascent).toInt()
val spacing = (2 * density).toInt()
val messages = messageCache[conversationId]
val previewContainerHeight = if (messages.isNullOrEmpty()) 0 else (messages.size * (lineHeight + spacing))
if (previewContainerHeight == 0) {
ffItem.layoutParams = ffItem.layoutParams.apply {
height = ViewGroup.LayoutParams.MATCH_PARENT
}
@@ -120,22 +123,23 @@ class FriendFeedMessagePreview : Feature("FriendFeedMessagePreview") {
}
ffItem.layoutParams = ffItem.layoutParams.apply {
height = feedEntryHeight + previewContainerHeight + separatorHeight
height = feedEntryHeight + (safetyGap * 2) + previewContainerHeight
}
cachedLayouts[conversationId] = frameLayout
frameLayout.addForegroundDrawable("ffItem", ShapeDrawable(object: Shape() {
override fun draw(canvas: Canvas, paint: Paint) {
val offsetY = canvas.height.toFloat() - previewContainerHeight
val startY = feedEntryHeight.toFloat() + safetyGap
paint.textSize = secondaryTextSize
paint.color = context.userInterface.colorPrimary
paint.color = Color(context.userInterface.colorPrimary).copy(alpha = 0.7f).toArgb()
paint.typeface = Typeface.DEFAULT
paint.isAntiAlias = true
messageCache[conversationId]?.forEachIndexed { index, messageString ->
messages?.forEachIndexed { index, messageString ->
canvas.drawText(messageString,
feedEntryHeight + ffSdlPrimaryTextStartMargin,
offsetY + index * maxTextHeight,
ffSdlAvatarSize + ffSdlAvatarMargin + (ffSdlPrimaryTextStartMargin * 2),
startY + (index + 1) * lineHeight + (index * spacing),
paint
)
}