ImportKeys: Add ability to "Show key" instead of "Import" for already imported keys
This commit is contained in:
@@ -29,6 +29,7 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -48,18 +49,23 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
||||
private ArrayList<Map.Entry<String, HashSet<String>>> mSortedUserIds;
|
||||
|
||||
private String mKeyIdHex;
|
||||
|
||||
private boolean mSecretKey;
|
||||
private boolean mRevoked;
|
||||
private boolean mExpired;
|
||||
private Date mDate; // TODO: not displayed
|
||||
private boolean mUpdated;
|
||||
|
||||
private Date mDate;
|
||||
private String mFingerprintHex;
|
||||
private Integer mBitStrength;
|
||||
private String mCurveOid;
|
||||
private String mAlgorithm;
|
||||
private boolean mSecretKey;
|
||||
|
||||
private UserId mPrimaryUserId;
|
||||
private String mKeyserver;
|
||||
private String mKeybaseName;
|
||||
private String mFbUsername;
|
||||
|
||||
private String mQuery;
|
||||
private Integer mHashCode = null;
|
||||
|
||||
@@ -82,6 +88,10 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
||||
return mKeyIdHex;
|
||||
}
|
||||
|
||||
public long getKeyId() {
|
||||
return new BigInteger(mKeyIdHex.substring(2), 16).longValue();
|
||||
}
|
||||
|
||||
public void setKeyIdHex(String keyIdHex) {
|
||||
mKeyIdHex = keyIdHex;
|
||||
}
|
||||
@@ -114,6 +124,14 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
||||
return mDate;
|
||||
}
|
||||
|
||||
public boolean isUpdated() {
|
||||
return mUpdated;
|
||||
}
|
||||
|
||||
public void setUpdated(boolean updated) {
|
||||
mUpdated = updated;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
mDate = date;
|
||||
}
|
||||
@@ -343,6 +361,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
||||
dest.writeSerializable(mMergedUserIds);
|
||||
dest.writeByte((byte) (mRevoked ? 1 : 0));
|
||||
dest.writeByte((byte) (mExpired ? 1 : 0));
|
||||
dest.writeByte((byte) (mUpdated ? 1 : 0));
|
||||
dest.writeInt(mDate == null ? 0 : 1);
|
||||
if (mDate != null) {
|
||||
dest.writeLong(mDate.getTime());
|
||||
@@ -370,6 +389,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
||||
vr.mMergedUserIds = (HashMap<String, HashSet<String>>) source.readSerializable();
|
||||
vr.mRevoked = source.readByte() == 1;
|
||||
vr.mExpired = source.readByte() == 1;
|
||||
vr.mUpdated = source.readByte() == 1;
|
||||
vr.mDate = source.readInt() != 0 ? new Date(source.readLong()) : null;
|
||||
vr.mFingerprintHex = source.readString();
|
||||
vr.mKeyIdHex = source.readString();
|
||||
|
||||
@@ -926,10 +926,12 @@ public class ProviderHelper {
|
||||
}
|
||||
|
||||
CanonicalizedPublicKeyRing canPublicRing;
|
||||
boolean alreadyExists = false;
|
||||
|
||||
// If there is an old keyring, merge it
|
||||
try {
|
||||
UncachedKeyRing oldPublicRing = getCanonicalizedPublicKeyRing(masterKeyId).getUncachedKeyRing();
|
||||
alreadyExists = true;
|
||||
|
||||
// Merge data from new public ring into the old one
|
||||
log(LogType.MSG_IP_MERGE_PUBLIC);
|
||||
@@ -998,18 +1000,23 @@ public class ProviderHelper {
|
||||
}
|
||||
}
|
||||
|
||||
int result = SaveKeyringResult.SAVED_PUBLIC;
|
||||
int result;
|
||||
if (!skipSave) {
|
||||
result = saveCanonicalizedPublicKeyRing(canPublicRing, progress, canSecretRing != null);
|
||||
} else {
|
||||
result = SaveKeyringResult.SAVED_PUBLIC
|
||||
| (alreadyExists ? SaveKeyringResult.UPDATED : 0);
|
||||
}
|
||||
|
||||
// Save the saved keyring (if any)
|
||||
if (canSecretRing != null) {
|
||||
progress.setProgress(LogType.MSG_IP_REINSERT_SECRET.getMsgId(), 90, 100);
|
||||
|
||||
int secretResult = SaveKeyringResult.SAVED_SECRET;
|
||||
int secretResult;
|
||||
if (!skipSave) {
|
||||
saveCanonicalizedSecretKeyRing(canSecretRing);
|
||||
secretResult = saveCanonicalizedSecretKeyRing(canSecretRing);
|
||||
} else {
|
||||
secretResult = SaveKeyringResult.SAVED_SECRET;
|
||||
}
|
||||
|
||||
if ((secretResult & SaveKeyringResult.RESULT_ERROR) != SaveKeyringResult.RESULT_ERROR) {
|
||||
@@ -1018,7 +1025,6 @@ public class ProviderHelper {
|
||||
}
|
||||
|
||||
return new SaveKeyringResult(result, mLog, canSecretRing);
|
||||
|
||||
} catch (IOException e) {
|
||||
log(LogType.MSG_IP_ERROR_IO_EXC);
|
||||
return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null);
|
||||
@@ -1051,10 +1057,12 @@ public class ProviderHelper {
|
||||
}
|
||||
|
||||
CanonicalizedSecretKeyRing canSecretRing;
|
||||
boolean alreadyExists = false;
|
||||
|
||||
// If there is an old secret key, merge it.
|
||||
try {
|
||||
UncachedKeyRing oldSecretRing = getCanonicalizedSecretKeyRing(masterKeyId).getUncachedKeyRing();
|
||||
alreadyExists = true;
|
||||
|
||||
// Merge data from new secret ring into old one
|
||||
log(LogType.MSG_IS_MERGE_SECRET);
|
||||
@@ -1129,9 +1137,11 @@ public class ProviderHelper {
|
||||
return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null);
|
||||
}
|
||||
|
||||
int publicResult = SaveKeyringResult.SAVED_PUBLIC;
|
||||
int publicResult;
|
||||
if (!skipSave) {
|
||||
publicResult = saveCanonicalizedPublicKeyRing(canPublicRing, progress, true);
|
||||
} else {
|
||||
publicResult = SaveKeyringResult.SAVED_PUBLIC;
|
||||
}
|
||||
|
||||
if ((publicResult & SaveKeyringResult.RESULT_ERROR) == SaveKeyringResult.RESULT_ERROR) {
|
||||
@@ -1140,13 +1150,15 @@ public class ProviderHelper {
|
||||
|
||||
progress.setProgress(LogType.MSG_IP_REINSERT_SECRET.getMsgId(), 90, 100);
|
||||
|
||||
int result = SaveKeyringResult.SAVED_SECRET;
|
||||
int result;
|
||||
if (!skipSave) {
|
||||
result = saveCanonicalizedSecretKeyRing(canSecretRing);
|
||||
} else {
|
||||
result = SaveKeyringResult.SAVED_SECRET
|
||||
| (alreadyExists ? SaveKeyringResult.UPDATED : 0);
|
||||
}
|
||||
|
||||
return new SaveKeyringResult(result, mLog, canSecretRing);
|
||||
|
||||
} catch (IOException e) {
|
||||
log(LogType.MSG_IS_ERROR_IO_EXC);
|
||||
return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null);
|
||||
|
||||
@@ -17,11 +17,13 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.ui.adapter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
@@ -35,7 +37,9 @@ import org.sufficientlysecure.keychain.keyimport.processing.ImportKeysResultList
|
||||
import org.sufficientlysecure.keychain.operations.ImportOperation;
|
||||
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.ui.ViewKeyActivity;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
@@ -131,7 +135,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
||||
final boolean downloaded = keyState.mDownloaded;
|
||||
final boolean showed = keyState.mShowed;
|
||||
|
||||
b.card.setOnClickListener(new View.OnClickListener() {
|
||||
b.card.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mCurrent = position;
|
||||
@@ -143,13 +147,22 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
||||
}
|
||||
});
|
||||
|
||||
b.extra.importKey.setOnClickListener(new View.OnClickListener() {
|
||||
b.extra.importKey.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getKey(entry, false);
|
||||
}
|
||||
});
|
||||
|
||||
b.extra.showKey.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(mActivity, ViewKeyActivity.class);
|
||||
intent.setData(KeyRings.buildGenericKeyRingUri(entry.getKeyId()));
|
||||
mActivity.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
b.extraContainer.setVisibility(showed ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
@@ -210,6 +223,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
||||
|
||||
entry.setRevoked(keyRing.isRevoked());
|
||||
entry.setExpired(keyRing.isExpired());
|
||||
entry.setUpdated(result.isOkUpdated());
|
||||
|
||||
entry.setDate(keyRing.getCreationDate());
|
||||
entry.setKeyId(keyRing.getMasterKeyId());
|
||||
|
||||
Reference in New Issue
Block a user