2017-10-16 13:11:42 -07:00
|
|
|
/*
|
2015-11-23 15:07:41 -08:00
|
|
|
* Copyright (C) 2015 Open Whisper Systems
|
2012-07-18 15:35:13 -07:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2017-11-12 12:39:22 -08:00
|
|
|
import android.annotation.SuppressLint;
|
2013-02-03 18:41:34 -08:00
|
|
|
import android.app.ProgressDialog;
|
2015-07-22 13:31:41 -07:00
|
|
|
import android.content.Context;
|
2015-01-20 21:26:58 -10:00
|
|
|
import android.content.Intent;
|
2015-07-08 00:46:21 +03:00
|
|
|
import android.content.res.TypedArray;
|
2012-07-18 15:35:13 -07:00
|
|
|
import android.database.Cursor;
|
2015-11-23 15:07:41 -08:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
import android.graphics.Canvas;
|
2015-07-08 00:46:21 +03:00
|
|
|
import android.graphics.Color;
|
2015-11-23 15:07:41 -08:00
|
|
|
import android.graphics.Paint;
|
2013-02-03 18:41:34 -08:00
|
|
|
import android.os.AsyncTask;
|
2015-07-08 00:46:21 +03:00
|
|
|
import android.os.Build;
|
2012-07-18 15:35:13 -07:00
|
|
|
import android.os.Bundle;
|
2020-08-19 10:06:26 +10:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.loader.app.LoaderManager;
|
|
|
|
import androidx.loader.content.Loader;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.view.ActionMode;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
2015-03-11 14:23:45 -07:00
|
|
|
import android.text.TextUtils;
|
2012-07-18 15:35:13 -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-18 15:35:13 -07:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2019-02-13 11:52:55 -08:00
|
|
|
import android.widget.ImageView;
|
2017-11-13 09:31:01 -08:00
|
|
|
import android.widget.TextView;
|
2012-07-18 15:35:13 -07:00
|
|
|
|
2017-11-15 16:29:00 -08:00
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
|
|
import org.greenrobot.eventbus.ThreadMode;
|
2015-04-04 01:38:44 -07:00
|
|
|
import org.thoughtcrime.securesms.ConversationListAdapter.ItemClickListener;
|
2017-02-19 11:25:23 -08:00
|
|
|
import org.thoughtcrime.securesms.components.recyclerview.DeleteItemAnimator;
|
2017-11-12 12:39:22 -08:00
|
|
|
import org.thoughtcrime.securesms.components.registration.PulsingFloatingActionButton;
|
2015-10-13 21:44:01 -07:00
|
|
|
import org.thoughtcrime.securesms.components.reminder.DefaultSmsReminder;
|
2017-02-20 12:00:03 -08:00
|
|
|
import org.thoughtcrime.securesms.components.reminder.DozeReminder;
|
2015-10-13 21:44:01 -07:00
|
|
|
import org.thoughtcrime.securesms.components.reminder.ExpiredBuildReminder;
|
2015-10-28 15:46:47 +01:00
|
|
|
import org.thoughtcrime.securesms.components.reminder.OutdatedBuildReminder;
|
2015-10-13 21:44:01 -07:00
|
|
|
import org.thoughtcrime.securesms.components.reminder.PushRegistrationReminder;
|
|
|
|
import org.thoughtcrime.securesms.components.reminder.Reminder;
|
|
|
|
import org.thoughtcrime.securesms.components.reminder.ReminderView;
|
2018-06-11 09:37:01 -07:00
|
|
|
import org.thoughtcrime.securesms.components.reminder.ServiceOutageReminder;
|
2015-10-19 11:23:12 -07:00
|
|
|
import org.thoughtcrime.securesms.components.reminder.ShareReminder;
|
2015-10-13 21:44:01 -07:00
|
|
|
import org.thoughtcrime.securesms.components.reminder.SystemSmsImportReminder;
|
2017-11-15 16:29:00 -08:00
|
|
|
import org.thoughtcrime.securesms.components.reminder.UnauthorizedReminder;
|
2014-06-13 08:57:37 +02:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
2016-10-10 11:13:37 -07:00
|
|
|
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
|
2014-06-13 08:57:37 +02:00
|
|
|
import org.thoughtcrime.securesms.database.loaders.ConversationListLoader;
|
2017-11-15 16:29:00 -08:00
|
|
|
import org.thoughtcrime.securesms.events.ReminderUpdateEvent;
|
2018-06-11 09:37:01 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.ServiceOutageDetectionJob;
|
2020-05-11 16:19:26 +10:00
|
|
|
import org.thoughtcrime.securesms.loki.activities.CreatePrivateChatActivity;
|
2017-10-16 13:11:42 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
2016-10-10 11:13:37 -07:00
|
|
|
import org.thoughtcrime.securesms.notifications.MarkReadReceiver;
|
2017-08-01 08:56:00 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2015-10-28 16:50:45 -07:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
2015-11-23 15:07:41 -08:00
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
|
|
|
import org.thoughtcrime.securesms.util.task.SnackbarAsyncTask;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
2014-06-13 08:57:37 +02:00
|
|
|
|
2018-10-29 15:14:31 -07:00
|
|
|
import java.util.Collections;
|
2015-11-23 15:07:41 -08:00
|
|
|
import java.util.HashSet;
|
2016-02-19 17:07:41 -08:00
|
|
|
import java.util.List;
|
2015-03-19 13:08:48 -07:00
|
|
|
import java.util.Locale;
|
2012-07-18 15:35:13 -07:00
|
|
|
import java.util.Set;
|
|
|
|
|
2019-07-24 12:30:23 +10:00
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
2012-07-18 15:35:13 -07:00
|
|
|
|
2015-04-04 01:38:44 -07:00
|
|
|
public class ConversationListFragment extends Fragment
|
|
|
|
implements LoaderManager.LoaderCallbacks<Cursor>, ActionMode.Callback, ItemClickListener
|
2012-07-18 15:35:13 -07:00
|
|
|
{
|
2015-11-23 15:07:41 -08:00
|
|
|
public static final String ARCHIVE = "archive";
|
|
|
|
|
2017-11-19 18:34:03 -08:00
|
|
|
@SuppressWarnings("unused")
|
|
|
|
private static final String TAG = ConversationListFragment.class.getSimpleName();
|
|
|
|
|
2019-02-13 11:52:55 -08:00
|
|
|
private static final int[] EMPTY_IMAGES = new int[] { R.drawable.empty_inbox_1,
|
|
|
|
R.drawable.empty_inbox_2,
|
|
|
|
R.drawable.empty_inbox_3,
|
|
|
|
R.drawable.empty_inbox_4,
|
|
|
|
R.drawable.empty_inbox_5 };
|
|
|
|
|
2017-11-12 12:39:22 -08:00
|
|
|
private ActionMode actionMode;
|
|
|
|
private RecyclerView list;
|
|
|
|
private ReminderView reminderView;
|
|
|
|
private View emptyState;
|
2019-02-13 11:52:55 -08:00
|
|
|
private ImageView emptyImage;
|
2017-11-13 09:31:01 -08:00
|
|
|
private TextView emptySearch;
|
2017-11-12 12:39:22 -08:00
|
|
|
private PulsingFloatingActionButton fab;
|
|
|
|
private Locale locale;
|
|
|
|
private String queryFilter = "";
|
|
|
|
private boolean archive;
|
2012-07-18 15:35:13 -07:00
|
|
|
|
2014-12-15 12:25:55 -08:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle icicle) {
|
|
|
|
super.onCreate(icicle);
|
2018-02-01 19:22:48 -08:00
|
|
|
locale = (Locale) getArguments().getSerializable(PassphraseRequiredActionBarActivity.LOCALE_EXTRA);
|
|
|
|
archive = getArguments().getBoolean(ARCHIVE, false);
|
2014-12-15 12:25:55 -08:00
|
|
|
}
|
|
|
|
|
2012-07-18 15:35:13 -07:00
|
|
|
@Override
|
2017-12-19 10:54:06 -08:00
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle bundle) {
|
2014-07-22 17:27:05 -10:00
|
|
|
final View view = inflater.inflate(R.layout.conversation_list_fragment, container, false);
|
2015-11-23 15:07:41 -08:00
|
|
|
|
|
|
|
reminderView = ViewUtil.findById(view, R.id.reminder);
|
|
|
|
list = ViewUtil.findById(view, R.id.list);
|
|
|
|
fab = ViewUtil.findById(view, R.id.fab);
|
2017-11-12 12:39:22 -08:00
|
|
|
emptyState = ViewUtil.findById(view, R.id.empty_state);
|
2019-02-13 11:52:55 -08:00
|
|
|
emptyImage = ViewUtil.findById(view, R.id.empty);
|
2017-11-13 09:31:01 -08:00
|
|
|
emptySearch = ViewUtil.findById(view, R.id.empty_search);
|
2015-11-23 15:07:41 -08:00
|
|
|
|
2019-05-20 12:19:34 -03:00
|
|
|
if (archive) fab.hide();
|
|
|
|
else fab.show();
|
2015-11-23 15:07:41 -08:00
|
|
|
|
2017-11-15 16:29:00 -08:00
|
|
|
reminderView.setOnDismissListener(() -> updateReminders(true));
|
2015-11-23 15:07:41 -08:00
|
|
|
|
2015-04-04 01:38:44 -07:00
|
|
|
list.setHasFixedSize(true);
|
|
|
|
list.setLayoutManager(new LinearLayoutManager(getActivity()));
|
2017-02-19 11:25:23 -08:00
|
|
|
list.setItemAnimator(new DeleteItemAnimator());
|
2017-11-13 15:54:38 -08:00
|
|
|
|
2015-11-23 15:07:41 -08:00
|
|
|
new ItemTouchHelper(new ArchiveListenerCallback()).attachToRecyclerView(list);
|
|
|
|
|
2014-07-22 17:27:05 -10:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2012-07-18 15:35:13 -07:00
|
|
|
@Override
|
|
|
|
public void onActivityCreated(Bundle bundle) {
|
|
|
|
super.onActivityCreated(bundle);
|
|
|
|
|
|
|
|
setHasOptionsMenu(true);
|
2020-01-31 12:50:25 +11:00
|
|
|
fab.setOnClickListener(v -> startActivity(new Intent(getActivity(), CreatePrivateChatActivity.class)));
|
2012-07-18 15:35:13 -07:00
|
|
|
initializeListAdapter();
|
2018-10-29 15:14:31 -07:00
|
|
|
initializeTypingObserver();
|
2012-07-18 15:35:13 -07:00
|
|
|
}
|
|
|
|
|
2014-07-22 17:27:05 -10:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
2017-11-15 16:29:00 -08:00
|
|
|
updateReminders(true);
|
2015-04-04 01:38:44 -07:00
|
|
|
list.getAdapter().notifyDataSetChanged();
|
2017-11-15 16:29:00 -08:00
|
|
|
EventBus.getDefault().register(this);
|
2014-07-22 17:27:05 -10:00
|
|
|
}
|
|
|
|
|
2017-11-12 12:39:22 -08:00
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
|
|
|
|
fab.stopPulse();
|
2017-11-15 16:29:00 -08:00
|
|
|
EventBus.getDefault().unregister(this);
|
2017-11-12 12:39:22 -08:00
|
|
|
}
|
|
|
|
|
2015-04-04 01:38:44 -07:00
|
|
|
public ConversationListAdapter getListAdapter() {
|
|
|
|
return (ConversationListAdapter) list.getAdapter();
|
2012-07-18 15:35:13 -07:00
|
|
|
}
|
|
|
|
|
2014-06-28 20:40:57 -07:00
|
|
|
public void setQueryFilter(String query) {
|
2014-04-06 01:58:38 +01:00
|
|
|
this.queryFilter = query;
|
|
|
|
getLoaderManager().restartLoader(0, null, this);
|
|
|
|
}
|
|
|
|
|
2014-06-28 20:40:57 -07:00
|
|
|
public void resetQueryFilter() {
|
|
|
|
if (!TextUtils.isEmpty(this.queryFilter)) {
|
|
|
|
setQueryFilter("");
|
|
|
|
}
|
2012-07-31 13:53:00 -07:00
|
|
|
}
|
|
|
|
|
2017-11-12 12:39:22 -08:00
|
|
|
@SuppressLint("StaticFieldLeak")
|
2017-11-15 16:29:00 -08:00
|
|
|
private void updateReminders(boolean hide) {
|
2015-07-22 13:31:41 -07:00
|
|
|
new AsyncTask<Context, Void, Optional<? extends Reminder>>() {
|
2017-11-15 16:29:00 -08:00
|
|
|
@Override
|
|
|
|
protected Optional<? extends Reminder> doInBackground(Context... params) {
|
2015-07-22 13:31:41 -07:00
|
|
|
final Context context = params[0];
|
2017-11-15 16:29:00 -08:00
|
|
|
if (UnauthorizedReminder.isEligible(context)) {
|
|
|
|
return Optional.of(new UnauthorizedReminder(context));
|
|
|
|
} else if (ExpiredBuildReminder.isEligible()) {
|
2015-10-13 21:44:01 -07:00
|
|
|
return Optional.of(new ExpiredBuildReminder(context));
|
2018-06-11 09:37:01 -07:00
|
|
|
} else if (ServiceOutageReminder.isEligible(context)) {
|
2019-03-28 08:56:35 -07:00
|
|
|
ApplicationContext.getInstance(context).getJobManager().add(new ServiceOutageDetectionJob());
|
2018-06-11 09:37:01 -07:00
|
|
|
return Optional.of(new ServiceOutageReminder(context));
|
2015-10-28 15:46:47 +01:00
|
|
|
} else if (OutdatedBuildReminder.isEligible()) {
|
|
|
|
return Optional.of(new OutdatedBuildReminder(context));
|
2015-07-22 13:31:41 -07:00
|
|
|
} else if (DefaultSmsReminder.isEligible(context)) {
|
|
|
|
return Optional.of(new DefaultSmsReminder(context));
|
2015-10-28 16:50:45 -07:00
|
|
|
} else if (Util.isDefaultSmsProvider(context) && SystemSmsImportReminder.isEligible(context)) {
|
2018-02-01 19:22:48 -08:00
|
|
|
return Optional.of((new SystemSmsImportReminder(context)));
|
2015-07-22 13:31:41 -07:00
|
|
|
} else if (PushRegistrationReminder.isEligible(context)) {
|
2018-02-01 19:22:48 -08:00
|
|
|
return Optional.of((new PushRegistrationReminder(context)));
|
2015-10-19 11:23:12 -07:00
|
|
|
} else if (ShareReminder.isEligible(context)) {
|
|
|
|
return Optional.of(new ShareReminder(context));
|
2017-02-20 12:00:03 -08:00
|
|
|
} else if (DozeReminder.isEligible(context)) {
|
|
|
|
return Optional.of(new DozeReminder(context));
|
2015-07-22 13:31:41 -07:00
|
|
|
} else {
|
|
|
|
return Optional.absent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 16:29:00 -08:00
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Optional<? extends Reminder> reminder) {
|
2015-07-22 13:31:41 -07:00
|
|
|
if (reminder.isPresent() && getActivity() != null && !isRemoving()) {
|
|
|
|
reminderView.showReminder(reminder.get());
|
2017-11-15 16:29:00 -08:00
|
|
|
} else if (!reminder.isPresent()) {
|
|
|
|
reminderView.hide();
|
2015-07-22 13:31:41 -07:00
|
|
|
}
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
|
2014-07-22 17:27:05 -10:00
|
|
|
}
|
|
|
|
|
2012-07-18 15:35:13 -07:00
|
|
|
private void initializeListAdapter() {
|
2018-01-24 19:17:44 -08:00
|
|
|
list.setAdapter(new ConversationListAdapter(getActivity(), GlideApp.with(this), locale, null, this));
|
2012-07-18 15:35:13 -07:00
|
|
|
getLoaderManager().restartLoader(0, null, this);
|
|
|
|
}
|
|
|
|
|
2018-10-29 15:14:31 -07:00
|
|
|
private void initializeTypingObserver() {
|
|
|
|
ApplicationContext.getInstance(requireContext()).getTypingStatusRepository().getTypingThreads().observe(this, threadIds -> {
|
|
|
|
if (threadIds == null) {
|
|
|
|
threadIds = Collections.emptySet();
|
|
|
|
}
|
|
|
|
|
|
|
|
getListAdapter().setTypingThreads(threadIds);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-12 12:39:22 -08:00
|
|
|
@SuppressLint("StaticFieldLeak")
|
2015-11-23 15:07:41 -08:00
|
|
|
private void handleArchiveAllSelected() {
|
|
|
|
final Set<Long> selectedConversations = new HashSet<>(getListAdapter().getBatchSelections());
|
|
|
|
final boolean archive = this.archive;
|
|
|
|
|
2015-12-16 15:36:14 +01:00
|
|
|
int snackBarTitleId;
|
2015-11-23 15:07:41 -08:00
|
|
|
|
2015-12-16 15:36:14 +01:00
|
|
|
if (archive) snackBarTitleId = R.plurals.ConversationListFragment_moved_conversations_to_inbox;
|
|
|
|
else snackBarTitleId = R.plurals.ConversationListFragment_conversations_archived;
|
|
|
|
|
|
|
|
int count = selectedConversations.size();
|
|
|
|
String snackBarTitle = getResources().getQuantityString(snackBarTitleId, count, count);
|
2015-11-23 15:07:41 -08:00
|
|
|
|
|
|
|
new SnackbarAsyncTask<Void>(getView(), snackBarTitle,
|
|
|
|
getString(R.string.ConversationListFragment_undo),
|
|
|
|
getResources().getColor(R.color.amber_500),
|
|
|
|
Snackbar.LENGTH_LONG, true)
|
|
|
|
{
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void result) {
|
|
|
|
super.onPostExecute(result);
|
|
|
|
|
|
|
|
if (actionMode != null) {
|
|
|
|
actionMode.finish();
|
|
|
|
actionMode = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void executeAction(@Nullable Void parameter) {
|
|
|
|
for (long threadId : selectedConversations) {
|
|
|
|
if (!archive) DatabaseFactory.getThreadDatabase(getActivity()).archiveConversation(threadId);
|
|
|
|
else DatabaseFactory.getThreadDatabase(getActivity()).unarchiveConversation(threadId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void reverseAction(@Nullable Void parameter) {
|
|
|
|
for (long threadId : selectedConversations) {
|
|
|
|
if (!archive) DatabaseFactory.getThreadDatabase(getActivity()).unarchiveConversation(threadId);
|
|
|
|
else DatabaseFactory.getThreadDatabase(getActivity()).archiveConversation(threadId);
|
|
|
|
}
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2015-11-23 15:07:41 -08:00
|
|
|
}
|
|
|
|
|
2017-11-12 12:39:22 -08:00
|
|
|
@SuppressLint("StaticFieldLeak")
|
2012-07-18 15:35:13 -07:00
|
|
|
private void handleDeleteAllSelected() {
|
2015-05-20 23:36:30 +02:00
|
|
|
int conversationsCount = getListAdapter().getBatchSelections().size();
|
|
|
|
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
|
2015-03-24 13:44:22 +01:00
|
|
|
alert.setIconAttribute(R.attr.dialog_alert_icon);
|
2015-11-04 12:29:14 -08:00
|
|
|
alert.setTitle(getActivity().getResources().getQuantityString(R.plurals.ConversationListFragment_delete_selected_conversations,
|
|
|
|
conversationsCount, conversationsCount));
|
|
|
|
alert.setMessage(getActivity().getResources().getQuantityString(R.plurals.ConversationListFragment_this_will_permanently_delete_all_n_selected_conversations,
|
|
|
|
conversationsCount, conversationsCount));
|
2012-07-18 15:35:13 -07:00
|
|
|
alert.setCancelable(true);
|
|
|
|
|
2017-11-12 12:39:22 -08:00
|
|
|
alert.setPositiveButton(R.string.delete, (dialog, which) -> {
|
|
|
|
final Set<Long> selectedConversations = (getListAdapter())
|
|
|
|
.getBatchSelections();
|
2013-02-03 18:41:34 -08:00
|
|
|
|
2017-11-12 12:39:22 -08:00
|
|
|
if (!selectedConversations.isEmpty()) {
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
private ProgressDialog dialog;
|
2013-02-03 18:41:34 -08:00
|
|
|
|
2017-11-12 12:39:22 -08:00
|
|
|
@Override
|
|
|
|
protected void onPreExecute() {
|
|
|
|
dialog = ProgressDialog.show(getActivity(),
|
|
|
|
getActivity().getString(R.string.ConversationListFragment_deleting),
|
|
|
|
getActivity().getString(R.string.ConversationListFragment_deleting_selected_conversations),
|
|
|
|
true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2020-06-26 16:18:19 +10:00
|
|
|
Context context = getActivity();
|
|
|
|
DatabaseFactory.getThreadDatabase(context).deleteConversations(selectedConversations);
|
|
|
|
ApplicationContext.getInstance(context).messageNotifier.updateNotification(context);
|
2017-11-12 12:39:22 -08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void result) {
|
|
|
|
dialog.dismiss();
|
|
|
|
if (actionMode != null) {
|
|
|
|
actionMode.finish();
|
|
|
|
actionMode = null;
|
2013-02-03 18:41:34 -08:00
|
|
|
}
|
2017-11-12 12:39:22 -08:00
|
|
|
}
|
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2012-07-18 15:35:13 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-09-22 21:53:56 +02:00
|
|
|
alert.setNegativeButton(android.R.string.cancel, null);
|
2012-07-18 15:35:13 -07:00
|
|
|
alert.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleSelectAllThreads() {
|
2015-04-04 01:38:44 -07:00
|
|
|
getListAdapter().selectAllThreads();
|
2018-02-13 21:55:59 +01:00
|
|
|
actionMode.setTitle(String.valueOf(getListAdapter().getBatchSelections().size()));
|
2012-07-18 15:35:13 -07:00
|
|
|
}
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
private void handleCreateConversation(long threadId, Recipient recipient, int distributionType, long lastSeen) {
|
|
|
|
((ConversationSelectedListener)getActivity()).onCreateConversation(threadId, recipient, distributionType, lastSeen);
|
2012-07-18 15:35:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-22 13:51:56 -03:00
|
|
|
public @NonNull Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
2015-11-23 15:07:41 -08:00
|
|
|
return new ConversationListLoader(getActivity(), queryFilter, archive);
|
2012-07-18 15:35:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-22 13:51:56 -03:00
|
|
|
public void onLoadFinished(@NonNull Loader<Cursor> arg0, Cursor cursor) {
|
2017-11-13 09:31:01 -08:00
|
|
|
if ((cursor == null || cursor.getCount() <= 0) && TextUtils.isEmpty(queryFilter) && !archive) {
|
2017-11-12 12:39:22 -08:00
|
|
|
list.setVisibility(View.INVISIBLE);
|
2019-07-18 15:59:41 +10:00
|
|
|
emptyState.setVisibility(View.VISIBLE);
|
2017-11-13 09:31:01 -08:00
|
|
|
emptySearch.setVisibility(View.INVISIBLE);
|
2019-02-13 11:52:55 -08:00
|
|
|
emptyImage.setImageResource(EMPTY_IMAGES[(int) (Math.random() * EMPTY_IMAGES.length)]);
|
2017-11-12 12:39:22 -08:00
|
|
|
fab.startPulse(3 * 1000);
|
2017-11-13 09:31:01 -08:00
|
|
|
} else if ((cursor == null || cursor.getCount() <= 0) && !TextUtils.isEmpty(queryFilter)) {
|
|
|
|
list.setVisibility(View.INVISIBLE);
|
|
|
|
emptyState.setVisibility(View.GONE);
|
|
|
|
emptySearch.setVisibility(View.VISIBLE);
|
|
|
|
emptySearch.setText(getString(R.string.ConversationListFragment_no_results_found_for_s_, queryFilter));
|
2017-11-12 12:39:22 -08:00
|
|
|
} else {
|
|
|
|
list.setVisibility(View.VISIBLE);
|
|
|
|
emptyState.setVisibility(View.GONE);
|
2017-11-13 09:31:01 -08:00
|
|
|
emptySearch.setVisibility(View.INVISIBLE);
|
2017-11-12 12:39:22 -08:00
|
|
|
fab.stopPulse();
|
|
|
|
}
|
|
|
|
|
2015-04-04 01:38:44 -07:00
|
|
|
getListAdapter().changeCursor(cursor);
|
2012-07-18 15:35:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-22 13:51:56 -03:00
|
|
|
public void onLoaderReset(@NonNull Loader<Cursor> arg0) {
|
2015-04-04 01:38:44 -07:00
|
|
|
getListAdapter().changeCursor(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onItemClick(ConversationListItem item) {
|
|
|
|
if (actionMode == null) {
|
2017-08-01 08:56:00 -07:00
|
|
|
handleCreateConversation(item.getThreadId(), item.getRecipient(),
|
2017-02-13 22:35:47 -08:00
|
|
|
item.getDistributionType(), item.getLastSeen());
|
2015-04-04 01:38:44 -07:00
|
|
|
} else {
|
|
|
|
ConversationListAdapter adapter = (ConversationListAdapter)list.getAdapter();
|
|
|
|
adapter.toggleThreadInBatchSet(item.getThreadId());
|
|
|
|
|
|
|
|
if (adapter.getBatchSelections().size() == 0) {
|
|
|
|
actionMode.finish();
|
|
|
|
} else {
|
2018-02-13 21:55:59 +01:00
|
|
|
actionMode.setTitle(String.valueOf(getListAdapter().getBatchSelections().size()));
|
2015-04-04 01:38:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onItemLongClick(ConversationListItem item) {
|
2015-06-09 07:37:20 -07:00
|
|
|
actionMode = ((AppCompatActivity)getActivity()).startSupportActionMode(ConversationListFragment.this);
|
2015-04-04 01:38:44 -07:00
|
|
|
|
|
|
|
getListAdapter().initializeBatchMode(true);
|
|
|
|
getListAdapter().toggleThreadInBatchSet(item.getThreadId());
|
|
|
|
getListAdapter().notifyDataSetChanged();
|
2012-07-18 15:35:13 -07:00
|
|
|
}
|
|
|
|
|
2015-11-23 15:07:41 -08:00
|
|
|
@Override
|
|
|
|
public void onSwitchToArchive() {
|
|
|
|
((ConversationSelectedListener)getActivity()).onSwitchToArchive();
|
|
|
|
}
|
|
|
|
|
2012-07-18 15:35:13 -07:00
|
|
|
public interface ConversationSelectedListener {
|
2017-08-01 08:56:00 -07:00
|
|
|
void onCreateConversation(long threadId, Recipient recipient, int distributionType, long lastSeen);
|
2015-11-23 15:07:41 -08:00
|
|
|
void onSwitchToArchive();
|
2012-07-18 15:35:13 -07:00
|
|
|
}
|
|
|
|
|
2012-07-26 16:21:45 -07:00
|
|
|
@Override
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
2014-06-28 20:40:57 -07:00
|
|
|
MenuInflater inflater = getActivity().getMenuInflater();
|
2015-11-23 15:07:41 -08:00
|
|
|
|
2019-07-22 13:08:56 +10:00
|
|
|
/*
|
2015-11-23 15:07:41 -08:00
|
|
|
if (archive) inflater.inflate(R.menu.conversation_list_batch_unarchive, menu);
|
|
|
|
else inflater.inflate(R.menu.conversation_list_batch_archive, menu);
|
2019-07-22 13:08:56 +10:00
|
|
|
*/
|
2015-11-23 15:07:41 -08:00
|
|
|
|
2012-07-26 16:21:45 -07:00
|
|
|
inflater.inflate(R.menu.conversation_list_batch, menu);
|
|
|
|
|
2018-02-13 21:55:59 +01:00
|
|
|
mode.setTitle("1");
|
2012-07-26 16:21:45 -07:00
|
|
|
|
2015-07-08 00:46:21 +03:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
2015-11-23 15:07:41 -08:00
|
|
|
getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.action_mode_status_bar));
|
2015-07-08 00:46:21 +03:00
|
|
|
}
|
|
|
|
|
2012-07-26 16:21:45 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
2015-11-23 15:07:41 -08:00
|
|
|
case R.id.menu_select_all: handleSelectAllThreads(); return true;
|
|
|
|
case R.id.menu_delete_selected: handleDeleteAllSelected(); return true;
|
2020-08-24 12:52:50 +10:00
|
|
|
// case R.id.menu_archive_selected: handleArchiveAllSelected(); return true;
|
2012-07-26 16:21:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {
|
2015-04-04 01:38:44 -07:00
|
|
|
getListAdapter().initializeBatchMode(false);
|
2015-07-08 00:46:21 +03:00
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
2015-11-23 15:07:41 -08:00
|
|
|
TypedArray color = getActivity().getTheme().obtainStyledAttributes(new int[] {android.R.attr.statusBarColor});
|
2015-07-08 00:46:21 +03:00
|
|
|
getActivity().getWindow().setStatusBarColor(color.getColor(0, Color.BLACK));
|
|
|
|
color.recycle();
|
|
|
|
}
|
|
|
|
|
2013-07-22 15:30:12 -07:00
|
|
|
actionMode = null;
|
2012-07-26 16:21:45 -07:00
|
|
|
}
|
|
|
|
|
2017-11-15 16:29:00 -08:00
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
|
public void onEvent(ReminderUpdateEvent event) {
|
|
|
|
updateReminders(false);
|
|
|
|
}
|
|
|
|
|
2015-11-23 15:07:41 -08:00
|
|
|
private class ArchiveListenerCallback extends ItemTouchHelper.SimpleCallback {
|
|
|
|
|
2017-11-12 12:39:22 -08:00
|
|
|
ArchiveListenerCallback() {
|
2015-11-23 15:07:41 -08:00
|
|
|
super(0, ItemTouchHelper.RIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-22 13:51:56 -03:00
|
|
|
public boolean onMove(@NonNull RecyclerView recyclerView,
|
|
|
|
@NonNull RecyclerView.ViewHolder viewHolder,
|
|
|
|
@NonNull RecyclerView.ViewHolder target)
|
2015-11-23 15:07:41 -08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-22 13:51:56 -03:00
|
|
|
public int getSwipeDirs(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
|
2015-11-23 15:07:41 -08:00
|
|
|
if (viewHolder.itemView instanceof ConversationListItemAction) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actionMode != null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.getSwipeDirs(recyclerView, viewHolder);
|
|
|
|
}
|
|
|
|
|
2017-11-12 12:39:22 -08:00
|
|
|
@SuppressLint("StaticFieldLeak")
|
2015-11-23 15:07:41 -08:00
|
|
|
@Override
|
2019-05-22 13:51:56 -03:00
|
|
|
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
|
2018-02-20 21:28:15 -05:00
|
|
|
if (viewHolder.itemView instanceof ConversationListItemInboxZero) return;
|
2017-11-13 18:01:05 -08:00
|
|
|
final long threadId = ((ConversationListItem)viewHolder.itemView).getThreadId();
|
|
|
|
final int unreadCount = ((ConversationListItem)viewHolder.itemView).getUnreadCount();
|
2015-11-23 15:07:41 -08:00
|
|
|
|
|
|
|
if (archive) {
|
|
|
|
new SnackbarAsyncTask<Long>(getView(),
|
2015-12-16 15:36:14 +01:00
|
|
|
getResources().getQuantityString(R.plurals.ConversationListFragment_moved_conversations_to_inbox, 1, 1),
|
2015-11-23 15:07:41 -08:00
|
|
|
getString(R.string.ConversationListFragment_undo),
|
|
|
|
getResources().getColor(R.color.amber_500),
|
2015-11-28 20:26:28 +09:00
|
|
|
Snackbar.LENGTH_LONG, false)
|
2015-11-23 15:07:41 -08:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
protected void executeAction(@Nullable Long parameter) {
|
|
|
|
DatabaseFactory.getThreadDatabase(getActivity()).unarchiveConversation(threadId);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void reverseAction(@Nullable Long parameter) {
|
|
|
|
DatabaseFactory.getThreadDatabase(getActivity()).archiveConversation(threadId);
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, threadId);
|
2015-11-23 15:07:41 -08:00
|
|
|
} else {
|
|
|
|
new SnackbarAsyncTask<Long>(getView(),
|
2015-12-16 15:36:14 +01:00
|
|
|
getResources().getQuantityString(R.plurals.ConversationListFragment_conversations_archived, 1, 1),
|
2015-11-23 15:07:41 -08:00
|
|
|
getString(R.string.ConversationListFragment_undo),
|
|
|
|
getResources().getColor(R.color.amber_500),
|
2015-11-28 20:26:28 +09:00
|
|
|
Snackbar.LENGTH_LONG, false)
|
2015-11-23 15:07:41 -08:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
protected void executeAction(@Nullable Long parameter) {
|
|
|
|
DatabaseFactory.getThreadDatabase(getActivity()).archiveConversation(threadId);
|
2015-12-03 12:36:47 -08:00
|
|
|
|
2017-11-13 18:01:05 -08:00
|
|
|
if (unreadCount > 0) {
|
2020-06-26 16:18:19 +10:00
|
|
|
Context context = getActivity();
|
|
|
|
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, false);
|
|
|
|
ApplicationContext.getInstance(context).messageNotifier.updateNotification(context);
|
|
|
|
MarkReadReceiver.process(context, messageIds);
|
2015-12-03 12:36:47 -08:00
|
|
|
}
|
2015-11-23 15:07:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void reverseAction(@Nullable Long parameter) {
|
|
|
|
DatabaseFactory.getThreadDatabase(getActivity()).unarchiveConversation(threadId);
|
2015-12-03 12:36:47 -08:00
|
|
|
|
2017-11-13 18:01:05 -08:00
|
|
|
if (unreadCount > 0) {
|
2020-06-26 16:18:19 +10:00
|
|
|
Context context = getActivity();
|
|
|
|
DatabaseFactory.getThreadDatabase(context).incrementUnread(threadId, unreadCount);
|
|
|
|
ApplicationContext.getInstance(context).messageNotifier.updateNotification(context);
|
2015-12-03 12:36:47 -08:00
|
|
|
}
|
2015-11-23 15:07:41 -08:00
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, threadId);
|
2015-11-23 15:07:41 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-22 13:51:56 -03:00
|
|
|
public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView,
|
|
|
|
@NonNull RecyclerView.ViewHolder viewHolder,
|
2015-11-23 15:07:41 -08:00
|
|
|
float dX, float dY, int actionState,
|
|
|
|
boolean isCurrentlyActive)
|
|
|
|
{
|
2018-02-20 21:28:15 -05:00
|
|
|
if (viewHolder.itemView instanceof ConversationListItemInboxZero) return;
|
2015-11-23 15:07:41 -08:00
|
|
|
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
|
|
|
|
View itemView = viewHolder.itemView;
|
|
|
|
Paint p = new Paint();
|
2017-11-19 18:34:03 -08:00
|
|
|
float alpha = 1.0f - Math.abs(dX) / (float) viewHolder.itemView.getWidth();
|
2015-11-23 15:07:41 -08:00
|
|
|
|
|
|
|
if (dX > 0) {
|
|
|
|
Bitmap icon;
|
|
|
|
|
|
|
|
if (archive) icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_unarchive_white_36dp);
|
|
|
|
else icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_archive_white_36dp);
|
|
|
|
|
2017-11-19 18:34:03 -08:00
|
|
|
if (alpha > 0) p.setColor(getResources().getColor(R.color.green_500));
|
|
|
|
else p.setColor(Color.WHITE);
|
2015-11-23 15:07:41 -08:00
|
|
|
|
|
|
|
c.drawRect((float) itemView.getLeft(), (float) itemView.getTop(), dX,
|
|
|
|
(float) itemView.getBottom(), p);
|
|
|
|
|
|
|
|
c.drawBitmap(icon,
|
|
|
|
(float) itemView.getLeft() + getResources().getDimension(R.dimen.conversation_list_fragment_archive_padding),
|
|
|
|
(float) itemView.getTop() + ((float) itemView.getBottom() - (float) itemView.getTop() - icon.getHeight())/2,
|
|
|
|
p);
|
|
|
|
}
|
|
|
|
|
2017-11-12 12:39:22 -08:00
|
|
|
viewHolder.itemView.setAlpha(alpha);
|
|
|
|
viewHolder.itemView.setTranslationX(dX);
|
2015-11-23 15:07:41 -08:00
|
|
|
} else {
|
|
|
|
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-18 15:35:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|