From e83532cb19756b3c585afa9b4a49ec1288f6fd42 Mon Sep 17 00:00:00 2001 From: iseki Date: Wed, 25 Mar 2015 04:44:53 +0900 Subject: [PATCH] Add a loop for multiple key export. --- .../keychain/ui/KeyListFragment.java | 81 ++++++++++++++++--- 1 file changed, 68 insertions(+), 13 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 861ae12d9..8ef74a15f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.ui; import android.animation.ObjectAnimator; import android.annotation.TargetApi; +import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; @@ -71,6 +72,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.CloudImportService; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.ServiceProgressHandler; +import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment; import org.sufficientlysecure.keychain.ui.util.Highlighter; @@ -97,6 +99,9 @@ public class KeyListFragment extends LoaderFragment implements SearchView.OnQueryTextListener, AdapterView.OnItemClickListener, LoaderManager.LoaderCallbacks, FabContainer { + static final int REQUEST_REPEAT_PASSPHRASE = 1; + static final int REQUEST_ACTION = 2; + ExportHelper mExportHelper; private KeyListAdapter mAdapter; @@ -109,6 +114,11 @@ public class KeyListFragment extends LoaderFragment private FloatingActionsMenu mFab; + // This ids for multiple key export. + private ArrayList mIdsForRepeatAskPassphrase; + // This index for remembering the number of master key. + private int mIndex; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -231,8 +241,29 @@ public class KeyListFragment extends LoaderFragment } case R.id.menu_key_list_multi_export: { ids = mAdapter.getCurrentSelectedMasterKeyIds(); - ExportHelper mExportHelper = new ExportHelper(getActivity()); - mExportHelper.showExportKeysDialog(ids, Constants.Path.APP_DIR_FILE, + mIdsForRepeatAskPassphrase = new ArrayList(); + for(long id: ids) { + try { + if (PassphraseCacheService.getCachedPassphrase( + getActivity(), id, id) == null) { + mIdsForRepeatAskPassphrase.add(Long.valueOf(id)); + } + } catch (PassphraseCacheService.KeyNotFoundException e) { + // This happens when the master key is stripped + // and ignore this key. + continue; + } + } + mIndex = 0; + if (mIdsForRepeatAskPassphrase.size() != 0) { + startPassphraseActivity(); + break; + } + long[] idsForMultiExport = new long[mIdsForRepeatAskPassphrase.size()]; + for(int i=0; i