diff --git a/src/org/thoughtcrime/securesms/ConversationListItem.java b/src/org/thoughtcrime/securesms/ConversationListItem.java index 37230fb112..fb62951dc3 100644 --- a/src/org/thoughtcrime/securesms/ConversationListItem.java +++ b/src/org/thoughtcrime/securesms/ConversationListItem.java @@ -61,6 +61,8 @@ public class ConversationListItem extends RelativeLayout private final static Typeface BOLD_TYPEFACE = Typeface.create("sans-serif-medium", Typeface.NORMAL); private final static Typeface LIGHT_TYPEFACE = Typeface.create("sans-serif", Typeface.NORMAL); + private static final int MAX_SNIPPET_LENGTH = 500; + private Set selectedThreads; private Recipient recipient; private long threadId; @@ -156,7 +158,7 @@ public class ConversationListItem extends RelativeLayout this.typingView.stopAnimation(); this.subjectView.setVisibility(VISIBLE); - this.subjectView.setText(thread.getDisplayBody(getContext())); + this.subjectView.setText(getTrimmedSnippet(thread.getDisplayBody(getContext()))); this.subjectView.setTypeface(unreadCount == 0 ? LIGHT_TYPEFACE : BOLD_TYPEFACE); this.subjectView.setTextColor(unreadCount == 0 ? ThemeUtil.getThemedColor(getContext(), R.attr.conversation_list_item_subject_color) : ThemeUtil.getThemedColor(getContext(), R.attr.conversation_list_item_unread_color)); @@ -265,6 +267,11 @@ public class ConversationListItem extends RelativeLayout return lastSeen; } + private @NonNull CharSequence getTrimmedSnippet(@NonNull CharSequence snippet) { + return snippet.length() <= MAX_SNIPPET_LENGTH ? snippet + : snippet.subSequence(0, MAX_SNIPPET_LENGTH); + } + private void setThumbnailSnippet(ThreadRecord thread) { if (thread.getSnippetUri() != null) { this.thumbnailView.setVisibility(View.VISIBLE); diff --git a/src/org/thoughtcrime/securesms/longmessage/LongMessageActivity.java b/src/org/thoughtcrime/securesms/longmessage/LongMessageActivity.java index 2b3998c6e6..a71cad7192 100644 --- a/src/org/thoughtcrime/securesms/longmessage/LongMessageActivity.java +++ b/src/org/thoughtcrime/securesms/longmessage/LongMessageActivity.java @@ -42,6 +42,8 @@ public class LongMessageActivity extends PassphraseRequiredActionBarActivity imp private static final String KEY_MESSAGE_ID = "message_id"; private static final String KEY_IS_MMS = "is_mms"; + private static final int MAX_DISPLAY_LENGTH = 64 * 1024; + private final DynamicLanguage dynamicLanguage = new DynamicLanguage(); private final DynamicTheme dynamicTheme = new DynamicTheme(); @@ -150,14 +152,22 @@ public class LongMessageActivity extends PassphraseRequiredActionBarActivity imp TextView text = bubble.findViewById(R.id.longmessage_text); ConversationItemFooter footer = bubble.findViewById(R.id.longmessage_footer); + String trimmedBody = getTrimmedBody(message.get().getFullBody()); + SpannableString styledBody = linkifyMessageBody(new SpannableString(trimmedBody)); + bubble.setVisibility(View.VISIBLE); - text.setText(linkifyMessageBody(new SpannableString(message.get().getFullBody()))); + text.setText(styledBody); text.setMovementMethod(LinkMovementMethod.getInstance()); text.setTextSize(TypedValue.COMPLEX_UNIT_SP, TextSecurePreferences.getMessageBodyTextSize(this)); footer.setMessageRecord(message.get().getMessageRecord(), dynamicLanguage.getCurrentLocale()); }); } + private String getTrimmedBody(@NonNull String text) { + return text.length() <= MAX_DISPLAY_LENGTH ? text + : text.substring(0, MAX_DISPLAY_LENGTH); + } + private SpannableString linkifyMessageBody(SpannableString messageBody) { int linkPattern = Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS; boolean hasLinks = Linkify.addLinks(messageBody, linkPattern); diff --git a/src/org/thoughtcrime/securesms/notifications/AbstractNotificationBuilder.java b/src/org/thoughtcrime/securesms/notifications/AbstractNotificationBuilder.java index cd73ef0948..e848fe3b11 100644 --- a/src/org/thoughtcrime/securesms/notifications/AbstractNotificationBuilder.java +++ b/src/org/thoughtcrime/securesms/notifications/AbstractNotificationBuilder.java @@ -22,6 +22,8 @@ public abstract class AbstractNotificationBuilder extends NotificationCompat.Bui @SuppressWarnings("unused") private static final String TAG = AbstractNotificationBuilder.class.getSimpleName(); + private static final int MAX_DISPLAY_LENGTH = 500; + protected Context context; protected NotificationPrivacyPreference privacy; @@ -74,7 +76,7 @@ public abstract class AbstractNotificationBuilder extends NotificationCompat.Bui public void setTicker(@NonNull Recipient recipient, @Nullable CharSequence message) { if (privacy.isDisplayMessage()) { - setTicker(getStyledMessage(recipient, message)); + setTicker(getStyledMessage(recipient, trimToDisplayLength(message))); } else if (privacy.isDisplayContact()) { setTicker(getStyledMessage(recipient, context.getString(R.string.AbstractNotificationBuilder_new_message))); } else { @@ -88,4 +90,11 @@ public abstract class AbstractNotificationBuilder extends NotificationCompat.Bui return blinkPattern.split(","); } + + protected @NonNull CharSequence trimToDisplayLength(@Nullable CharSequence text) { + text = text == null ? "" : text; + + return text.length() <= MAX_DISPLAY_LENGTH ? text + : text.subSequence(0, MAX_DISPLAY_LENGTH); + } } diff --git a/src/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.java b/src/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.java index 59c9f168f8..7daca4a107 100644 --- a/src/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.java +++ b/src/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.java @@ -81,7 +81,7 @@ public class MultipleRecipientNotificationBuilder extends AbstractNotificationBu NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); for (CharSequence body : messageBodies) { - style.addLine(body); + style.addLine(trimToDisplayLength(body)); } setStyle(style); diff --git a/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java b/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java index 702d70015c..c1322e90c1 100644 --- a/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java +++ b/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java @@ -257,15 +257,15 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil } public NotificationCompat.Builder setContentText(CharSequence contentText) { - this.contentText = contentText; - return super.setContentText(contentText); + this.contentText = trimToDisplayLength(contentText); + return super.setContentText(this.contentText); } private CharSequence getBigText(List messageBodies) { SpannableStringBuilder content = new SpannableStringBuilder(); for (int i = 0; i < messageBodies.size(); i++) { - content.append(messageBodies.get(i)); + content.append(trimToDisplayLength(messageBodies.get(i))); if (i < messageBodies.size() - 1) { content.append('\n'); }