2012-07-19 14:22:03 -07:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2012-08-03 17:34:09 -07:00
|
|
|
import android.app.Activity;
|
2012-07-19 14:22:03 -07:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.database.Cursor;
|
2014-11-08 11:35:58 -08:00
|
|
|
import android.os.AsyncTask;
|
2012-07-19 14:22:03 -07:00
|
|
|
import android.os.Bundle;
|
2014-06-28 20:40:57 -07:00
|
|
|
import android.support.v4.app.ListFragment;
|
2012-07-19 14:22:03 -07:00
|
|
|
import android.support.v4.app.LoaderManager;
|
|
|
|
import android.support.v4.content.Loader;
|
2014-11-12 11:15:05 -08:00
|
|
|
import android.support.v4.widget.CursorAdapter;
|
2015-06-09 07:37:20 -07:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
2014-06-28 20:40:57 -07:00
|
|
|
import android.support.v7.view.ActionMode;
|
2012-07-19 14:22:03 -07:00
|
|
|
import android.text.ClipboardManager;
|
2014-06-11 18:03:01 -07:00
|
|
|
import android.util.Log;
|
2012-07-19 14:22:03 -07:00
|
|
|
import android.view.LayoutInflater;
|
2014-06-28 20:40:57 -07:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2012-07-19 14:22:03 -07:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2014-06-12 19:22:57 +02:00
|
|
|
import android.widget.AdapterView;
|
2014-03-26 15:11:56 -07:00
|
|
|
import android.widget.ListView;
|
2014-06-11 18:03:01 -07:00
|
|
|
import android.widget.Toast;
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2015-03-24 13:44:22 +01:00
|
|
|
import com.afollestad.materialdialogs.AlertDialogWrapper;
|
|
|
|
|
2014-11-12 11:15:05 -08:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2012-07-19 14:22:03 -07:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
2015-01-15 13:35:35 -08:00
|
|
|
import org.thoughtcrime.securesms.database.MmsSmsDatabase;
|
2012-07-19 14:22:03 -07:00
|
|
|
import org.thoughtcrime.securesms.database.loaders.ConversationLoader;
|
2014-06-11 18:03:01 -07:00
|
|
|
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
2012-10-28 16:04:24 -07:00
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
2014-06-11 18:03:01 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.Slide;
|
2014-03-07 12:39:16 -08:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
2012-07-19 14:22:03 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
2013-10-13 12:53:41 +02:00
|
|
|
import org.thoughtcrime.securesms.sms.MessageSender;
|
2014-03-07 12:39:16 -08:00
|
|
|
import org.thoughtcrime.securesms.util.DirectoryHelper;
|
2014-11-12 11:15:05 -08:00
|
|
|
import org.thoughtcrime.securesms.util.FutureTaskListener;
|
2014-12-13 18:10:59 -08:00
|
|
|
import org.thoughtcrime.securesms.util.ProgressDialogAsyncTask;
|
2014-08-12 12:11:23 -07:00
|
|
|
import org.thoughtcrime.securesms.util.SaveAttachmentTask;
|
|
|
|
import org.thoughtcrime.securesms.util.SaveAttachmentTask.Attachment;
|
2014-11-03 15:16:04 -08:00
|
|
|
|
2014-12-13 18:10:59 -08:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2015-03-19 13:08:48 -07:00
|
|
|
import java.util.Locale;
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2014-06-28 20:40:57 -07:00
|
|
|
public class ConversationFragment extends ListFragment
|
2012-07-19 14:22:03 -07:00
|
|
|
implements LoaderManager.LoaderCallbacks<Cursor>
|
|
|
|
{
|
2014-06-11 18:03:01 -07:00
|
|
|
private static final String TAG = ConversationFragment.class.getSimpleName();
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2014-12-13 18:10:59 -08:00
|
|
|
private final ActionModeCallback actionModeCallback = new ActionModeCallback();
|
2015-03-08 11:37:18 -07:00
|
|
|
private final SelectionClickListener selectionClickListener = new ConversationFragmentSelectionClickListener();
|
2014-12-13 18:10:59 -08:00
|
|
|
|
2012-08-03 17:34:09 -07:00
|
|
|
private ConversationFragmentListener listener;
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
private MasterSecret masterSecret;
|
|
|
|
private Recipients recipients;
|
|
|
|
private long threadId;
|
2014-06-12 19:22:57 +02:00
|
|
|
private ActionMode actionMode;
|
2015-03-19 13:08:48 -07:00
|
|
|
private Locale locale;
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2014-12-15 12:25:55 -08:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle icicle) {
|
|
|
|
super.onCreate(icicle);
|
|
|
|
this.masterSecret = getArguments().getParcelable("master_secret");
|
2015-03-19 13:08:48 -07:00
|
|
|
this.locale = (Locale) getArguments().getSerializable(PassphraseRequiredActionBarActivity.LOCALE_EXTRA);
|
2014-12-15 12:25:55 -08:00
|
|
|
}
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
|
|
|
|
return inflater.inflate(R.layout.conversation_fragment, container, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityCreated(Bundle bundle) {
|
|
|
|
super.onActivityCreated(bundle);
|
|
|
|
|
|
|
|
initializeResources();
|
|
|
|
initializeListAdapter();
|
2014-06-12 19:22:57 +02:00
|
|
|
initializeContextualActionBar();
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-12 19:22:57 +02:00
|
|
|
public void onAttach(Activity activity) {
|
|
|
|
super.onAttach(activity);
|
|
|
|
this.listener = (ConversationFragmentListener)activity;
|
|
|
|
}
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2015-03-05 15:51:23 -08:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
|
|
|
if (getListAdapter() != null) {
|
|
|
|
((ConversationAdapter) getListAdapter()).notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-24 18:32:51 -08:00
|
|
|
public void onNewIntent() {
|
|
|
|
if (actionMode != null) {
|
|
|
|
actionMode.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
initializeResources();
|
|
|
|
initializeListAdapter();
|
2015-04-03 14:54:47 -07:00
|
|
|
|
|
|
|
if (threadId == -1) {
|
|
|
|
getLoaderManager().restartLoader(0, null, this);
|
|
|
|
}
|
2014-12-24 18:32:51 -08:00
|
|
|
}
|
|
|
|
|
2014-06-12 19:22:57 +02:00
|
|
|
private void initializeResources() {
|
2014-12-17 18:14:19 -08:00
|
|
|
this.recipients = RecipientFactory.getRecipientsForIds(getActivity(), getActivity().getIntent().getLongArrayExtra("recipients"), true);
|
2014-06-12 19:22:57 +02:00
|
|
|
this.threadId = this.getActivity().getIntent().getLongExtra("thread_id", -1);
|
|
|
|
}
|
2014-06-11 18:03:01 -07:00
|
|
|
|
2014-06-12 19:22:57 +02:00
|
|
|
private void initializeListAdapter() {
|
|
|
|
if (this.recipients != null && this.threadId != -1) {
|
2015-03-19 13:08:48 -07:00
|
|
|
this.setListAdapter(new ConversationAdapter(getActivity(), masterSecret, locale, selectionClickListener,
|
2014-06-12 19:22:57 +02:00
|
|
|
(!this.recipients.isSingleRecipient()) || this.recipients.isGroupRecipient(),
|
|
|
|
DirectoryHelper.isPushDestination(getActivity(), this.recipients)));
|
|
|
|
getListView().setRecyclerListener((ConversationAdapter)getListAdapter());
|
2015-03-05 16:06:11 -08:00
|
|
|
getLoaderManager().restartLoader(0, null, this);
|
2013-10-13 12:53:41 +02:00
|
|
|
}
|
2014-06-12 19:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeContextualActionBar() {
|
2014-12-13 18:10:59 -08:00
|
|
|
getListView().setOnItemClickListener(selectionClickListener);
|
|
|
|
getListView().setOnItemLongClickListener(selectionClickListener);
|
2014-06-12 19:22:57 +02:00
|
|
|
}
|
|
|
|
|
2014-12-13 18:10:59 -08:00
|
|
|
private void setCorrectMenuVisibility(Menu menu) {
|
|
|
|
List<MessageRecord> messageRecords = getSelectedMessageRecords();
|
2014-06-12 19:22:57 +02:00
|
|
|
|
2014-12-13 18:10:59 -08:00
|
|
|
if (actionMode != null && messageRecords.size() == 0) {
|
|
|
|
actionMode.finish();
|
|
|
|
return;
|
|
|
|
}
|
2014-06-11 18:03:01 -07:00
|
|
|
|
2014-12-13 18:10:59 -08:00
|
|
|
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);
|
2014-06-12 19:22:57 +02:00
|
|
|
} else {
|
2014-12-13 18:10:59 -08:00
|
|
|
MessageRecord messageRecord = messageRecords.get(0);
|
|
|
|
|
|
|
|
menu.findItem(R.id.menu_context_resend).setVisible(messageRecord.isFailed());
|
|
|
|
menu.findItem(R.id.menu_context_save_attachment).setVisible(messageRecord.isMms() &&
|
|
|
|
!messageRecord.isMmsNotification() &&
|
|
|
|
((MediaMmsMessageRecord)messageRecord).containsMediaSlide());
|
|
|
|
|
|
|
|
menu.findItem(R.id.menu_context_forward).setVisible(true);
|
|
|
|
menu.findItem(R.id.menu_context_details).setVisible(true);
|
|
|
|
menu.findItem(R.id.menu_context_copy).setVisible(true);
|
2014-06-11 18:03:01 -07:00
|
|
|
}
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
2014-12-13 18:10:59 -08:00
|
|
|
private MessageRecord getSelectedMessageRecord() {
|
|
|
|
List<MessageRecord> messageRecords = getSelectedMessageRecords();
|
|
|
|
|
|
|
|
if (messageRecords.size() == 1) return messageRecords.get(0);
|
|
|
|
else throw new AssertionError();
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<MessageRecord> getSelectedMessageRecords() {
|
|
|
|
return new LinkedList<>(((ConversationAdapter)getListAdapter()).getBatchSelected());
|
2013-10-13 12:53:41 +02:00
|
|
|
}
|
|
|
|
|
2012-07-31 16:27:58 -07:00
|
|
|
public void reload(Recipients recipients, long threadId) {
|
|
|
|
this.recipients = recipients;
|
|
|
|
|
2015-03-05 16:06:11 -08:00
|
|
|
if (this.threadId != threadId) {
|
|
|
|
this.threadId = threadId;
|
|
|
|
initializeListAdapter();
|
|
|
|
}
|
2012-07-31 16:27:58 -07:00
|
|
|
}
|
|
|
|
|
2014-03-26 15:11:56 -07:00
|
|
|
public void scrollToBottom() {
|
|
|
|
final ListView list = getListView();
|
|
|
|
list.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
list.setSelection(getListAdapter().getCount() - 1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
private void handleCopyMessage(MessageRecord message) {
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
String body = message.getDisplayBody().toString();
|
2012-07-19 14:22:03 -07:00
|
|
|
if (body == null) return;
|
|
|
|
|
|
|
|
ClipboardManager clipboard = (ClipboardManager)getActivity()
|
|
|
|
.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
clipboard.setText(body);
|
|
|
|
}
|
|
|
|
|
2014-12-13 18:10:59 -08:00
|
|
|
private void handleDeleteMessages(final List<MessageRecord> messageRecords) {
|
2015-03-24 13:44:22 +01:00
|
|
|
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(getActivity());
|
2012-09-22 21:53:56 +02:00
|
|
|
builder.setTitle(R.string.ConversationFragment_confirm_message_delete);
|
2015-03-24 13:44:22 +01:00
|
|
|
builder.setIconAttribute(R.attr.dialog_alert_icon);
|
2012-07-19 14:22:03 -07:00
|
|
|
builder.setCancelable(true);
|
2014-12-13 18:10:59 -08:00
|
|
|
builder.setMessage(R.string.ConversationFragment_are_you_sure_you_want_to_permanently_delete_all_selected_messages);
|
2012-07-19 14:22:03 -07:00
|
|
|
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2014-12-13 18:10:59 -08:00
|
|
|
new ProgressDialogAsyncTask<MessageRecord, Void, Void>(getActivity(),
|
|
|
|
R.string.ConversationFragment_deleting,
|
|
|
|
R.string.ConversationFragment_deleting_messages)
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(MessageRecord... messageRecords) {
|
|
|
|
for (MessageRecord messageRecord : messageRecords) {
|
2015-03-31 13:36:04 -07:00
|
|
|
boolean threadDeleted;
|
|
|
|
|
2014-12-13 18:10:59 -08:00
|
|
|
if (messageRecord.isMms()) {
|
2015-03-31 13:36:04 -07:00
|
|
|
threadDeleted = DatabaseFactory.getMmsDatabase(getActivity()).delete(messageRecord.getId());
|
2014-12-13 18:10:59 -08:00
|
|
|
} else {
|
2015-03-31 13:36:04 -07:00
|
|
|
threadDeleted = DatabaseFactory.getSmsDatabase(getActivity()).deleteMessage(messageRecord.getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (threadDeleted) {
|
|
|
|
threadId = -1;
|
|
|
|
listener.setThreadId(threadId);
|
2014-12-13 18:10:59 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.execute(messageRecords.toArray(new MessageRecord[messageRecords.size()]));
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
builder.setNegativeButton(R.string.no, null);
|
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleDisplayDetails(MessageRecord message) {
|
2015-01-15 13:35:35 -08:00
|
|
|
Intent intent = new Intent(getActivity(), MessageDetailsActivity.class);
|
|
|
|
intent.putExtra(MessageDetailsActivity.MASTER_SECRET_EXTRA, masterSecret);
|
|
|
|
intent.putExtra(MessageDetailsActivity.MESSAGE_ID_EXTRA, message.getId());
|
|
|
|
intent.putExtra(MessageDetailsActivity.TYPE_EXTRA, message.isMms() ? MmsSmsDatabase.MMS_TRANSPORT : MmsSmsDatabase.SMS_TRANSPORT);
|
|
|
|
startActivity(intent);
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private void handleForwardMessage(MessageRecord message) {
|
2014-02-27 22:44:02 -08:00
|
|
|
Intent composeIntent = new Intent(getActivity(), ShareActivity.class);
|
2015-04-02 11:23:18 -07:00
|
|
|
composeIntent.putExtra(Intent.EXTRA_TEXT, message.getDisplayBody().toString());
|
2012-07-19 14:22:03 -07:00
|
|
|
startActivity(composeIntent);
|
|
|
|
}
|
|
|
|
|
2014-11-08 11:35:58 -08:00
|
|
|
private void handleResendMessage(final MessageRecord message) {
|
|
|
|
final Context context = getActivity().getApplicationContext();
|
|
|
|
new AsyncTask<MessageRecord, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(MessageRecord... messageRecords) {
|
|
|
|
MessageSender.resend(context, masterSecret, messageRecords[0]);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.execute(message);
|
2013-10-13 12:53:41 +02:00
|
|
|
}
|
|
|
|
|
2014-08-12 12:11:23 -07:00
|
|
|
private void handleSaveAttachment(final MediaMmsMessageRecord message) {
|
|
|
|
SaveAttachmentTask.showWarningDialog(getActivity(), new DialogInterface.OnClickListener() {
|
2014-06-11 18:03:01 -07:00
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2014-08-12 12:11:23 -07:00
|
|
|
|
2014-10-28 02:23:00 -05:00
|
|
|
message.fetchMediaSlide(new FutureTaskListener<Slide>() {
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Slide slide) {
|
|
|
|
SaveAttachmentTask saveTask = new SaveAttachmentTask(getActivity(), masterSecret);
|
|
|
|
saveTask.execute(new Attachment(slide.getUri(), slide.getContentType(), message.getDateReceived()));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable error) {
|
|
|
|
Log.w(TAG, "No slide with attachable media found, failing nicely.");
|
|
|
|
Log.w(TAG, error);
|
|
|
|
Toast.makeText(getActivity(), R.string.ConversationFragment_error_while_saving_attachment_to_sd_card, Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
});
|
2014-06-11 18:03:01 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
@Override
|
|
|
|
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
2013-04-25 18:59:49 -07:00
|
|
|
return new ConversationLoader(getActivity(), threadId);
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
|
2015-04-13 11:49:08 -07:00
|
|
|
if (getListAdapter() != null) {
|
|
|
|
((CursorAdapter) getListAdapter()).changeCursor(cursor);
|
|
|
|
}
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoaderReset(Loader<Cursor> arg0) {
|
2015-04-13 11:49:08 -07:00
|
|
|
if (getListAdapter() != null) {
|
|
|
|
((CursorAdapter) getListAdapter()).changeCursor(null);
|
|
|
|
}
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
2012-08-03 17:34:09 -07:00
|
|
|
public interface ConversationFragmentListener {
|
|
|
|
public void setComposeText(String text);
|
2015-03-31 13:36:04 -07:00
|
|
|
|
|
|
|
public void setThreadId(long threadId);
|
2012-08-03 17:34:09 -07:00
|
|
|
}
|
|
|
|
|
2015-03-08 11:37:18 -07:00
|
|
|
public interface SelectionClickListener extends
|
|
|
|
AdapterView.OnItemLongClickListener, AdapterView.OnItemClickListener {}
|
|
|
|
|
|
|
|
private class ConversationFragmentSelectionClickListener
|
|
|
|
implements SelectionClickListener
|
2014-12-13 18:10:59 -08:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
if (actionMode != null && view instanceof ConversationItem) {
|
|
|
|
MessageRecord messageRecord = ((ConversationItem)view).getMessageRecord();
|
|
|
|
((ConversationAdapter) getListAdapter()).toggleBatchSelected(messageRecord);
|
|
|
|
((ConversationAdapter) getListAdapter()).notifyDataSetChanged();
|
|
|
|
|
|
|
|
setCorrectMenuVisibility(actionMode.getMenu());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
if (actionMode == null && view instanceof ConversationItem) {
|
|
|
|
MessageRecord messageRecord = ((ConversationItem)view).getMessageRecord();
|
|
|
|
((ConversationAdapter) getListAdapter()).toggleBatchSelected(messageRecord);
|
|
|
|
((ConversationAdapter) getListAdapter()).notifyDataSetChanged();
|
|
|
|
|
2015-06-09 07:37:20 -07:00
|
|
|
actionMode = ((AppCompatActivity)getActivity()).startSupportActionMode(actionModeCallback);
|
2014-12-13 18:10:59 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class ActionModeCallback implements ActionMode.Callback {
|
2014-06-12 19:22:57 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
|
|
MenuInflater inflater = mode.getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.conversation_context, menu);
|
|
|
|
|
2014-12-13 18:10:59 -08:00
|
|
|
setCorrectMenuVisibility(menu);
|
2014-06-12 19:22:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {
|
2014-12-13 18:10:59 -08:00
|
|
|
((ConversationAdapter)getListAdapter()).getBatchSelected().clear();
|
|
|
|
((ConversationAdapter)getListAdapter()).notifyDataSetChanged();
|
|
|
|
|
2014-06-12 19:22:57 +02:00
|
|
|
actionMode = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
|
|
switch(item.getItemId()) {
|
|
|
|
case R.id.menu_context_copy:
|
2014-12-13 18:10:59 -08:00
|
|
|
handleCopyMessage(getSelectedMessageRecord());
|
2014-06-12 19:22:57 +02:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
|
|
|
case R.id.menu_context_delete_message:
|
2014-12-13 18:10:59 -08:00
|
|
|
handleDeleteMessages(getSelectedMessageRecords());
|
2014-06-12 19:22:57 +02:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
|
|
|
case R.id.menu_context_details:
|
2014-12-13 18:10:59 -08:00
|
|
|
handleDisplayDetails(getSelectedMessageRecord());
|
2014-06-12 19:22:57 +02:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
|
|
|
case R.id.menu_context_forward:
|
2014-12-13 18:10:59 -08:00
|
|
|
handleForwardMessage(getSelectedMessageRecord());
|
2014-06-12 19:22:57 +02:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
|
|
|
case R.id.menu_context_resend:
|
2014-12-13 18:10:59 -08:00
|
|
|
handleResendMessage(getSelectedMessageRecord());
|
2014-06-12 19:22:57 +02:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
|
|
|
case R.id.menu_context_save_attachment:
|
2014-12-13 18:10:59 -08:00
|
|
|
handleSaveAttachment((MediaMmsMessageRecord)getSelectedMessageRecord());
|
2014-06-12 19:22:57 +02:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2014-03-06 14:41:36 +10:30
|
|
|
}
|