2015-11-05 16:47:29 +00:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2015 Open Whisper Systems
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2012-07-19 21:22:03 +00:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2012-08-04 00:34:09 +00:00
|
|
|
import android.app.Activity;
|
2012-07-19 21:22:03 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.database.Cursor;
|
2014-11-08 19:35:58 +00:00
|
|
|
import android.os.AsyncTask;
|
2015-07-07 21:46:21 +00:00
|
|
|
import android.os.Build;
|
2012-07-19 21:22:03 +00:00
|
|
|
import android.os.Bundle;
|
2015-09-15 22:28:27 +00:00
|
|
|
import android.support.v4.app.Fragment;
|
2012-07-19 21:22:03 +00:00
|
|
|
import android.support.v4.app.LoaderManager;
|
|
|
|
import android.support.v4.content.Loader;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
2015-05-20 21:36:30 +00:00
|
|
|
import android.support.v7.app.AlertDialog;
|
2014-06-29 03:40:57 +00:00
|
|
|
import android.support.v7.view.ActionMode;
|
2015-09-15 22:28:27 +00:00
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
2015-11-24 01:22:10 +00:00
|
|
|
import android.support.v7.widget.RecyclerView.ItemAnimator.ItemAnimatorFinishedListener;
|
2012-07-19 21:22:03 +00:00
|
|
|
import android.text.ClipboardManager;
|
2015-07-26 00:35:28 +00:00
|
|
|
import android.text.TextUtils;
|
2014-06-12 01:03:01 +00:00
|
|
|
import android.util.Log;
|
2012-07-19 21:22:03 +00:00
|
|
|
import android.view.LayoutInflater;
|
2014-06-29 03:40:57 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2012-07-19 21:22:03 +00:00
|
|
|
import android.view.View;
|
2015-08-04 19:29:26 +00:00
|
|
|
import android.view.View.OnClickListener;
|
2012-07-19 21:22:03 +00:00
|
|
|
import android.view.ViewGroup;
|
2015-07-07 21:46:21 +00:00
|
|
|
import android.view.Window;
|
2014-06-12 01:03:01 +00:00
|
|
|
import android.widget.Toast;
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
import org.thoughtcrime.securesms.ConversationAdapter.ItemClickListener;
|
2014-11-12 19:15:05 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2012-07-19 21:22:03 +00:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
2015-01-15 21:35:35 +00:00
|
|
|
import org.thoughtcrime.securesms.database.MmsSmsDatabase;
|
2012-07-19 21:22:03 +00:00
|
|
|
import org.thoughtcrime.securesms.database.loaders.ConversationLoader;
|
2014-06-12 01:03:01 +00:00
|
|
|
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
2012-10-28 23:04:24 +00:00
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
2014-06-12 01:03:01 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.Slide;
|
2014-03-07 20:39:16 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
2012-07-19 21:22:03 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
2013-10-13 10:53:41 +00:00
|
|
|
import org.thoughtcrime.securesms.sms.MessageSender;
|
2015-11-23 23:07:41 +00:00
|
|
|
import org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask;
|
2014-08-12 19:11:23 +00:00
|
|
|
import org.thoughtcrime.securesms.util.SaveAttachmentTask;
|
|
|
|
import org.thoughtcrime.securesms.util.SaveAttachmentTask.Attachment;
|
2015-09-15 22:28:27 +00:00
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
2014-11-03 23:16:04 +00:00
|
|
|
|
2015-07-26 00:35:28 +00:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
2014-12-14 02:10:59 +00:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2015-03-19 20:08:48 +00:00
|
|
|
import java.util.Locale;
|
2015-09-15 22:28:27 +00:00
|
|
|
import java.util.Set;
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
public class ConversationFragment extends Fragment
|
2012-07-19 21:22:03 +00:00
|
|
|
implements LoaderManager.LoaderCallbacks<Cursor>
|
|
|
|
{
|
2014-06-12 01:03:01 +00:00
|
|
|
private static final String TAG = ConversationFragment.class.getSimpleName();
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2015-08-04 19:29:26 +00:00
|
|
|
private static final long PARTIAL_CONVERSATION_LIMIT = 500L;
|
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
private final ActionModeCallback actionModeCallback = new ActionModeCallback();
|
|
|
|
private final ItemClickListener selectionClickListener = new ConversationFragmentItemClickListener();
|
2014-12-14 02:10:59 +00:00
|
|
|
|
2012-08-04 00:34:09 +00:00
|
|
|
private ConversationFragmentListener listener;
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
private MasterSecret masterSecret;
|
|
|
|
private Recipients recipients;
|
|
|
|
private long threadId;
|
2014-06-12 17:22:57 +00:00
|
|
|
private ActionMode actionMode;
|
2015-03-19 20:08:48 +00:00
|
|
|
private Locale locale;
|
2015-09-15 22:28:27 +00:00
|
|
|
private RecyclerView list;
|
2015-08-04 19:29:26 +00:00
|
|
|
private View loadMoreView;
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle icicle) {
|
|
|
|
super.onCreate(icicle);
|
|
|
|
this.masterSecret = getArguments().getParcelable("master_secret");
|
2015-03-19 20:08:48 +00:00
|
|
|
this.locale = (Locale) getArguments().getSerializable(PassphraseRequiredActionBarActivity.LOCALE_EXTRA);
|
2014-12-15 20:25:55 +00:00
|
|
|
}
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
|
2015-09-15 22:28:27 +00:00
|
|
|
final View view = inflater.inflate(R.layout.conversation_fragment, container, false);
|
|
|
|
list = ViewUtil.findById(view, android.R.id.list);
|
2015-08-04 19:29:26 +00:00
|
|
|
final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, true);
|
|
|
|
list.setHasFixedSize(false);
|
|
|
|
list.setLayoutManager(layoutManager);
|
|
|
|
|
|
|
|
loadMoreView = inflater.inflate(R.layout.load_more_header, container, false);
|
|
|
|
loadMoreView.setOnClickListener(new OnClickListener() {
|
2015-11-18 20:54:40 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-08-04 19:29:26 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("limit", 0);
|
|
|
|
getLoaderManager().restartLoader(0, args, ConversationFragment.this);
|
|
|
|
}
|
|
|
|
});
|
2015-09-15 22:28:27 +00:00
|
|
|
return view;
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityCreated(Bundle bundle) {
|
|
|
|
super.onActivityCreated(bundle);
|
|
|
|
|
|
|
|
initializeResources();
|
|
|
|
initializeListAdapter();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-12 17:22:57 +00:00
|
|
|
public void onAttach(Activity activity) {
|
|
|
|
super.onAttach(activity);
|
|
|
|
this.listener = (ConversationFragmentListener)activity;
|
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2015-03-05 23:51:23 +00:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
if (list.getAdapter() != null) {
|
|
|
|
list.getAdapter().notifyDataSetChanged();
|
2015-03-05 23:51:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-25 02:32:51 +00:00
|
|
|
public void onNewIntent() {
|
|
|
|
if (actionMode != null) {
|
|
|
|
actionMode.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
initializeResources();
|
|
|
|
initializeListAdapter();
|
2015-04-03 21:54:47 +00:00
|
|
|
|
|
|
|
if (threadId == -1) {
|
2015-08-04 19:29:26 +00:00
|
|
|
getLoaderManager().restartLoader(0, Bundle.EMPTY, this);
|
2015-04-03 21:54:47 +00:00
|
|
|
}
|
2014-12-25 02:32:51 +00:00
|
|
|
}
|
|
|
|
|
2015-10-16 13:39:27 +00:00
|
|
|
public void reloadList() {
|
2015-12-13 01:37:16 +00:00
|
|
|
getLoaderManager().restartLoader(0, Bundle.EMPTY, this);
|
2015-10-16 13:39:27 +00:00
|
|
|
}
|
|
|
|
|
2014-06-12 17:22:57 +00:00
|
|
|
private void initializeResources() {
|
2015-08-04 19:29:26 +00:00
|
|
|
this.recipients = RecipientFactory.getRecipientsForIds(getActivity(), getActivity().getIntent().getLongArrayExtra("recipients"), true);
|
|
|
|
this.threadId = this.getActivity().getIntent().getLongExtra("thread_id", -1);
|
2014-06-12 17:22:57 +00:00
|
|
|
}
|
2014-06-12 01:03:01 +00:00
|
|
|
|
2014-06-12 17:22:57 +00:00
|
|
|
private void initializeListAdapter() {
|
|
|
|
if (this.recipients != null && this.threadId != -1) {
|
2015-10-21 22:32:29 +00:00
|
|
|
list.setAdapter(new ConversationAdapter(getActivity(), masterSecret, locale, selectionClickListener, null, this.recipients));
|
2015-08-04 19:29:26 +00:00
|
|
|
getLoaderManager().restartLoader(0, Bundle.EMPTY, this);
|
2015-11-24 01:22:10 +00:00
|
|
|
list.getItemAnimator().setSupportsChangeAnimations(false);
|
|
|
|
list.getItemAnimator().setMoveDuration(120);
|
2013-10-13 10:53:41 +00:00
|
|
|
}
|
2014-06-12 17:22:57 +00:00
|
|
|
}
|
|
|
|
|
2014-12-14 02:10:59 +00:00
|
|
|
private void setCorrectMenuVisibility(Menu menu) {
|
2015-09-15 22:28:27 +00:00
|
|
|
Set<MessageRecord> messageRecords = getListAdapter().getSelectedItems();
|
2014-06-12 17:22:57 +00:00
|
|
|
|
2014-12-14 02:10:59 +00:00
|
|
|
if (actionMode != null && messageRecords.size() == 0) {
|
|
|
|
actionMode.finish();
|
|
|
|
return;
|
|
|
|
}
|
2014-06-12 01:03:01 +00:00
|
|
|
|
2014-12-14 02:10:59 +00:00
|
|
|
if (messageRecords.size() > 1) {
|
|
|
|
menu.findItem(R.id.menu_context_forward).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 17:22:57 +00:00
|
|
|
} else {
|
2015-09-15 22:28:27 +00:00
|
|
|
MessageRecord messageRecord = messageRecords.iterator().next();
|
2014-12-14 02:10:59 +00:00
|
|
|
|
|
|
|
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-12 01:03:01 +00:00
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
private ConversationAdapter getListAdapter() {
|
|
|
|
return (ConversationAdapter) list.getAdapter();
|
|
|
|
}
|
|
|
|
|
2014-12-14 02:10:59 +00:00
|
|
|
private MessageRecord getSelectedMessageRecord() {
|
2015-09-15 22:28:27 +00:00
|
|
|
Set<MessageRecord> messageRecords = getListAdapter().getSelectedItems();
|
2014-12-14 02:10:59 +00:00
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
if (messageRecords.size() == 1) return messageRecords.iterator().next();
|
2014-12-14 02:10:59 +00:00
|
|
|
else throw new AssertionError();
|
|
|
|
}
|
|
|
|
|
2012-07-31 23:27:58 +00:00
|
|
|
public void reload(Recipients recipients, long threadId) {
|
|
|
|
this.recipients = recipients;
|
|
|
|
|
2015-03-06 00:06:11 +00:00
|
|
|
if (this.threadId != threadId) {
|
|
|
|
this.threadId = threadId;
|
|
|
|
initializeListAdapter();
|
|
|
|
}
|
2012-07-31 23:27:58 +00:00
|
|
|
}
|
|
|
|
|
2014-03-26 22:11:56 +00:00
|
|
|
public void scrollToBottom() {
|
2015-11-24 01:22:10 +00:00
|
|
|
list.getItemAnimator().isRunning(new ItemAnimatorFinishedListener() {
|
2014-03-26 22:11:56 +00:00
|
|
|
@Override
|
2015-11-24 01:22:10 +00:00
|
|
|
public void onAnimationsFinished() {
|
2015-09-15 22:28:27 +00:00
|
|
|
list.stopScroll();
|
|
|
|
list.smoothScrollToPosition(0);
|
2014-03-26 22:11:56 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
private void handleCopyMessage(final Set<MessageRecord> messageRecords) {
|
|
|
|
List<MessageRecord> messageList = new LinkedList<>(messageRecords);
|
|
|
|
Collections.sort(messageList, new Comparator<MessageRecord>() {
|
2015-07-26 00:35:28 +00:00
|
|
|
@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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
StringBuilder bodyBuilder = new StringBuilder();
|
|
|
|
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
boolean first = true;
|
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
for (MessageRecord messageRecord : messageList) {
|
2015-07-26 00:35:28 +00:00
|
|
|
String body = messageRecord.getDisplayBody().toString();
|
|
|
|
|
|
|
|
if (body != null) {
|
|
|
|
if (!first) bodyBuilder.append('\n');
|
|
|
|
bodyBuilder.append(body);
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String result = bodyBuilder.toString();
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2015-07-26 00:35:28 +00:00
|
|
|
if (!TextUtils.isEmpty(result))
|
|
|
|
clipboard.setText(result);
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
private void handleDeleteMessages(final Set<MessageRecord> messageRecords) {
|
2015-05-20 21:36:30 +00:00
|
|
|
int messagesCount = messageRecords.size();
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
2015-11-04 20:29:14 +00:00
|
|
|
|
2015-03-24 12:44:22 +00:00
|
|
|
builder.setIconAttribute(R.attr.dialog_alert_icon);
|
2015-11-04 20:29:14 +00:00
|
|
|
builder.setTitle(getActivity().getResources().getQuantityString(R.plurals.ConversationFragment_delete_selected_messages, messagesCount, messagesCount));
|
|
|
|
builder.setMessage(getActivity().getResources().getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messagesCount, messagesCount));
|
2012-07-19 21:22:03 +00:00
|
|
|
builder.setCancelable(true);
|
2015-10-23 21:01:53 +00:00
|
|
|
|
2015-11-24 06:55:32 +00:00
|
|
|
builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
|
2012-07-19 21:22:03 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2014-12-14 02:10:59 +00: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 20:36:04 +00:00
|
|
|
boolean threadDeleted;
|
|
|
|
|
2014-12-14 02:10:59 +00:00
|
|
|
if (messageRecord.isMms()) {
|
2015-03-31 20:36:04 +00:00
|
|
|
threadDeleted = DatabaseFactory.getMmsDatabase(getActivity()).delete(messageRecord.getId());
|
2014-12-14 02:10:59 +00:00
|
|
|
} else {
|
2015-03-31 20:36:04 +00:00
|
|
|
threadDeleted = DatabaseFactory.getSmsDatabase(getActivity()).deleteMessage(messageRecord.getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (threadDeleted) {
|
|
|
|
threadId = -1;
|
|
|
|
listener.setThreadId(threadId);
|
2014-12-14 02:10:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.execute(messageRecords.toArray(new MessageRecord[messageRecords.size()]));
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-11-24 06:55:32 +00:00
|
|
|
builder.setNegativeButton(android.R.string.cancel, null);
|
2012-07-19 21:22:03 +00:00
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleDisplayDetails(MessageRecord message) {
|
2015-01-15 21:35:35 +00:00
|
|
|
Intent intent = new Intent(getActivity(), MessageDetailsActivity.class);
|
|
|
|
intent.putExtra(MessageDetailsActivity.MASTER_SECRET_EXTRA, masterSecret);
|
|
|
|
intent.putExtra(MessageDetailsActivity.MESSAGE_ID_EXTRA, message.getId());
|
2015-08-15 12:00:08 +00:00
|
|
|
intent.putExtra(MessageDetailsActivity.THREAD_ID_EXTRA, threadId);
|
2015-01-15 21:35:35 +00:00
|
|
|
intent.putExtra(MessageDetailsActivity.TYPE_EXTRA, message.isMms() ? MmsSmsDatabase.MMS_TRANSPORT : MmsSmsDatabase.SMS_TRANSPORT);
|
2015-11-05 16:47:29 +00:00
|
|
|
intent.putExtra(MessageDetailsActivity.RECIPIENTS_IDS_EXTRA, recipients.getIds());
|
2015-01-15 21:35:35 +00:00
|
|
|
startActivity(intent);
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void handleForwardMessage(MessageRecord message) {
|
2014-02-28 06:44:02 +00:00
|
|
|
Intent composeIntent = new Intent(getActivity(), ShareActivity.class);
|
2015-04-02 18:23:18 +00:00
|
|
|
composeIntent.putExtra(Intent.EXTRA_TEXT, message.getDisplayBody().toString());
|
2015-11-18 20:54:40 +00:00
|
|
|
if (message.isMms()) {
|
|
|
|
MediaMmsMessageRecord mediaMessage = (MediaMmsMessageRecord) message;
|
|
|
|
if (mediaMessage.containsMediaSlide()) {
|
|
|
|
Slide slide = mediaMessage.getSlideDeck().getSlides().get(0);
|
|
|
|
composeIntent.putExtra(Intent.EXTRA_STREAM, slide.getUri());
|
|
|
|
composeIntent.setType(slide.getContentType());
|
|
|
|
}
|
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
startActivity(composeIntent);
|
|
|
|
}
|
|
|
|
|
2014-11-08 19:35:58 +00: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 10:53:41 +00:00
|
|
|
}
|
|
|
|
|
2014-08-12 19:11:23 +00:00
|
|
|
private void handleSaveAttachment(final MediaMmsMessageRecord message) {
|
|
|
|
SaveAttachmentTask.showWarningDialog(getActivity(), new DialogInterface.OnClickListener() {
|
2014-06-12 01:03:01 +00:00
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2015-10-21 22:32:19 +00:00
|
|
|
for (Slide slide : message.getSlideDeck().getSlides()) {
|
|
|
|
if (slide.hasImage() || slide.hasVideo() || slide.hasAudio()) {
|
2014-10-28 07:23:00 +00:00
|
|
|
SaveAttachmentTask saveTask = new SaveAttachmentTask(getActivity(), masterSecret);
|
|
|
|
saveTask.execute(new Attachment(slide.getUri(), slide.getContentType(), message.getDateReceived()));
|
2015-10-21 22:32:19 +00:00
|
|
|
return;
|
2014-10-28 07:23:00 +00:00
|
|
|
}
|
2015-10-21 22:32:19 +00:00
|
|
|
}
|
2014-10-28 07:23:00 +00:00
|
|
|
|
2015-10-21 22:32:19 +00:00
|
|
|
Log.w(TAG, "No slide with attachable media found, failing nicely.");
|
|
|
|
Toast.makeText(getActivity(), R.string.ConversationFragment_error_while_saving_attachment_to_sd_card, Toast.LENGTH_LONG).show();
|
2014-06-12 01:03:01 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
@Override
|
2015-08-04 19:29:26 +00:00
|
|
|
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
|
|
|
return new ConversationLoader(getActivity(), threadId, args.getLong("limit", PARTIAL_CONVERSATION_LIMIT));
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-08-04 19:29:26 +00:00
|
|
|
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
|
2015-09-15 22:28:27 +00:00
|
|
|
if (list.getAdapter() != null) {
|
2015-08-04 19:29:26 +00:00
|
|
|
if (cursor.getCount() >= PARTIAL_CONVERSATION_LIMIT && ((ConversationLoader)loader).hasLimit()) {
|
|
|
|
getListAdapter().setFooterView(loadMoreView);
|
|
|
|
} else {
|
|
|
|
getListAdapter().setFooterView(null);
|
|
|
|
}
|
2015-09-15 22:28:27 +00:00
|
|
|
getListAdapter().changeCursor(cursor);
|
2015-04-13 18:49:08 +00:00
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoaderReset(Loader<Cursor> arg0) {
|
2015-09-15 22:28:27 +00:00
|
|
|
if (list.getAdapter() != null) {
|
|
|
|
getListAdapter().changeCursor(null);
|
2015-04-13 18:49:08 +00:00
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
2012-08-04 00:34:09 +00:00
|
|
|
public interface ConversationFragmentListener {
|
2015-09-15 22:28:27 +00:00
|
|
|
void setThreadId(long threadId);
|
2012-08-04 00:34:09 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
private class ConversationFragmentItemClickListener implements ItemClickListener {
|
2015-03-08 18:37:18 +00:00
|
|
|
|
2015-11-04 20:29:14 +00:00
|
|
|
@Override
|
|
|
|
public void onItemClick(ConversationItem item) {
|
2015-09-15 22:28:27 +00:00
|
|
|
if (actionMode != null) {
|
|
|
|
MessageRecord messageRecord = item.getMessageRecord();
|
|
|
|
((ConversationAdapter) list.getAdapter()).toggleSelection(messageRecord);
|
|
|
|
list.getAdapter().notifyDataSetChanged();
|
2014-12-14 02:10:59 +00:00
|
|
|
|
|
|
|
setCorrectMenuVisibility(actionMode.getMenu());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-04 20:29:14 +00:00
|
|
|
@Override
|
|
|
|
public void onItemLongClick(ConversationItem item) {
|
2015-09-15 22:28:27 +00:00
|
|
|
if (actionMode == null) {
|
|
|
|
((ConversationAdapter) list.getAdapter()).toggleSelection(item.getMessageRecord());
|
|
|
|
list.getAdapter().notifyDataSetChanged();
|
2014-12-14 02:10:59 +00:00
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
actionMode = ((AppCompatActivity)getActivity()).startSupportActionMode(actionModeCallback);
|
2014-12-14 02:10:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class ActionModeCallback implements ActionMode.Callback {
|
2014-06-12 17:22:57 +00:00
|
|
|
|
2015-07-07 21:46:21 +00:00
|
|
|
private int statusBarColor;
|
|
|
|
|
2014-06-12 17:22:57 +00:00
|
|
|
@Override
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
|
|
MenuInflater inflater = mode.getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.conversation_context, menu);
|
|
|
|
|
2015-07-07 21:46:21 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
Window window = getActivity().getWindow();
|
|
|
|
statusBarColor = window.getStatusBarColor();
|
|
|
|
window.setStatusBarColor(getResources().getColor(R.color.action_mode_status_bar));
|
|
|
|
}
|
|
|
|
|
2014-12-14 02:10:59 +00:00
|
|
|
setCorrectMenuVisibility(menu);
|
2014-06-12 17:22:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {
|
2015-09-15 22:28:27 +00:00
|
|
|
((ConversationAdapter)list.getAdapter()).clearSelection();
|
|
|
|
list.getAdapter().notifyDataSetChanged();
|
2014-12-14 02:10:59 +00:00
|
|
|
|
2015-07-07 21:46:21 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
getActivity().getWindow().setStatusBarColor(statusBarColor);
|
|
|
|
}
|
|
|
|
|
2014-06-12 17:22:57 +00:00
|
|
|
actionMode = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
|
|
switch(item.getItemId()) {
|
|
|
|
case R.id.menu_context_copy:
|
2015-09-15 22:28:27 +00:00
|
|
|
handleCopyMessage(getListAdapter().getSelectedItems());
|
2014-06-12 17:22:57 +00:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
|
|
|
case R.id.menu_context_delete_message:
|
2015-09-15 22:28:27 +00:00
|
|
|
handleDeleteMessages(getListAdapter().getSelectedItems());
|
2014-06-12 17:22:57 +00:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
|
|
|
case R.id.menu_context_details:
|
2014-12-14 02:10:59 +00:00
|
|
|
handleDisplayDetails(getSelectedMessageRecord());
|
2014-06-12 17:22:57 +00:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
|
|
|
case R.id.menu_context_forward:
|
2014-12-14 02:10:59 +00:00
|
|
|
handleForwardMessage(getSelectedMessageRecord());
|
2014-06-12 17:22:57 +00:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
|
|
|
case R.id.menu_context_resend:
|
2014-12-14 02:10:59 +00:00
|
|
|
handleResendMessage(getSelectedMessageRecord());
|
2014-06-12 17:22:57 +00:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
|
|
|
case R.id.menu_context_save_attachment:
|
2014-12-14 02:10:59 +00:00
|
|
|
handleSaveAttachment((MediaMmsMessageRecord)getSelectedMessageRecord());
|
2014-06-12 17:22:57 +00:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-15 22:28:27 +00:00
|
|
|
}
|
2014-03-06 04:11:36 +00:00
|
|
|
}
|