aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-03-08 14:08:44 +0100
committerVincent Breitmoser <valodim@mugenguild.com>2014-03-08 14:08:44 +0100
commitde6daf5c30c66e1152f06560e0030fb514d5f68f (patch)
tree8ef2852b57e42f06c0e820adccbccca62203e6a1
parent16116ba72572fc85fe00ec422248818da516506a (diff)
downloadopen-keychain-de6daf5c30c66e1152f06560e0030fb514d5f68f.tar.gz
open-keychain-de6daf5c30c66e1152f06560e0030fb514d5f68f.tar.bz2
open-keychain-de6daf5c30c66e1152f06560e0030fb514d5f68f.zip
better handling of multi select in ListKeysFragment
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java39
1 files changed, 22 insertions, 17 deletions
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
index bdae88e55..941abdd6d 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
@@ -164,22 +164,18 @@ public class KeyListFragment extends Fragment implements AdapterView.OnItemClick
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
- Set<Integer> positions = mAdapter.getCurrentCheckedPosition();
// 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++;
- }
+ long[] ids;
switch (item.getItemId()) {
case R.id.menu_key_list_multi_encrypt: {
+ ids = mAdapter.getCurrentSelectedMasterKeyIds();
encrypt(mode, ids);
break;
}
case R.id.menu_key_list_multi_delete: {
+ ids = mAdapter.getCurrentSelectedItemIds();
showDeleteKeyDialog(mode, ids);
break;
}
@@ -290,16 +286,10 @@ public class KeyListFragment extends Fragment implements AdapterView.OnItemClick
}
@TargetApi(11)
- public void encrypt(ActionMode mode, long[] keyRingRowIds) {
- // 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]);
- }
-
+ protected void encrypt(ActionMode mode, long[] keyRingMasterKeyIds) {
Intent intent = new Intent(getActivity(), EncryptActivity.class);
intent.setAction(EncryptActivity.ACTION_ENCRYPT);
- intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, keyRingIds);
+ intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, keyRingMasterKeyIds);
// used instead of startActivity set actionbar based on callingPackage
startActivityForResult(intent, 0);
@@ -312,6 +302,7 @@ public class KeyListFragment extends Fragment implements AdapterView.OnItemClick
* @param keyRingRowIds
*/
@TargetApi(11)
+ // TODO: this method needs an overhaul to handle both public and secret keys gracefully!
public void showDeleteKeyDialog(final ActionMode mode, long[] keyRingRowIds) {
// Message is received after key is deleted
Handler returnHandler = new Handler() {
@@ -557,8 +548,22 @@ public class KeyListFragment extends Fragment implements AdapterView.OnItemClick
return result == null ? false : result;
}
- public Set<Integer> getCurrentCheckedPosition() {
- return mSelection.keySet();
+ public long[] getCurrentSelectedItemIds() {
+ long[] ids = new long[mSelection.size()];
+ int i = 0;
+ // get master key ids
+ for (int pos : mSelection.keySet())
+ ids[i++] = mAdapter.getItemId(pos);
+ return ids;
+ }
+
+ public long[] getCurrentSelectedMasterKeyIds() {
+ long[] ids = new long[mSelection.size()];
+ int i = 0;
+ // get master key ids
+ for (int pos : mSelection.keySet())
+ ids[i++] = mAdapter.getMasterKeyId(pos);
+ return ids;
}
public void removeSelection(int position) {