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());
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
<variable name="nonInteractive" type="boolean" />
|
||||
<variable name="entry" type="ImportKeysListEntry" />
|
||||
<variable name="expanded" type="boolean" />
|
||||
</data>
|
||||
|
||||
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<data>
|
||||
<import type="android.view.View" alias="V" />
|
||||
<import type="org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry" />
|
||||
|
||||
<variable name="entry" type="ImportKeysListEntry" />
|
||||
@@ -98,7 +99,14 @@
|
||||
<Button
|
||||
android:id="@+id/import_key"
|
||||
style="@style/CardViewActionButton"
|
||||
android:text="@string/btn_import" />
|
||||
android:text="@string/btn_import"
|
||||
android:visibility="@{entry.updated ? V.GONE : V.VISIBLE}" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/show_key"
|
||||
style="@style/CardViewActionButton"
|
||||
android:text="@string/btn_show_key"
|
||||
android:visibility="@{entry.updated ? V.VISIBLE : V.GONE}" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -532,6 +532,11 @@
|
||||
<string name="import_qr_code_too_short_fingerprint">"Fingerprint is too short!"</string>
|
||||
<string name="import_qr_code_button">"Scan QR Code"</string>
|
||||
<string name="import_qr_code_text">"Place your camera over the QR Code!"</string>
|
||||
<string name="btn_import">"Import"</string>
|
||||
<string name="btn_import_keys">"Import all keys"</string>
|
||||
<string name="btn_view_list">"View list"</string>
|
||||
<string name="btn_refresh">"Refresh"</string>
|
||||
<string name="btn_show_key">"Show key"</string>
|
||||
|
||||
<!-- Import from URL -->
|
||||
<string name="import_url_warn_no_search_parameter">"No search query defined. You can still manually search on this keyserver."</string>
|
||||
@@ -1573,9 +1578,6 @@
|
||||
<string name="security_token_status_partly">"Security Token matches, partly bound to key"</string>
|
||||
<string name="security_token_create">"Hold Security Token against the back of your device."</string>
|
||||
<string name="security_token_reset_or_import">"This Security Token already contains a key. You can import the key using the cloud or reset the Security Token."</string>
|
||||
<string name="btn_import">"Import"</string>
|
||||
<string name="btn_import_keys">"Import all keys"</string>
|
||||
<string name="btn_view_list">"View list"</string>
|
||||
<string name="btn_reset">"Reset"</string>
|
||||
<string name="security_token_import_radio">"Import key"</string>
|
||||
<string name="security_token_reset_radio">"Reset Security Token"</string>
|
||||
|
||||
Reference in New Issue
Block a user