From 054b467caf9c5020cf7cad38e41b74aed59f5121 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 26 Feb 2020 14:18:48 +0100 Subject: [PATCH] Fix crash reported from rageshake --- .../im/vector/riotx/core/platform/EllipsizingTextView.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/riotx/core/platform/EllipsizingTextView.kt b/vector/src/main/java/im/vector/riotx/core/platform/EllipsizingTextView.kt index 70af607753..2e5786b57d 100644 --- a/vector/src/main/java/im/vector/riotx/core/platform/EllipsizingTextView.kt +++ b/vector/src/main/java/im/vector/riotx/core/platform/EllipsizingTextView.kt @@ -38,6 +38,7 @@ import android.text.TextUtils.substring import android.text.style.ForegroundColorSpan import android.util.AttributeSet import androidx.appcompat.widget.AppCompatTextView +import timber.log.Timber import java.util.ArrayList import java.util.regex.Pattern @@ -300,7 +301,13 @@ class EllipsizingTextView @JvmOverloads constructor(context: Context, attrs: Att private inner class EllipsizeEndStrategy : EllipsizeStrategy() { override fun createEllipsizedText(fullText: CharSequence?): CharSequence? { val layout = createWorkingLayout(fullText) - val cutOffIndex = layout.getLineEnd(maxLines - 1) + val cutOffIndex = try { + layout.getLineEnd(maxLines - 1) + } catch (exception: IndexOutOfBoundsException) { + // Not sure to understand why this is happening + Timber.e(exception, "IndexOutOfBoundsException, maxLine: $maxLines") + 0 + } val textLength = fullText!!.length var cutOffLength = textLength - cutOffIndex if (cutOffLength < ELLIPSIS.length) cutOffLength = ELLIPSIS.length