mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-04 15:35:38 +01:00
committed by
Moxie Marlinspike
parent
f5724795cf
commit
1cc581aed8
@@ -16,19 +16,21 @@
|
||||
*/
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v4.widget.CursorAdapter;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.view.ActionMode;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.RecyclerView.RecyclerListener;
|
||||
import android.support.v7.widget.RecyclerView.ViewHolder;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
@@ -37,13 +39,13 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.afollestad.materialdialogs.AlertDialogWrapper;
|
||||
import com.melnykov.fab.FloatingActionButton;
|
||||
|
||||
import org.thoughtcrime.securesms.ConversationListAdapter.ItemClickListener;
|
||||
import org.thoughtcrime.securesms.components.DefaultSmsReminder;
|
||||
import org.thoughtcrime.securesms.components.DividerItemDecoration;
|
||||
import org.thoughtcrime.securesms.components.ExpiredBuildReminder;
|
||||
import org.thoughtcrime.securesms.components.PushRegistrationReminder;
|
||||
import org.thoughtcrime.securesms.components.ReminderView;
|
||||
@@ -57,15 +59,16 @@ import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class ConversationListFragment extends ListFragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor>, ActionMode.Callback
|
||||
public class ConversationListFragment extends Fragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor>, ActionMode.Callback, ItemClickListener
|
||||
{
|
||||
|
||||
private MasterSecret masterSecret;
|
||||
private ActionMode actionMode;
|
||||
private ReminderView reminderView;
|
||||
private FloatingActionButton fab;
|
||||
private String queryFilter = "";
|
||||
private MasterSecret masterSecret;
|
||||
private ActionMode actionMode;
|
||||
private RecyclerView list;
|
||||
private ReminderView reminderView;
|
||||
private FloatingActionButton fab;
|
||||
private String queryFilter = "";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
@@ -76,8 +79,12 @@ public class ConversationListFragment extends ListFragment
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
|
||||
final View view = inflater.inflate(R.layout.conversation_list_fragment, container, false);
|
||||
reminderView = new ReminderView(getActivity());
|
||||
reminderView = (ReminderView) view.findViewById(R.id.reminder);
|
||||
list = (RecyclerView) view.findViewById(R.id.list);
|
||||
fab = (FloatingActionButton) view.findViewById(R.id.fab);
|
||||
list.setHasFixedSize(true);
|
||||
list.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
list.addItemDecoration(new DividerItemDecoration(getActivity(), LinearLayoutManager.VERTICAL, R.attr.conversation_list_item_divider));
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -86,8 +93,6 @@ public class ConversationListFragment extends ListFragment
|
||||
super.onActivityCreated(bundle);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
getListView().setAdapter(null);
|
||||
getListView().addHeaderView(reminderView);
|
||||
fab.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -95,7 +100,6 @@ public class ConversationListFragment extends ListFragment
|
||||
}
|
||||
});
|
||||
initializeListAdapter();
|
||||
initializeBatchListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,30 +107,11 @@ public class ConversationListFragment extends ListFragment
|
||||
super.onResume();
|
||||
|
||||
initializeReminders();
|
||||
((ConversationListAdapter)getListAdapter()).notifyDataSetChanged();
|
||||
list.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
if (v instanceof ConversationListItem) {
|
||||
ConversationListItem headerView = (ConversationListItem) v;
|
||||
if (actionMode == null) {
|
||||
handleCreateConversation(headerView.getThreadId(), headerView.getRecipients(),
|
||||
headerView.getDistributionType());
|
||||
} else {
|
||||
ConversationListAdapter adapter = (ConversationListAdapter)getListAdapter();
|
||||
adapter.toggleThreadInBatchSet(headerView.getThreadId());
|
||||
|
||||
if (adapter.getBatchSelections().size() == 0) {
|
||||
actionMode.finish();
|
||||
} else {
|
||||
actionMode.setSubtitle(getString(R.string.conversation_fragment_cab__batch_selection_amount,
|
||||
adapter.getBatchSelections().size()));
|
||||
}
|
||||
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
public ConversationListAdapter getListAdapter() {
|
||||
return (ConversationListAdapter) list.getAdapter();
|
||||
}
|
||||
|
||||
public void setQueryFilter(String query) {
|
||||
@@ -140,22 +125,6 @@ public class ConversationListFragment extends ListFragment
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeBatchListener() {
|
||||
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> arg0, View v, int position, long id) {
|
||||
ConversationListAdapter adapter = (ConversationListAdapter)getListAdapter();
|
||||
actionMode = ((ActionBarActivity)getActivity()).startSupportActionMode(ConversationListFragment.this);
|
||||
|
||||
adapter.initializeBatchMode(true);
|
||||
adapter.toggleThreadInBatchSet(((ConversationListItem) v).getThreadId());
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initializeReminders() {
|
||||
if (ExpiredBuildReminder.isEligible(getActivity())) {
|
||||
reminderView.showReminder(new ExpiredBuildReminder());
|
||||
@@ -171,8 +140,13 @@ public class ConversationListFragment extends ListFragment
|
||||
}
|
||||
|
||||
private void initializeListAdapter() {
|
||||
this.setListAdapter(new ConversationListAdapter(getActivity(), null, masterSecret));
|
||||
getListView().setRecyclerListener((ConversationListAdapter)getListAdapter());
|
||||
list.setAdapter(new ConversationListAdapter(getActivity(), masterSecret, null, this));
|
||||
list.setRecyclerListener(new RecyclerListener() {
|
||||
@Override
|
||||
public void onViewRecycled(ViewHolder holder) {
|
||||
((ConversationListItem)holder.itemView).unbind();
|
||||
}
|
||||
});
|
||||
getLoaderManager().restartLoader(0, null, this);
|
||||
}
|
||||
|
||||
@@ -186,7 +160,7 @@ public class ConversationListFragment extends ListFragment
|
||||
alert.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final Set<Long> selectedConversations = ((ConversationListAdapter)getListAdapter())
|
||||
final Set<Long> selectedConversations = (getListAdapter())
|
||||
.getBatchSelections();
|
||||
|
||||
if (!selectedConversations.isEmpty()) {
|
||||
@@ -226,7 +200,7 @@ public class ConversationListFragment extends ListFragment
|
||||
}
|
||||
|
||||
private void handleSelectAllThreads() {
|
||||
((ConversationListAdapter)this.getListAdapter()).selectAllThreads();
|
||||
getListAdapter().selectAllThreads();
|
||||
actionMode.setSubtitle(getString(R.string.conversation_fragment_cab__batch_selection_amount,
|
||||
((ConversationListAdapter)this.getListAdapter()).getBatchSelections().size()));
|
||||
}
|
||||
@@ -242,16 +216,45 @@ public class ConversationListFragment extends ListFragment
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
|
||||
((CursorAdapter)getListAdapter()).changeCursor(cursor);
|
||||
getListAdapter().changeCursor(cursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> arg0) {
|
||||
((CursorAdapter)getListAdapter()).changeCursor(null);
|
||||
getListAdapter().changeCursor(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(ConversationListItem item) {
|
||||
if (actionMode == null) {
|
||||
handleCreateConversation(item.getThreadId(), item.getRecipients(),
|
||||
item.getDistributionType());
|
||||
} else {
|
||||
ConversationListAdapter adapter = (ConversationListAdapter)list.getAdapter();
|
||||
adapter.toggleThreadInBatchSet(item.getThreadId());
|
||||
|
||||
if (adapter.getBatchSelections().size() == 0) {
|
||||
actionMode.finish();
|
||||
} else {
|
||||
actionMode.setSubtitle(getString(R.string.conversation_fragment_cab__batch_selection_amount,
|
||||
adapter.getBatchSelections().size()));
|
||||
}
|
||||
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemLongClick(ConversationListItem item) {
|
||||
actionMode = ((ActionBarActivity)getActivity()).startSupportActionMode(ConversationListFragment.this);
|
||||
|
||||
getListAdapter().initializeBatchMode(true);
|
||||
getListAdapter().toggleThreadInBatchSet(item.getThreadId());
|
||||
getListAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public interface ConversationSelectedListener {
|
||||
public void onCreateConversation(long threadId, Recipients recipients, int distributionType);
|
||||
void onCreateConversation(long threadId, Recipients recipients, int distributionType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -282,7 +285,7 @@ public class ConversationListFragment extends ListFragment
|
||||
|
||||
@Override
|
||||
public void onDestroyActionMode(ActionMode mode) {
|
||||
((ConversationListAdapter)getListAdapter()).initializeBatchMode(false);
|
||||
getListAdapter().initializeBatchMode(false);
|
||||
actionMode = null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user