Truncate long posts (#271)

Factor the truncate long posts into it's own method.
Add an ellipsis to end of long post text to let the user know there is
more to the post
multisite^2
Andy Klimczak 9 years ago committed by Florens
parent 91026d76c8
commit a013a30d13
  1. 17
      Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java

@ -409,12 +409,8 @@ public class PostCell extends LinearLayout implements PostCellInterface {
icons.apply(); icons.apply();
CharSequence commentText; CharSequence commentText;
if (post.comment.length() > COMMENT_MAX_LENGTH_BOARD && !threadMode) { if (!threadMode && post.comment.length() > COMMENT_MAX_LENGTH_BOARD) {
BreakIterator bi = BreakIterator.getWordInstance(); commentText = truncatePostComment(post, COMMENT_MAX_LENGTH_BOARD);
bi.setText(post.comment.toString());
int precedingBoundary = bi.preceding(COMMENT_MAX_LENGTH_BOARD);
// Fallback to old method in case the comment does not have any spaces/individual words
commentText = precedingBoundary > 0 ? post.comment.subSequence(0, precedingBoundary) : post.comment.subSequence(0, COMMENT_MAX_LENGTH_BOARD);
} else { } else {
commentText = post.comment; commentText = post.comment;
} }
@ -491,6 +487,15 @@ public class PostCell extends LinearLayout implements PostCellInterface {
} }
} }
private CharSequence truncatePostComment(Post post, int maxCommentLength) {
BreakIterator bi = BreakIterator.getWordInstance();
bi.setText(post.comment.toString());
int precedingBoundary = bi.following(maxCommentLength);
// Fallback to old method in case the comment does not have any spaces/individual words
CharSequence commentText = precedingBoundary > 0 ? post.comment.subSequence(0, precedingBoundary) : post.comment.subSequence(0, maxCommentLength);
return TextUtils.concat(commentText, "\u2026"); // append ellipsis
}
private static BackgroundColorSpan BACKGROUND_SPAN = new BackgroundColorSpan(0x6633B5E5); private static BackgroundColorSpan BACKGROUND_SPAN = new BackgroundColorSpan(0x6633B5E5);
/** /**

Loading…
Cancel
Save