From 813d3679cd48126d7a26a89d6fcc5769e72bea73 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Mon, 28 Dec 2020 14:00:37 +0100 Subject: [PATCH] Fix footer when text does not match the locale's RTL status Change-Id: Iaaf3d5fc2f2bd1b635974494362ed6569962e67e --- .../vector/app/core/ui/views/FooteredTextView.kt | 14 +++++++++++++- 1 file changed, 13 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 e54d4163db..84c4ece519 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 @@ -37,6 +37,18 @@ class FooteredTextView @JvmOverloads constructor( } */ + val lastLine = layout.lineCount - 1 + + // Let's check if the last line's text has the same RTL behaviour as the layout direction. + val viewIsRtl = layoutDirection == LAYOUT_DIRECTION_RTL + val lastVisibleCharacter = layout.getLineVisibleEnd(lastLine) - 1 + val looksLikeRtl = layout.isRtlCharAt(lastVisibleCharacter) + if (looksLikeRtl != viewIsRtl) { + // Our footer would overlap text even if there is space in the last line, so reserve space in y-direction + setMeasuredDimension(max(measuredWidth, footerWidth), measuredHeight + footerHeight) + return + } + // Get required width for all lines var maxLineWidth = 0f for (i in 0 until layout.lineCount) { @@ -48,7 +60,7 @@ class FooteredTextView @JvmOverloads constructor( var newWidth = ceil(maxLineWidth).toInt() var newHeight = measuredHeight - val widthLastLine = layout.getLineWidth(layout.lineCount-1) + val widthLastLine = layout.getLineWidth(lastLine) // Required width if putting footer in the same line as the last line val widthWithHorizontalFooter = widthLastLine + footerWidth