1
0
mirror of https://github.com/tuskyapp/Tusky synced 2024-12-12 09:08:16 +01:00

Fix posts with show more button even if bad ratio didn't collapse

This commit is contained in:
HellPie 2018-09-05 22:47:31 +02:00 committed by HellPie
parent 0d83ff9c5e
commit b2dbd16678
2 changed files with 16 additions and 1 deletions

View File

@ -72,6 +72,18 @@ public class SmartLengthInputFilter implements InputFilter {
this.skipIfBadRatio = skipIfBadRatio;
}
/**
* Calculates if it's worth trimming the message at a specific limit or if the content
* that will be hidden will not be enough to justify the operation.
*
* @param message The message to trim.
* @param limit The maximum length after trimming.
* @return Whether the message should be trimmed or not.
*/
public static boolean hasBadRatio(Spanned message, int limit) {
return (double) limit / message.length() > 0.75;
}
/** {@inheritDoc} */
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {

View File

@ -59,7 +59,10 @@ public final class ViewDataUtils {
.setApplication(visibleStatus.getApplication())
.setStatusEmojis(visibleStatus.getEmojis())
.setAccountEmojis(visibleStatus.getAccount().getEmojis())
.setCollapsible(collapseLongStatusContent && status.getContent().length() > SmartLengthInputFilter.LENGTH_DEFAULT)
.setCollapsible(collapseLongStatusContent && !SmartLengthInputFilter.hasBadRatio(
visibleStatus.getContent(),
SmartLengthInputFilter.LENGTH_DEFAULT
))
.setCollapsed(true)
.createStatusViewData();
}