mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-17 21:31:57 +01:00
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:
parent
5c21e219fe
commit
f50e511da0
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user