aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java41
1 files changed, 30 insertions, 11 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
index 3c97b1128..b4676f9b7 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013-2014 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Vincent Breitmoser <v.breitmoser@mugenguild.com>
*
* 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
@@ -79,14 +80,15 @@ public class KeyListFragment extends LoaderFragment
private KeyListAdapter mAdapter;
private StickyListHeadersListView mStickyList;
+ // saves the mode object for multiselect, needed for reset at some point
+ private ActionMode mActionMode = null;
+
private String mQuery;
private SearchView mSearchView;
// empty list layout
private Button mButtonEmptyCreate;
private Button mButtonEmptyImport;
- public static final int REQUEST_CODE_CREATE_OR_IMPORT_KEY = 0x00007012;
-
/**
* Load custom layout with StickyListView from library
*/
@@ -105,7 +107,7 @@ public class KeyListFragment extends LoaderFragment
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), CreateKeyActivity.class);
- startActivityForResult(intent, REQUEST_CODE_CREATE_OR_IMPORT_KEY);
+ startActivityForResult(intent, 0);
}
});
mButtonEmptyImport = (Button) view.findViewById(R.id.key_list_empty_button_import);
@@ -115,7 +117,7 @@ public class KeyListFragment extends LoaderFragment
public void onClick(View v) {
Intent intent = new Intent(getActivity(), ImportKeysActivity.class);
intent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN);
- startActivityForResult(intent, REQUEST_CODE_CREATE_OR_IMPORT_KEY);
+ startActivityForResult(intent, 0);
}
});
@@ -148,6 +150,7 @@ public class KeyListFragment extends LoaderFragment
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
android.view.MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.key_list_multi, menu);
+ mActionMode = mode;
return true;
}
@@ -193,6 +196,7 @@ public class KeyListFragment extends LoaderFragment
@Override
public void onDestroyActionMode(ActionMode mode) {
+ mActionMode = null;
mAdapter.clearSelection();
}
@@ -288,6 +292,13 @@ public class KeyListFragment extends LoaderFragment
// this view is made visible if no data is available
mStickyList.setEmptyView(getActivity().findViewById(R.id.key_list_empty));
+ // end action mode, if any
+ if (mActionMode != null) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+ mActionMode.finish();
+ }
+ }
+
// The list should now be shown.
if (isResumed()) {
setContentShown(true);
@@ -330,12 +341,12 @@ public class KeyListFragment extends LoaderFragment
* Show dialog to delete key
*
* @param masterKeyIds
- * @param hasSecret must contain whether the list of masterKeyIds contains a secret key or not
+ * @param hasSecret must contain whether the list of masterKeyIds contains a secret key or not
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void showDeleteKeyDialog(final ActionMode mode, long[] masterKeyIds, boolean hasSecret) {
// Can only work on singular secret keys
- if(hasSecret && masterKeyIds.length > 1) {
+ if (hasSecret && masterKeyIds.length > 1) {
Notify.showNotify(getActivity(), R.string.secret_cannot_multiple,
Notify.Style.ERROR);
return;
@@ -365,6 +376,7 @@ public class KeyListFragment extends LoaderFragment
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
// Get the searchview
MenuItem searchItem = menu.findItem(R.id.menu_key_list_search);
+
mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
// Execute this when searching
@@ -383,7 +395,6 @@ public class KeyListFragment extends LoaderFragment
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
mQuery = null;
- mSearchView.setQuery("", true);
getLoaderManager().restartLoader(0, null, KeyListFragment.this);
return true;
}
@@ -399,11 +410,18 @@ public class KeyListFragment extends LoaderFragment
@Override
public boolean onQueryTextChange(String s) {
+ Log.d(Constants.TAG, "onQueryTextChange s:" + 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.
- mQuery = !TextUtils.isEmpty(s) ? s : null;
- getLoaderManager().restartLoader(0, null, this);
+ // If the nav drawer is opened, onQueryTextChange("") is executed.
+ // This hack prevents restarting the loader.
+ // TODO: better way to fix this?
+ String tmp = (mQuery == null) ? "" : mQuery;
+ if (!s.equals(tmp)) {
+ mQuery = s;
+ getLoaderManager().restartLoader(0, null, this);
+ }
return true;
}
@@ -479,7 +497,7 @@ public class KeyListFragment extends LoaderFragment
boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0;
boolean isExpired = !cursor.isNull(INDEX_EXPIRY)
- && new Date(cursor.getLong(INDEX_EXPIRY)*1000).before(new Date());
+ && new Date(cursor.getLong(INDEX_EXPIRY) * 1000).before(new Date());
boolean isVerified = cursor.getInt(INDEX_VERIFIED) > 0;
// Note: order is important!
@@ -521,6 +539,7 @@ public class KeyListFragment extends LoaderFragment
return mCursor.getInt(INDEX_HAS_ANY_SECRET) != 0;
}
+
public long getMasterKeyId(int id) {
if (!mCursor.moveToPosition(id)) {
throw new IllegalStateException("couldn't move cursor to position " + id);
@@ -625,7 +644,7 @@ public class KeyListFragment extends LoaderFragment
public boolean isAnySecretSelected() {
for (int pos : mSelection.keySet()) {
- if(mAdapter.isSecretAvailable(pos))
+ if (mAdapter.isSecretAvailable(pos))
return true;
}
return false;