Merge pull request #1973 from open-keychain/fix-multi-import-load
fix loading of multiple keys simultaneously
This commit is contained in:
@@ -24,15 +24,18 @@ import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
|||||||
public class ImportKeysOperationCallback implements
|
public class ImportKeysOperationCallback implements
|
||||||
CryptoOperationHelper.Callback<ImportKeyringParcel, ImportKeyResult> {
|
CryptoOperationHelper.Callback<ImportKeyringParcel, ImportKeyResult> {
|
||||||
|
|
||||||
private ImportKeysResultListener mResultListener;
|
private final ImportKeysResultListener mResultListener;
|
||||||
private ImportKeyringParcel mKeyringParcel;
|
private final ImportKeyringParcel mKeyringParcel;
|
||||||
|
private final Integer mPosition;
|
||||||
|
|
||||||
public ImportKeysOperationCallback(
|
public ImportKeysOperationCallback(
|
||||||
ImportKeysResultListener resultListener,
|
ImportKeysResultListener resultListener,
|
||||||
ImportKeyringParcel inputParcel
|
ImportKeyringParcel inputParcel,
|
||||||
|
Integer position
|
||||||
) {
|
) {
|
||||||
this.mResultListener = resultListener;
|
this.mResultListener = resultListener;
|
||||||
this.mKeyringParcel = inputParcel;
|
this.mKeyringParcel = inputParcel;
|
||||||
|
this.mPosition = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -42,7 +45,7 @@ public class ImportKeysOperationCallback implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCryptoOperationSuccess(ImportKeyResult result) {
|
public void onCryptoOperationSuccess(ImportKeyResult result) {
|
||||||
mResultListener.handleResult(result);
|
mResultListener.handleResult(result, mPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -52,7 +55,7 @@ public class ImportKeysOperationCallback implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCryptoOperationError(ImportKeyResult result) {
|
public void onCryptoOperationError(ImportKeyResult result) {
|
||||||
mResultListener.handleResult(result);
|
mResultListener.handleResult(result, mPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -21,6 +21,6 @@ import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
|||||||
|
|
||||||
public interface ImportKeysResultListener {
|
public interface ImportKeysResultListener {
|
||||||
|
|
||||||
void handleResult(ImportKeyResult result);
|
void handleResult(ImportKeyResult result, Integer position);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class RemoteImportKeysActivity extends ImportKeysActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleResult(ImportKeyResult result) {
|
public void handleResult(ImportKeyResult result, Integer position) {
|
||||||
setResult(RESULT_OK, mPendingIntentData);
|
setResult(RESULT_OK, mPendingIntentData);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -359,13 +359,13 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImportKeyringParcel inputParcel = new ImportKeyringParcel(null, null);
|
ImportKeyringParcel inputParcel = new ImportKeyringParcel(null, null);
|
||||||
ImportKeysOperationCallback callback = new ImportKeysOperationCallback(this, inputParcel);
|
ImportKeysOperationCallback callback = new ImportKeysOperationCallback(this, inputParcel, null);
|
||||||
mOpHelper = new CryptoOperationHelper<>(1, this, callback, R.string.progress_importing);
|
mOpHelper = new CryptoOperationHelper<>(1, this, callback, R.string.progress_importing);
|
||||||
mOpHelper.cryptoOperation();
|
mOpHelper.cryptoOperation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleResult(ImportKeyResult result) {
|
public void handleResult(ImportKeyResult result, Integer position) {
|
||||||
String intentAction = getIntent().getAction();
|
String intentAction = getIntent().getAction();
|
||||||
|
|
||||||
if (ImportKeysActivity.ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT.equals(intentAction)
|
if (ImportKeysActivity.ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT.equals(intentAction)
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
|
|
||||||
private List<ImportKeysListEntry> mData;
|
private List<ImportKeysListEntry> mData;
|
||||||
private KeyState[] mKeyStates;
|
private KeyState[] mKeyStates;
|
||||||
private int mCurrent;
|
|
||||||
|
|
||||||
private ProviderHelper mProviderHelper;
|
private ProviderHelper mProviderHelper;
|
||||||
|
|
||||||
@@ -83,9 +82,9 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
|
|
||||||
mKeyStates = new KeyState[data.size()];
|
mKeyStates = new KeyState[data.size()];
|
||||||
for (int i = 0; i < mKeyStates.length; i++) {
|
for (int i = 0; i < mKeyStates.length; i++) {
|
||||||
mKeyStates[i] = new KeyState();
|
|
||||||
|
|
||||||
ImportKeysListEntry entry = mData.get(i);
|
ImportKeysListEntry entry = mData.get(i);
|
||||||
|
|
||||||
|
KeyState keyState = new KeyState();
|
||||||
long keyId = KeyFormattingUtils.convertKeyIdHexToKeyId(entry.getKeyIdHex());
|
long keyId = KeyFormattingUtils.convertKeyIdHexToKeyId(entry.getKeyIdHex());
|
||||||
try {
|
try {
|
||||||
KeyRing keyRing;
|
KeyRing keyRing;
|
||||||
@@ -94,15 +93,16 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
} else {
|
} else {
|
||||||
keyRing = mProviderHelper.getCachedPublicKeyRing(keyId);
|
keyRing = mProviderHelper.getCachedPublicKeyRing(keyId);
|
||||||
}
|
}
|
||||||
mKeyStates[i].mAlreadyPresent = true;
|
keyState.mAlreadyPresent = true;
|
||||||
mKeyStates[i].mVerified = keyRing.getVerified() > 0;
|
keyState.mVerified = keyRing.getVerified() > 0;
|
||||||
} catch (ProviderHelper.NotFoundException | PgpKeyNotFoundException ignored) {
|
} catch (ProviderHelper.NotFoundException | PgpKeyNotFoundException ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mKeyStates[i] = keyState;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is only one key, get it automatically
|
// If there is only one key, get it automatically
|
||||||
if (mData.size() == 1) {
|
if (mData.size() == 1) {
|
||||||
mCurrent = 0;
|
|
||||||
getKeyWithProgress(0, mData.get(0), true);
|
getKeyWithProgress(0, mData.get(0), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,8 +164,6 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (!keyState.mDownloaded) {
|
if (!keyState.mDownloaded) {
|
||||||
mCurrent = position;
|
|
||||||
|
|
||||||
getKeyWithProgress(position, entry, true);
|
getKeyWithProgress(position, entry, true);
|
||||||
} else {
|
} else {
|
||||||
changeShowed(position, !keyState.mShowed);
|
changeShowed(position, !keyState.mShowed);
|
||||||
@@ -202,13 +200,13 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
|
|
||||||
private void getKeyWithProgress(int position, ImportKeysListEntry entry, boolean skipSave) {
|
private void getKeyWithProgress(int position, ImportKeysListEntry entry, boolean skipSave) {
|
||||||
changeProgress(position, true);
|
changeProgress(position, true);
|
||||||
getKey(entry, skipSave);
|
getKey(position, entry, skipSave);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getKey(ImportKeysListEntry entry, boolean skipSave) {
|
private void getKey(int position, ImportKeysListEntry entry, boolean skipSave) {
|
||||||
ImportKeyringParcel inputParcel = prepareKeyOperation(entry, skipSave);
|
ImportKeyringParcel inputParcel = prepareKeyOperation(entry, skipSave);
|
||||||
ImportKeysResultListener listener = skipSave ? this : mListener;
|
ImportKeysResultListener listener = skipSave ? this : mListener;
|
||||||
ImportKeysOperationCallback cb = new ImportKeysOperationCallback(listener, inputParcel);
|
ImportKeysOperationCallback cb = new ImportKeysOperationCallback(listener, inputParcel, position);
|
||||||
CryptoOperationHelper opHelper = new CryptoOperationHelper<>(1, mActivity, cb, null);
|
CryptoOperationHelper opHelper = new CryptoOperationHelper<>(1, mActivity, cb, null);
|
||||||
opHelper.cryptoOperation();
|
opHelper.cryptoOperation();
|
||||||
}
|
}
|
||||||
@@ -242,7 +240,11 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleResult(ImportKeyResult result) {
|
public void handleResult(ImportKeyResult result, Integer position) {
|
||||||
|
if (position == null) {
|
||||||
|
throw new IllegalArgumentException("position parameter must be non-null!");
|
||||||
|
}
|
||||||
|
|
||||||
boolean resultStatus = result.success();
|
boolean resultStatus = result.success();
|
||||||
Log.e(Constants.TAG, "getKey result: " + resultStatus);
|
Log.e(Constants.TAG, "getKey result: " + resultStatus);
|
||||||
if (resultStatus) {
|
if (resultStatus) {
|
||||||
@@ -252,13 +254,13 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
Log.e(Constants.TAG, "Key ID: " + keyRing.getMasterKeyId() +
|
Log.e(Constants.TAG, "Key ID: " + keyRing.getMasterKeyId() +
|
||||||
"| isRev: " + keyRing.isRevoked() + "| isExp: " + keyRing.isExpired());
|
"| isRev: " + keyRing.isRevoked() + "| isExp: " + keyRing.isExpired());
|
||||||
|
|
||||||
ImportKeysListEntry entry = mData.get(mCurrent);
|
ImportKeysListEntry entry = mData.get(position);
|
||||||
entry.setUpdated(result.isOkUpdated());
|
entry.setUpdated(result.isOkUpdated());
|
||||||
|
|
||||||
mergeEntryWithKey(entry, keyRing);
|
mergeEntryWithKey(entry, keyRing);
|
||||||
|
|
||||||
mKeyStates[mCurrent].mDownloaded = true;
|
mKeyStates[position].mDownloaded = true;
|
||||||
changeShowed(mCurrent, true);
|
changeShowed(position, true);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("getKey retrieved more than one key ("
|
throw new RuntimeException("getKey retrieved more than one key ("
|
||||||
+ canKeyRings.size() + ")");
|
+ canKeyRings.size() + ")");
|
||||||
@@ -267,7 +269,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
result.createNotify(mActivity).show();
|
result.createNotify(mActivity).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
changeProgress(mCurrent, false);
|
changeProgress(position, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeEntryWithKey(ImportKeysListEntry entry, CanonicalizedKeyRing keyRing) {
|
private void mergeEntryWithKey(ImportKeysListEntry entry, CanonicalizedKeyRing keyRing) {
|
||||||
@@ -308,5 +310,4 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
keyState.mProgress = progress;
|
keyState.mProgress = progress;
|
||||||
notifyItemChanged(position);
|
notifyItemChanged(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user