From 4f4381a32522b4478057fc491e27fef018e725fb Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Sun, 20 Feb 2022 14:50:34 +0100 Subject: [PATCH] [bubble merge] Keep footered time out of code blocks Change-Id: I185016a1f014cb774afa0bb28bd8020f2ec2f410 --- .../app/core/ui/views/FooteredTextView.kt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/core/ui/views/FooteredTextView.kt b/vector/src/main/java/im/vector/app/core/ui/views/FooteredTextView.kt index 790b9204fd..9853b88425 100644 --- a/vector/src/main/java/im/vector/app/core/ui/views/FooteredTextView.kt +++ b/vector/src/main/java/im/vector/app/core/ui/views/FooteredTextView.kt @@ -4,9 +4,14 @@ import android.content.Context import android.graphics.Canvas import android.graphics.Rect import android.text.Layout +import android.text.Spannable +import android.text.Spanned import android.util.AttributeSet import androidx.appcompat.widget.AppCompatTextView +import androidx.core.text.getSpans +import androidx.core.text.toSpanned import im.vector.app.R +import im.vector.app.features.html.HtmlCodeSpan import kotlin.math.ceil import kotlin.math.max @@ -90,8 +95,19 @@ class FooteredTextView @JvmOverloads constructor( (maxLineWidth + resources.getDimensionPixelSize(R.dimen.sc_footer_rtl_mismatch_extra_padding)) ) + footerWidth + // If the last line is a multi-line code block, we have never space in the last line (as the black background always uses full width) + val forceNewlineFooter = if (text is Spannable || text is Spanned) { + val span = text.toSpanned() + // If not found, -1+1 = 0 + val lastLineStart = span.lastIndexOf("\n") + 1 + val lastLineCodeSpans = span.getSpans(lastLineStart) + lastLineCodeSpans.any { it.isBlock } + } else { + false + } + // Is there space for a horizontal footer? - if (widthWithHorizontalFooter <= widthLimit) { + if (widthWithHorizontalFooter <= widthLimit && !forceNewlineFooter) { // Reserve extra horizontal footer space if necessary if (widthWithHorizontalFooter > newWidth) { newWidth = ceil(widthWithHorizontalFooter).toInt()