From a013a30d1340af94761e4638661c96563d822dc1 Mon Sep 17 00:00:00 2001 From: Andy Klimczak Date: Tue, 27 Dec 2016 15:12:26 -0500 Subject: [PATCH] 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 --- .../java/org/floens/chan/ui/cell/PostCell.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java b/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java index f42f33a5..d194f592 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java +++ b/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(); CharSequence commentText; - if (post.comment.length() > COMMENT_MAX_LENGTH_BOARD && !threadMode) { - BreakIterator bi = BreakIterator.getWordInstance(); - 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); + if (!threadMode && post.comment.length() > COMMENT_MAX_LENGTH_BOARD) { + commentText = truncatePostComment(post, COMMENT_MAX_LENGTH_BOARD); } else { 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); /**