ImportKeys: Add creation date and more check on keys's data

This commit is contained in:
Andrea Torlaschi
2016-08-04 17:03:03 +02:00
parent 8c6c97d932
commit ebe7b6293d
25 changed files with 113 additions and 48 deletions

View File

@@ -83,13 +83,21 @@ public abstract class CanonicalizedKeyRing extends KeyRing {
return getRing().getPublicKey().isRevoked();
}
public Date getCreationDate() {
return getPublicKey().getCreationTime();
}
public Date getExpirationDate() {
return getPublicKey().getExpiryTime();
}
public boolean isExpired() {
// Is the master key expired?
Date creationDate = getPublicKey().getCreationTime();
Date expiryDate = getPublicKey().getExpiryTime();
Date creationDate = getCreationDate();
Date expirationDate = getExpirationDate();
Date now = new Date();
return creationDate.after(now) || (expiryDate != null && expiryDate.before(now));
return creationDate.after(now) || (expirationDate != null && expirationDate.before(now));
}
public boolean canCertify() throws PgpKeyNotFoundException {

View File

@@ -236,6 +236,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
ImportKeysListEntry entry = mData.get(mCurrent);
entry.setDate(keyRing.getCreationDate());
entry.setKeyId(keyRing.getMasterKeyId());
ArrayList<String> realUserIdsPlusKeybase = keyRing.getUnorderedUserIds();

View File

@@ -1,7 +1,9 @@
package org.sufficientlysecure.keychain.ui.bindings;
import android.content.Context;
import android.content.res.Resources;
import android.databinding.BindingAdapter;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -12,17 +14,36 @@ import org.sufficientlysecure.keychain.ui.util.Highlighter;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
public class ImportKeysExtraBindings {
@BindingAdapter({"app:keyCreation"})
public static void setCreation(TextView textView, Date creationDate) {
Context context = textView.getContext();
String text;
if (creationDate != null) {
text = DateFormat.getDateFormat(context).format(creationDate);
} else {
Resources resources = context.getResources();
text = resources.getString(R.string.unknown);
}
textView.setText(text);
}
@BindingAdapter({"app:keyId"})
public static void setKeyId(TextView textView, String keyId) {
if (keyId == null)
keyId = "";
textView.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(keyId));
Context context = textView.getContext();
String text;
if (keyId != null){
text = KeyFormattingUtils.beautifyKeyId(keyId);
} else {
Resources resources = context.getResources();
text = resources.getString(R.string.unknown);
}
textView.setText(text);
}
@BindingAdapter({"app:keyUserIds", "app:query"})

View File

@@ -99,7 +99,7 @@ public class KeyFormattingUtils {
default: {
if (context != null) {
algorithmStr = context.getResources().getString(R.string.unknown_algorithm);
algorithmStr = context.getResources().getString(R.string.unknown);
} else {
algorithmStr = "unknown";
}
@@ -154,7 +154,7 @@ public class KeyFormattingUtils {
default: {
if (context != null) {
algorithmStr = context.getResources().getString(R.string.unknown_algorithm);
algorithmStr = context.getResources().getString(R.string.unknown);
} else {
algorithmStr = "unknown";
}
@@ -189,7 +189,7 @@ public class KeyFormattingUtils {
*/
}
if (context != null) {
return context.getResources().getString(R.string.unknown_algorithm);
return context.getResources().getString(R.string.unknown);
} else {
return "unknown";
}
@@ -208,7 +208,7 @@ public class KeyFormattingUtils {
return name;
}
if (context != null) {
return context.getResources().getString(R.string.unknown_algorithm);
return context.getResources().getString(R.string.unknown);
} else {
return "unknown";
}