Fix posts with show more button even if bad ratio didn't collapse
This commit is contained in:
parent
0d83ff9c5e
commit
b2dbd16678
|
@ -72,6 +72,18 @@ public class SmartLengthInputFilter implements InputFilter {
|
||||||
this.skipIfBadRatio = skipIfBadRatio;
|
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} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
|
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
|
||||||
|
|
|
@ -59,7 +59,10 @@ public final class ViewDataUtils {
|
||||||
.setApplication(visibleStatus.getApplication())
|
.setApplication(visibleStatus.getApplication())
|
||||||
.setStatusEmojis(visibleStatus.getEmojis())
|
.setStatusEmojis(visibleStatus.getEmojis())
|
||||||
.setAccountEmojis(visibleStatus.getAccount().getEmojis())
|
.setAccountEmojis(visibleStatus.getAccount().getEmojis())
|
||||||
.setCollapsible(collapseLongStatusContent && status.getContent().length() > SmartLengthInputFilter.LENGTH_DEFAULT)
|
.setCollapsible(collapseLongStatusContent && !SmartLengthInputFilter.hasBadRatio(
|
||||||
|
visibleStatus.getContent(),
|
||||||
|
SmartLengthInputFilter.LENGTH_DEFAULT
|
||||||
|
))
|
||||||
.setCollapsed(true)
|
.setCollapsed(true)
|
||||||
.createStatusViewData();
|
.createStatusViewData();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue