mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-10 01:02:33 +02: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:
@@ -24,7 +24,7 @@ class ExpandableTextCutOffCalculator {
|
|||||||
companion object {
|
companion object {
|
||||||
private const val SHORT_TEXT_LENGTH = 350
|
private const val SHORT_TEXT_LENGTH = 350
|
||||||
private const val SHORTEN_AFTER_LINES = 10
|
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 {
|
fun indexToCutOff(content: String): Int {
|
||||||
// Cuts the text in the first space or new line after SHORT_TEXT_LENGTH characters
|
// 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)
|
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 newString = content.take(SHORT_TEXT_LENGTH)
|
||||||
val firstSpaceBeforeCut =
|
val firstSpaceBeforeCut =
|
||||||
newString.lastIndexOf(' ').let { if (it < 0) content.length else it }
|
newString.lastIndexOf(' ').let { if (it < 0) content.length else it }
|
||||||
val firstNewLineBeforeCut =
|
val firstNewLineBeforeCut =
|
||||||
newString.lastIndexOf('\n').let { if (it < 0) content.length else it }
|
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)
|
return maxOf(firstSpaceBeforeCut, firstNewLineBeforeCut)
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user