2012-10-30 19:39:32 -04:00
|
|
|
/*
|
2014-01-01 16:26:19 -05:00
|
|
|
* Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
|
2012-10-30 19:39:32 -04:00
|
|
|
*
|
2013-09-06 10:17:01 -04: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.
|
2012-10-30 19:39:32 -04:00
|
|
|
*
|
2013-09-06 10:17:01 -04:00
|
|
|
* 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.
|
2012-10-30 19:39:32 -04:00
|
|
|
*
|
2013-09-06 10:17:01 -04:00
|
|
|
* 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-10-30 19:39:32 -04:00
|
|
|
*/
|
|
|
|
|
2013-01-16 08:31:16 -05:00
|
|
|
package org.sufficientlysecure.keychain.ui;
|
2012-10-28 18:51:03 -04:00
|
|
|
|
2014-02-05 19:02:18 -05:00
|
|
|
import java.util.ArrayList;
|
2014-01-05 18:58:04 -05:00
|
|
|
import java.util.Set;
|
|
|
|
|
2013-01-16 08:31:16 -05:00
|
|
|
import org.sufficientlysecure.keychain.Id;
|
2014-01-01 16:26:19 -05:00
|
|
|
import org.sufficientlysecure.keychain.R;
|
2014-01-01 10:54:55 -05:00
|
|
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
2013-01-16 08:31:16 -05:00
|
|
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
|
|
|
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
|
2014-01-09 09:12:41 -05:00
|
|
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
2014-01-01 16:26:19 -05:00
|
|
|
import org.sufficientlysecure.keychain.ui.adapter.KeyListPublicAdapter;
|
2014-01-05 18:58:04 -05:00
|
|
|
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
|
2012-10-28 18:51:03 -04:00
|
|
|
|
2014-01-02 15:10:08 -05:00
|
|
|
import se.emilsjolander.stickylistheaders.ApiLevelTooLowException;
|
|
|
|
import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
|
2014-02-04 09:01:50 -05:00
|
|
|
|
2014-01-02 15:10:08 -05:00
|
|
|
import android.annotation.SuppressLint;
|
2014-03-03 05:55:36 -05:00
|
|
|
import android.annotation.TargetApi;
|
2012-10-30 19:39:32 -04:00
|
|
|
import android.content.Intent;
|
2012-10-28 18:51:03 -04:00
|
|
|
import android.database.Cursor;
|
|
|
|
import android.net.Uri;
|
2014-01-05 18:58:04 -05:00
|
|
|
import android.os.Build;
|
2012-10-28 18:51:03 -04:00
|
|
|
import android.os.Bundle;
|
2014-02-05 19:02:18 -05:00
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Message;
|
|
|
|
import android.os.Messenger;
|
2014-01-05 18:58:04 -05:00
|
|
|
import android.support.v4.app.Fragment;
|
2014-01-01 16:26:19 -05:00
|
|
|
import android.support.v4.app.LoaderManager;
|
2012-10-28 18:51:03 -04:00
|
|
|
import android.support.v4.content.CursorLoader;
|
|
|
|
import android.support.v4.content.Loader;
|
2014-03-05 15:54:13 -05:00
|
|
|
import android.support.v4.view.MenuItemCompat;
|
|
|
|
import android.support.v7.widget.SearchView;
|
|
|
|
import android.text.TextUtils;
|
2014-01-05 18:58:04 -05:00
|
|
|
import android.view.ActionMode;
|
2014-01-02 15:10:08 -05:00
|
|
|
import android.view.LayoutInflater;
|
2014-01-05 18:58:04 -05:00
|
|
|
import android.view.Menu;
|
2014-03-05 15:54:13 -05:00
|
|
|
import android.view.MenuInflater;
|
2014-01-05 18:58:04 -05:00
|
|
|
import android.view.MenuItem;
|
2012-10-30 19:39:32 -04:00
|
|
|
import android.view.View;
|
2014-01-07 17:48:16 -05:00
|
|
|
import android.view.View.OnClickListener;
|
2014-01-09 09:12:41 -05:00
|
|
|
import android.view.ViewGroup;
|
2014-03-07 14:58:33 -05:00
|
|
|
import android.view.animation.AnimationUtils;
|
2014-01-05 18:58:04 -05:00
|
|
|
import android.widget.AbsListView.MultiChoiceModeListener;
|
2014-01-01 16:26:19 -05:00
|
|
|
import android.widget.AdapterView;
|
2014-01-05 18:58:04 -05:00
|
|
|
import android.widget.ListView;
|
2014-02-05 19:02:18 -05:00
|
|
|
import android.widget.Toast;
|
2014-01-02 15:10:08 -05:00
|
|
|
|
2014-01-09 09:12:41 -05:00
|
|
|
import com.beardedhen.androidbootstrap.BootstrapButton;
|
|
|
|
|
2014-01-02 15:10:08 -05:00
|
|
|
/**
|
2014-01-03 12:07:42 -05:00
|
|
|
* Public key list with sticky list headers. It does _not_ extend ListFragment because it uses
|
|
|
|
* StickyListHeaders library which does not extend upon ListView.
|
2014-01-02 15:10:08 -05:00
|
|
|
*/
|
2014-03-05 15:54:13 -05:00
|
|
|
public class KeyListPublicFragment extends Fragment implements SearchView.OnQueryTextListener, AdapterView.OnItemClickListener,
|
2014-01-05 18:58:04 -05:00
|
|
|
LoaderManager.LoaderCallbacks<Cursor> {
|
2012-10-28 18:51:03 -04:00
|
|
|
|
2014-01-01 16:26:19 -05:00
|
|
|
private KeyListPublicAdapter mAdapter;
|
2014-01-02 16:36:57 -05:00
|
|
|
private StickyListHeadersListView mStickyList;
|
2014-03-07 14:58:33 -05:00
|
|
|
|
|
|
|
// rebuild functionality of ListFragment, http://stackoverflow.com/a/12504097
|
|
|
|
boolean mListShown;
|
|
|
|
View mProgressContainer;
|
|
|
|
View mListContainer;
|
|
|
|
|
2014-03-05 15:54:13 -05:00
|
|
|
private String mCurQuery;
|
|
|
|
private SearchView mSearchView;
|
2014-02-04 09:01:50 -05:00
|
|
|
// empty list layout
|
2014-01-09 09:12:41 -05:00
|
|
|
private BootstrapButton mButtonEmptyCreate;
|
|
|
|
private BootstrapButton mButtonEmptyImport;
|
2014-01-07 17:48:16 -05:00
|
|
|
|
2014-03-05 15:54:13 -05:00
|
|
|
|
2014-01-02 16:36:57 -05:00
|
|
|
/**
|
|
|
|
* Load custom layout with StickyListView from library
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
2014-03-07 14:58:33 -05:00
|
|
|
View root = inflater.inflate(R.layout.key_list_public_fragment, container, false);
|
|
|
|
|
|
|
|
mStickyList = (StickyListHeadersListView) root.findViewById(R.id.key_list_public_list);
|
|
|
|
mStickyList.setOnItemClickListener(this);
|
|
|
|
|
|
|
|
|
|
|
|
// empty view
|
|
|
|
mButtonEmptyCreate = (BootstrapButton) root.findViewById(R.id.key_list_empty_button_create);
|
2014-01-07 17:48:16 -05:00
|
|
|
mButtonEmptyCreate.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent(getActivity(), EditKeyActivity.class);
|
|
|
|
intent.setAction(EditKeyActivity.ACTION_CREATE_KEY);
|
|
|
|
intent.putExtra(EditKeyActivity.EXTRA_GENERATE_DEFAULT_KEYS, true);
|
|
|
|
intent.putExtra(EditKeyActivity.EXTRA_USER_IDS, ""); // show user id view
|
|
|
|
startActivityForResult(intent, 0);
|
|
|
|
}
|
|
|
|
});
|
2014-03-07 14:58:33 -05:00
|
|
|
mButtonEmptyImport = (BootstrapButton) root.findViewById(R.id.key_list_empty_button_import);
|
2014-01-07 17:48:16 -05:00
|
|
|
mButtonEmptyImport.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-02-04 09:01:50 -05:00
|
|
|
Intent intent = new Intent(getActivity(), ImportKeysActivity.class);
|
|
|
|
intent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_FILE);
|
|
|
|
startActivityForResult(intent, 0);
|
2014-01-07 17:48:16 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-03-07 14:58:33 -05:00
|
|
|
// rebuild functionality of ListFragment, http://stackoverflow.com/a/12504097
|
|
|
|
mListContainer = root.findViewById(R.id.key_list_public_list_container);
|
|
|
|
mProgressContainer = root.findViewById(R.id.key_list_public_progress_container);
|
|
|
|
mListShown = true;
|
|
|
|
|
|
|
|
return root;
|
2014-01-02 16:36:57 -05:00
|
|
|
}
|
2014-01-02 15:10:08 -05:00
|
|
|
|
2012-10-28 18:51:03 -04:00
|
|
|
/**
|
|
|
|
* Define Adapter and Loader on create of Activity
|
|
|
|
*/
|
2014-01-02 15:10:08 -05:00
|
|
|
@SuppressLint("NewApi")
|
2012-10-28 18:51:03 -04:00
|
|
|
@Override
|
|
|
|
public void onActivityCreated(Bundle savedInstanceState) {
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
|
2014-01-02 16:36:57 -05:00
|
|
|
mStickyList.setAreHeadersSticky(true);
|
|
|
|
mStickyList.setDrawingListUnderStickyHeader(false);
|
|
|
|
mStickyList.setFastScrollEnabled(true);
|
2014-01-02 15:10:08 -05:00
|
|
|
try {
|
2014-01-02 16:36:57 -05:00
|
|
|
mStickyList.setFastScrollAlwaysVisible(true);
|
2014-01-02 15:10:08 -05:00
|
|
|
} catch (ApiLevelTooLowException e) {
|
|
|
|
}
|
2012-10-30 19:39:32 -04:00
|
|
|
|
2014-01-03 12:07:42 -05:00
|
|
|
// this view is made visible if no data is available
|
2014-03-07 14:58:33 -05:00
|
|
|
mStickyList.setEmptyView(getActivity().findViewById(R.id.key_list_public_empty));
|
2014-01-01 10:54:55 -05:00
|
|
|
|
2014-01-05 18:58:04 -05:00
|
|
|
/*
|
|
|
|
* ActionBarSherlock does not support MultiChoiceModeListener. Thus multi-selection is only
|
|
|
|
* available for Android >= 3.0
|
|
|
|
*/
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
mStickyList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
|
|
|
|
mStickyList.getWrappedList().setMultiChoiceModeListener(new MultiChoiceModeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
|
|
android.view.MenuInflater inflater = getActivity().getMenuInflater();
|
2014-01-07 16:59:39 -05:00
|
|
|
inflater.inflate(R.menu.key_list_public_multi, menu);
|
2014-01-05 18:58:04 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
|
|
Set<Integer> positions = mAdapter.getCurrentCheckedPosition();
|
2014-01-07 16:59:39 -05:00
|
|
|
|
|
|
|
// get IDs for checked positions as long array
|
|
|
|
long[] ids = new long[positions.size()];
|
|
|
|
int i = 0;
|
|
|
|
for (int pos : positions) {
|
|
|
|
ids[i] = mAdapter.getItemId(pos);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2014-01-05 18:58:04 -05:00
|
|
|
switch (item.getItemId()) {
|
2014-02-04 09:01:50 -05:00
|
|
|
case R.id.menu_key_list_public_multi_encrypt: {
|
2014-02-05 19:02:18 -05:00
|
|
|
encrypt(mode, ids);
|
2014-02-04 09:01:50 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case R.id.menu_key_list_public_multi_delete: {
|
2014-02-05 19:02:18 -05:00
|
|
|
showDeleteKeyDialog(mode, ids);
|
2014-02-04 09:01:50 -05:00
|
|
|
break;
|
|
|
|
}
|
2014-03-06 13:32:10 -05:00
|
|
|
case R.id.menu_key_list_public_multi_select_all: {
|
|
|
|
//Select all
|
|
|
|
int localCount = mStickyList.getCount();
|
2014-03-07 13:50:36 -05:00
|
|
|
for (int k = 0; k < localCount; k++) {
|
2014-03-06 13:32:10 -05:00
|
|
|
mStickyList.setItemChecked(k, true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-01-07 16:59:39 -05:00
|
|
|
}
|
2014-02-05 19:02:18 -05:00
|
|
|
return true;
|
2014-01-05 18:58:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {
|
|
|
|
mAdapter.clearSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
|
2014-02-04 09:01:50 -05:00
|
|
|
boolean checked) {
|
2014-01-05 18:58:04 -05:00
|
|
|
if (checked) {
|
|
|
|
mAdapter.setNewSelection(position, checked);
|
|
|
|
} else {
|
|
|
|
mAdapter.removeSelection(position);
|
|
|
|
}
|
2014-03-06 13:32:10 -05:00
|
|
|
int count = mAdapter.getCurrentCheckedPosition().size();
|
2014-01-05 18:58:04 -05:00
|
|
|
String keysSelected = getResources().getQuantityString(
|
|
|
|
R.plurals.key_list_selected_keys, count, count);
|
|
|
|
mode.setTitle(keysSelected);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-03-07 14:58:33 -05:00
|
|
|
// We have a menu item to show in action bar.
|
|
|
|
setHasOptionsMenu(true);
|
|
|
|
|
2014-03-07 15:32:24 -05:00
|
|
|
// NOTE: Not supported by StickyListHeader, but reimplemented here
|
2014-01-01 16:26:19 -05:00
|
|
|
// Start out with a progress indicator.
|
2014-03-07 14:58:33 -05:00
|
|
|
setListShown(false);
|
2013-01-08 16:12:23 -05:00
|
|
|
|
2014-01-01 16:26:19 -05:00
|
|
|
// Create an empty adapter we will use to display the loaded data.
|
2014-01-07 16:59:39 -05:00
|
|
|
mAdapter = new KeyListPublicAdapter(getActivity(), null, Id.type.public_key, USER_ID_INDEX);
|
2014-01-03 12:07:42 -05:00
|
|
|
mStickyList.setAdapter(mAdapter);
|
2012-10-30 19:39:32 -04:00
|
|
|
|
2014-01-01 16:26:19 -05:00
|
|
|
// Prepare the loader. Either re-connect with an existing one,
|
|
|
|
// or start a new one.
|
|
|
|
getLoaderManager().initLoader(0, null, this);
|
2012-10-30 19:39:32 -04:00
|
|
|
}
|
|
|
|
|
2012-10-28 18:51:03 -04:00
|
|
|
// These are the rows that we will retrieve.
|
2014-02-04 09:01:50 -05:00
|
|
|
static final String[] PROJECTION = new String[]{
|
|
|
|
KeychainContract.KeyRings._ID,
|
|
|
|
KeychainContract.KeyRings.MASTER_KEY_ID,
|
|
|
|
KeychainContract.UserIds.USER_ID,
|
|
|
|
KeychainContract.Keys.IS_REVOKED
|
|
|
|
};
|
2012-10-28 18:51:03 -04:00
|
|
|
|
2014-01-03 12:07:42 -05:00
|
|
|
static final int USER_ID_INDEX = 2;
|
|
|
|
|
2012-10-29 19:15:08 -04:00
|
|
|
static final String SORT_ORDER = UserIds.USER_ID + " ASC";
|
2012-10-28 18:51:03 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
|
|
|
// This is called when a new Loader needs to be created. This
|
|
|
|
// sample only has one Loader, so we don't care about the ID.
|
2012-10-29 19:15:08 -04:00
|
|
|
Uri baseUri = KeyRings.buildPublicKeyRingsUri();
|
2014-03-05 15:54:13 -05:00
|
|
|
String where = null;
|
2014-03-06 05:57:35 -05:00
|
|
|
String whereArgs[] = null;
|
2014-03-07 13:50:36 -05:00
|
|
|
if (mCurQuery != null) {
|
2014-03-06 05:57:35 -05:00
|
|
|
where = KeychainContract.UserIds.USER_ID + " LIKE ?";
|
2014-03-07 13:50:36 -05:00
|
|
|
whereArgs = new String[]{"%" + mCurQuery + "%"};
|
2014-03-06 05:57:35 -05:00
|
|
|
}
|
2012-10-28 18:51:03 -04:00
|
|
|
// Now create and return a CursorLoader that will take care of
|
|
|
|
// creating a Cursor for the data being displayed.
|
2014-03-06 05:57:35 -05:00
|
|
|
return new CursorLoader(getActivity(), baseUri, PROJECTION, where, whereArgs, SORT_ORDER);
|
2012-10-28 18:51:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
|
|
|
// Swap the new cursor in. (The framework will take care of closing the
|
|
|
|
// old cursor once we return.)
|
2014-03-10 05:55:09 -04:00
|
|
|
mAdapter.setSearchQuery(mCurQuery);
|
2014-01-03 12:07:42 -05:00
|
|
|
mAdapter.swapCursor(data);
|
2014-01-02 16:36:57 -05:00
|
|
|
mStickyList.setAdapter(mAdapter);
|
2012-10-28 18:51:03 -04:00
|
|
|
|
2014-03-07 15:32:24 -05:00
|
|
|
// NOTE: Not supported by StickyListHeader, but reimplemented here
|
2012-10-28 18:51:03 -04:00
|
|
|
// The list should now be shown.
|
2014-03-07 14:58:33 -05:00
|
|
|
if (isResumed()) {
|
|
|
|
setListShown(true);
|
|
|
|
} else {
|
|
|
|
setListShownNoAnimation(true);
|
|
|
|
}
|
2012-10-28 18:51:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoaderReset(Loader<Cursor> loader) {
|
|
|
|
// This is called when the last Cursor provided to onLoadFinished()
|
|
|
|
// above is about to be closed. We need to make sure we are no
|
|
|
|
// longer using it.
|
2014-01-01 16:26:19 -05:00
|
|
|
mAdapter.swapCursor(null);
|
2012-10-28 18:51:03 -04:00
|
|
|
}
|
|
|
|
|
2014-01-02 16:36:57 -05:00
|
|
|
/**
|
|
|
|
* On click on item, start key view activity
|
|
|
|
*/
|
2014-01-02 15:10:08 -05:00
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
|
2014-01-19 11:54:26 -05:00
|
|
|
Intent viewIntent = null;
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
|
|
|
|
viewIntent = new Intent(getActivity(), ViewKeyActivity.class);
|
|
|
|
} else {
|
|
|
|
viewIntent = new Intent(getActivity(), ViewKeyActivityJB.class);
|
|
|
|
}
|
|
|
|
viewIntent.setData(KeychainContract.KeyRings.buildPublicKeyRingsUri(Long.toString(id)));
|
|
|
|
startActivity(viewIntent);
|
2014-01-02 15:10:08 -05:00
|
|
|
}
|
2014-03-07 13:50:36 -05:00
|
|
|
|
2014-03-03 05:55:36 -05:00
|
|
|
@TargetApi(11)
|
2014-02-05 19:02:18 -05:00
|
|
|
public void encrypt(ActionMode mode, long[] keyRingRowIds) {
|
2014-01-07 16:59:39 -05:00
|
|
|
// get master key ids from row ids
|
|
|
|
long[] keyRingIds = new long[keyRingRowIds.length];
|
|
|
|
for (int i = 0; i < keyRingRowIds.length; i++) {
|
|
|
|
keyRingIds[i] = ProviderHelper.getPublicMasterKeyId(getActivity(), keyRingRowIds[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Intent intent = new Intent(getActivity(), EncryptActivity.class);
|
|
|
|
intent.setAction(EncryptActivity.ACTION_ENCRYPT);
|
|
|
|
intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, keyRingIds);
|
|
|
|
// used instead of startActivity set actionbar based on callingPackage
|
|
|
|
startActivityForResult(intent, 0);
|
2014-02-05 19:02:18 -05:00
|
|
|
|
|
|
|
mode.finish();
|
2014-01-07 16:59:39 -05:00
|
|
|
}
|
|
|
|
|
2014-01-05 18:58:04 -05:00
|
|
|
/**
|
|
|
|
* Show dialog to delete key
|
2014-02-04 09:01:50 -05:00
|
|
|
*
|
2014-01-05 18:58:04 -05:00
|
|
|
* @param keyRingRowIds
|
|
|
|
*/
|
2014-03-03 05:55:36 -05:00
|
|
|
@TargetApi(11)
|
2014-02-05 19:02:18 -05:00
|
|
|
public void showDeleteKeyDialog(final ActionMode mode, long[] keyRingRowIds) {
|
|
|
|
// Message is received after key is deleted
|
|
|
|
Handler returnHandler = new Handler() {
|
|
|
|
@Override
|
|
|
|
public void handleMessage(Message message) {
|
|
|
|
if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) {
|
|
|
|
Bundle returnData = message.getData();
|
|
|
|
if (returnData != null
|
|
|
|
&& returnData.containsKey(DeleteKeyDialogFragment.MESSAGE_NOT_DELETED)) {
|
|
|
|
ArrayList<String> notDeleted =
|
|
|
|
returnData.getStringArrayList(DeleteKeyDialogFragment.MESSAGE_NOT_DELETED);
|
|
|
|
String notDeletedMsg = "";
|
|
|
|
for (String userId : notDeleted) {
|
|
|
|
notDeletedMsg += userId + "\n";
|
|
|
|
}
|
2014-02-08 09:42:31 -05:00
|
|
|
Toast.makeText(getActivity(), getString(R.string.error_can_not_delete_contacts, notDeletedMsg)
|
|
|
|
+ getResources().getQuantityString(R.plurals.error_can_not_delete_info, notDeleted.size()),
|
2014-02-05 19:02:18 -05:00
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
|
|
|
|
mode.finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create a new Messenger for the communication back
|
|
|
|
Messenger messenger = new Messenger(returnHandler);
|
|
|
|
|
|
|
|
DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger,
|
2014-01-05 18:58:04 -05:00
|
|
|
keyRingRowIds, Id.type.public_key);
|
|
|
|
|
|
|
|
deleteKeyDialog.show(getActivity().getSupportFragmentManager(), "deleteKeyDialog");
|
|
|
|
}
|
|
|
|
|
2014-03-05 15:54:13 -05:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
|
|
|
|
// Get the searchview
|
|
|
|
MenuItem searchItem = menu.findItem(R.id.menu_key_list_public_search);
|
|
|
|
mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
|
|
|
|
|
|
|
|
// Execute this when searching
|
|
|
|
mSearchView.setOnQueryTextListener(this);
|
|
|
|
|
2014-03-08 04:58:46 -05:00
|
|
|
|
2014-03-05 15:54:13 -05:00
|
|
|
super.onCreateOptionsMenu(menu, inflater);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextSubmit(String s) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextChange(String s) {
|
|
|
|
// Called when the action bar search text has changed. Update
|
|
|
|
// the search filter, and restart the loader to do a new query
|
|
|
|
// with this filter.
|
2014-03-07 13:50:36 -05:00
|
|
|
mCurQuery = !TextUtils.isEmpty(s) ? s : null;
|
2014-03-05 15:54:13 -05:00
|
|
|
getLoaderManager().restartLoader(0, null, this);
|
|
|
|
return true;
|
|
|
|
}
|
2014-03-07 14:58:33 -05:00
|
|
|
|
|
|
|
// rebuild functionality of ListFragment, http://stackoverflow.com/a/12504097
|
|
|
|
public void setListShown(boolean shown, boolean animate) {
|
|
|
|
if (mListShown == shown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mListShown = shown;
|
|
|
|
if (shown) {
|
|
|
|
if (animate) {
|
|
|
|
mProgressContainer.startAnimation(AnimationUtils.loadAnimation(
|
|
|
|
getActivity(), android.R.anim.fade_out));
|
|
|
|
mListContainer.startAnimation(AnimationUtils.loadAnimation(
|
|
|
|
getActivity(), android.R.anim.fade_in));
|
|
|
|
}
|
|
|
|
mProgressContainer.setVisibility(View.GONE);
|
|
|
|
mListContainer.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
if (animate) {
|
|
|
|
mProgressContainer.startAnimation(AnimationUtils.loadAnimation(
|
|
|
|
getActivity(), android.R.anim.fade_in));
|
|
|
|
mListContainer.startAnimation(AnimationUtils.loadAnimation(
|
|
|
|
getActivity(), android.R.anim.fade_out));
|
|
|
|
}
|
|
|
|
mProgressContainer.setVisibility(View.VISIBLE);
|
|
|
|
mListContainer.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// rebuild functionality of ListFragment, http://stackoverflow.com/a/12504097
|
|
|
|
public void setListShown(boolean shown) {
|
|
|
|
setListShown(shown, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// rebuild functionality of ListFragment, http://stackoverflow.com/a/12504097
|
|
|
|
public void setListShownNoAnimation(boolean shown) {
|
|
|
|
setListShown(shown, false);
|
|
|
|
}
|
2014-03-03 05:55:36 -05:00
|
|
|
}
|