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

View File

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