From b8fbc91f33591df10579a9e996221f811c3ef1da Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Tue, 3 Apr 2018 09:58:06 -0700 Subject: [PATCH] Only show copy if text is selected, remove newlines from copied text. We now check if _any_ text is selected when doing a batch selection to determine if we should show the copy option. Also, previously it was putting in empty lines for messages that don't have any text. I changed it so empty messages have no effect on the text that is copied. Fixes #7472 --- .../securesms/ConversationFragment.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationFragment.java b/src/org/thoughtcrime/securesms/ConversationFragment.java index 46191f985..eda7a8250 100644 --- a/src/org/thoughtcrime/securesms/ConversationFragment.java +++ b/src/org/thoughtcrime/securesms/ConversationFragment.java @@ -201,7 +201,7 @@ public class ConversationFragment extends Fragment private void setCorrectMenuVisibility(Menu menu) { Set messageRecords = getListAdapter().getSelectedItems(); boolean actionMessage = false; - boolean mediaMessage = false; + boolean hasText = false; if (actionMode != null && messageRecords.size() == 0) { actionMode.finish(); @@ -215,12 +215,11 @@ public class ConversationFragment extends Fragment messageRecord.isIdentityVerified() || messageRecord.isIdentityDefault()) { actionMessage = true; - break; - } else if (messageRecord.isMms() && - !messageRecord.isMmsNotification() && - ((MediaMmsMessageRecord)messageRecord).containsMediaSlide()) - { - mediaMessage = true; + } + if (messageRecord.getBody().length() > 0) { + hasText = true; + } + if (actionMessage && hasText) { break; } } @@ -230,7 +229,6 @@ public class ConversationFragment extends Fragment menu.findItem(R.id.menu_context_details).setVisible(false); menu.findItem(R.id.menu_context_save_attachment).setVisible(false); menu.findItem(R.id.menu_context_resend).setVisible(false); - menu.findItem(R.id.menu_context_copy).setVisible(!actionMessage && !mediaMessage); } else { MessageRecord messageRecord = messageRecords.iterator().next(); @@ -242,8 +240,8 @@ public class ConversationFragment extends Fragment menu.findItem(R.id.menu_context_forward).setVisible(!actionMessage); menu.findItem(R.id.menu_context_details).setVisible(!actionMessage); - menu.findItem(R.id.menu_context_copy).setVisible(!actionMessage && !mediaMessage); } + menu.findItem(R.id.menu_context_copy).setVisible(!actionMessage && hasText); } private ConversationAdapter getListAdapter() { @@ -293,17 +291,16 @@ public class ConversationFragment extends Fragment StringBuilder bodyBuilder = new StringBuilder(); ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); - boolean first = true; for (MessageRecord messageRecord : messageList) { String body = messageRecord.getDisplayBody().toString(); - - if (body != null) { - if (!first) bodyBuilder.append('\n'); - bodyBuilder.append(body); - first = false; + if (!TextUtils.isEmpty(body)) { + bodyBuilder.append(body).append('\n'); } } + if (bodyBuilder.length() > 0 && bodyBuilder.charAt(bodyBuilder.length() - 1) == '\n') { + bodyBuilder.deleteCharAt(bodyBuilder.length() - 1); + } String result = bodyBuilder.toString();