Fix cut display names in bubbles

Fix guessing text width for bold text

Change-Id: I61d0421c1c159eb92b675166b9cbf6a4f1f609bc
This commit is contained in:
SpiritCroc 2022-07-10 14:56:55 +02:00
parent 81f0bf2a29
commit b165b40d70
2 changed files with 27 additions and 27 deletions

View File

@ -262,15 +262,15 @@ class ScMessageBubbleWrapView @JvmOverloads constructor(context: Context, attrs:
if (messageLayout.isRealBubble || messageLayout.isPseudoBubble) {
// Padding for bubble content: long for side with tail, short for other sides
val longPaddingDp: Int
val shortPaddingDp: Int
val longPadding: Int
val shortPadding: Int
bubbleView.setBackgroundResource(messageLayout.bubbleDrawable)
if (!messageLayout.isPseudoBubble) {
longPaddingDp = bubbleView.resources.getDimensionPixelSize(R.dimen.sc_bubble_inner_padding_long_side)
shortPaddingDp = bubbleView.resources.getDimensionPixelSize(R.dimen.sc_bubble_inner_padding_short_side)
longPadding = bubbleView.resources.getDimensionPixelSize(R.dimen.sc_bubble_inner_padding_long_side)
shortPadding = bubbleView.resources.getDimensionPixelSize(R.dimen.sc_bubble_inner_padding_short_side)
} else {
longPaddingDp = bubbleView.resources.getDimensionPixelSize(R.dimen.sc_bubble_tail_size)
shortPaddingDp = 0//if (attributes.informationData.showInformation && !hideSenderInformation()) { 8 } else { 0 }
longPadding = bubbleView.resources.getDimensionPixelSize(R.dimen.sc_bubble_tail_size)
shortPadding = 0//if (attributes.informationData.showInformation && !hideSenderInformation()) { 8 } else { 0 }
}
if (messageLayout.reverseBubble != defaultRtl) {
// Use left/right instead of start/end: bubbleView is always LTR
@ -283,17 +283,17 @@ class ScMessageBubbleWrapView @JvmOverloads constructor(context: Context, attrs:
if (messageLayout.reverseBubble != defaultRtl) {
// Use left/right instead of start/end: bubbleView is always LTR
bubbleView.setPadding(
shortPaddingDp,
shortPaddingDp,
longPaddingDp,
shortPaddingDp
shortPadding,
shortPadding,
longPadding,
shortPadding
)
} else {
bubbleView.setPadding(
longPaddingDp,
shortPaddingDp,
shortPaddingDp,
shortPaddingDp
longPadding,
shortPadding,
shortPadding,
shortPadding
)
}
@ -390,16 +390,16 @@ class ScMessageBubbleWrapView @JvmOverloads constructor(context: Context, attrs:
// We need to align the non-bubble member name view to pseudo bubbles
if (messageLayout.reverseBubble) {
views.messageMemberNameView.setPaddingRelative(
shortPaddingDp,
shortPadding,
0,
longPaddingDp,
longPadding,
0
)
} else {
views.messageMemberNameView.setPaddingRelative(
longPaddingDp,
longPadding,
0,
shortPaddingDp,
shortPadding,
0
)
}
@ -475,9 +475,7 @@ class ScMessageBubbleWrapView @JvmOverloads constructor(context: Context, attrs:
if (informationData?.messageLayout is TimelineMessageLayout.ScBubble &&
getBubbleTimeLocation(informationData.messageLayout as TimelineMessageLayout.ScBubble) == BubbleThemeUtils.BUBBLE_TIME_BOTTOM) {
// Guess text width for name and time
timeWidth = ceil(guessTextWidth(views.bubbleFooterMessageTimeView, informationData.time.toString())).toInt() +
views.bubbleFooterMessageTimeView.paddingLeft +
views.bubbleFooterMessageTimeView.paddingRight
timeWidth = ceil(guessTextWidth(views.bubbleFooterMessageTimeView, informationData.time.toString())).toInt()
timeHeight = ceil(views.bubbleFooterMessageTimeView.textSize).toInt() +
views.bubbleFooterMessageTimeView.paddingTop +
views.bubbleFooterMessageTimeView.paddingBottom
@ -522,9 +520,9 @@ class ScMessageBubbleWrapView @JvmOverloads constructor(context: Context, attrs:
val result = if (contentInBubble) {
if (getBubbleTimeLocation(messageLayout) == BUBBLE_TIME_BOTTOM) {
if (attributes.informationData.messageLayout.showDisplayName && !canHideSender) {
// Since timeView automatically gets enough space, either within or outside the viewStub, we just need to ensure the member name view has enough space
// Somehow not enough without extra space...
ceil(guessTextWidth(views.bubbleMessageMemberNameView, "$memberName ")).toInt()
// Since timeView automatically gets enough space, either within or outside the viewStub,
// we just need to ensure the member name view has enough space
ceil(guessTextWidth(views.bubbleMessageMemberNameView, memberName)).toInt()
} else {
// wrap_content works!
0

View File

@ -2,6 +2,7 @@ package im.vector.app.features.themes
import android.content.Context
import android.graphics.Paint
import android.graphics.Typeface
import android.os.Parcelable
import android.widget.TextView
import androidx.annotation.DimenRes
@ -104,13 +105,14 @@ fun guessTextWidth(view: TextView): Float {
}
fun guessTextWidth(view: TextView, text: CharSequence): Float {
return guessTextWidth(view.textSize, text);
return guessTextWidth(view.textSize, text, view.typeface) + view.paddingLeft + view.paddingRight
}
fun guessTextWidth(textSize: Float, text: CharSequence): Float {
fun guessTextWidth(textSize: Float, text: CharSequence, typeface: Typeface? = null): Float {
val paint = Paint()
paint.textSize = textSize
return paint.measureText(text.toString())
typeface?.let { paint.typeface = it }
return paint.measureText(text, 0, text.length)
}
@Parcelize