Cut the text when the content length is greater than SHORT_TEXT_LENGTH and theres no spaces and new lines

This commit is contained in:
greenart7c3 2024-06-30 10:20:14 -03:00
parent 5c21e219fe
commit f50e511da0
No known key found for this signature in database
GPG Key ID: 885822EED3A26A6D

View File

@ -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 {