From f50e511da028fbd1aa5f7192ab8941de5b819e4d Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Sun, 30 Jun 2024 10:20:14 -0300 Subject: [PATCH] Cut the text when the content length is greater than SHORT_TEXT_LENGTH and theres no spaces and new lines --- .../commons/richtext/ExpandableTextCutOffCalculator.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/commons/src/main/java/com/vitorpamplona/amethyst/commons/richtext/ExpandableTextCutOffCalculator.kt b/commons/src/main/java/com/vitorpamplona/amethyst/commons/richtext/ExpandableTextCutOffCalculator.kt index 8cabd98fd..9a91c8ae5 100644 --- a/commons/src/main/java/com/vitorpamplona/amethyst/commons/richtext/ExpandableTextCutOffCalculator.kt +++ b/commons/src/main/java/com/vitorpamplona/amethyst/commons/richtext/ExpandableTextCutOffCalculator.kt @@ -24,7 +24,7 @@ class ExpandableTextCutOffCalculator { companion object { private const val SHORT_TEXT_LENGTH = 350 private const val SHORTEN_AFTER_LINES = 10 - private const val TOO_FAR_SEACH_THE_OTHER_WAY = 450 + private const val TOO_FAR_SEARCH_THE_OTHER_WAY = 450 fun indexToCutOff(content: String): Int { // Cuts the text in the first space or new line after SHORT_TEXT_LENGTH characters @@ -37,12 +37,15 @@ class ExpandableTextCutOffCalculator { val min = minOf(firstSpaceAfterCut, firstNewLineAfterCut, firstLineAfterLineLimits) - if (min > TOO_FAR_SEACH_THE_OTHER_WAY) { + if (min > TOO_FAR_SEARCH_THE_OTHER_WAY) { val newString = content.take(SHORT_TEXT_LENGTH) val firstSpaceBeforeCut = newString.lastIndexOf(' ').let { if (it < 0) content.length else it } val firstNewLineBeforeCut = newString.lastIndexOf('\n').let { if (it < 0) content.length else it } + if (maxOf(firstSpaceBeforeCut, firstNewLineBeforeCut) == content.length && content.length > SHORT_TEXT_LENGTH) { + return SHORT_TEXT_LENGTH + } return maxOf(firstSpaceBeforeCut, firstNewLineBeforeCut) } else {