mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +00:00
Add support to copy multiple messages
Fixes #3748 Closes #3798 // FREEBIE
This commit is contained in:
parent
00eb637e51
commit
a3a7f8fb6c
@ -15,6 +15,7 @@ import android.support.v4.widget.CursorAdapter;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.view.ActionMode;
|
||||
import android.text.ClipboardManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
@ -44,7 +45,10 @@ import org.thoughtcrime.securesms.util.FutureTaskListener;
|
||||
import org.thoughtcrime.securesms.util.ProgressDialogAsyncTask;
|
||||
import org.thoughtcrime.securesms.util.SaveAttachmentTask;
|
||||
import org.thoughtcrime.securesms.util.SaveAttachmentTask.Attachment;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@ -144,7 +148,6 @@ public class ConversationFragment extends ListFragment
|
||||
|
||||
if (messageRecords.size() > 1) {
|
||||
menu.findItem(R.id.menu_context_forward).setVisible(false);
|
||||
menu.findItem(R.id.menu_context_copy).setVisible(false);
|
||||
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);
|
||||
@ -192,13 +195,34 @@ public class ConversationFragment extends ListFragment
|
||||
});
|
||||
}
|
||||
|
||||
private void handleCopyMessage(MessageRecord message) {
|
||||
String body = message.getDisplayBody().toString();
|
||||
if (body == null) return;
|
||||
private void handleCopyMessage(final List<MessageRecord> messageRecords) {
|
||||
Collections.sort(messageRecords, new Comparator<MessageRecord>() {
|
||||
@Override
|
||||
public int compare(MessageRecord lhs, MessageRecord rhs) {
|
||||
if (lhs.getDateReceived() < rhs.getDateReceived()) return -1;
|
||||
else if (lhs.getDateReceived() == rhs.getDateReceived()) return 0;
|
||||
else return 1;
|
||||
}
|
||||
});
|
||||
|
||||
ClipboardManager clipboard = (ClipboardManager)getActivity()
|
||||
.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
clipboard.setText(body);
|
||||
StringBuilder bodyBuilder = new StringBuilder();
|
||||
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
boolean first = true;
|
||||
|
||||
for (MessageRecord messageRecord : messageRecords) {
|
||||
String body = messageRecord.getDisplayBody().toString();
|
||||
|
||||
if (body != null) {
|
||||
if (!first) bodyBuilder.append('\n');
|
||||
bodyBuilder.append(body);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
String result = bodyBuilder.toString();
|
||||
|
||||
if (!TextUtils.isEmpty(result))
|
||||
clipboard.setText(result);
|
||||
}
|
||||
|
||||
private void handleDeleteMessages(final List<MessageRecord> messageRecords) {
|
||||
@ -385,7 +409,7 @@ public class ConversationFragment extends ListFragment
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
switch(item.getItemId()) {
|
||||
case R.id.menu_context_copy:
|
||||
handleCopyMessage(getSelectedMessageRecord());
|
||||
handleCopyMessage(getSelectedMessageRecords());
|
||||
actionMode.finish();
|
||||
return true;
|
||||
case R.id.menu_context_delete_message:
|
||||
|
Loading…
Reference in New Issue
Block a user