From fd5719ff6bd6f5b82199368d28a9cacfacf8ab24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Sun, 15 Mar 2015 18:40:52 +0100 Subject: Remove display of key id in other lists --- .../ui/AppSettingsAllowedKeysListFragment.java | 2 + .../remote/ui/SelectSignKeyIdListFragment.java | 2 + .../keychain/ui/SelectPublicKeyFragment.java | 2 + .../ui/adapter/SelectKeyCursorAdapter.java | 32 +++++++++++--- .../ui/widget/EncryptKeyCompletionView.java | 49 ++++++++++++++++------ .../src/main/res/layout/select_key_item.xml | 2 +- 6 files changed, 70 insertions(+), 19 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AppSettingsAllowedKeysListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AppSettingsAllowedKeysListFragment.java index 13b242a5e..b880525ca 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AppSettingsAllowedKeysListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AppSettingsAllowedKeysListFragment.java @@ -205,6 +205,8 @@ public class AppSettingsAllowedKeysListFragment extends ListFragmentWorkaround i KeyRings.HAS_ENCRYPT, KeyRings.VERIFIED, KeyRings.HAS_ANY_SECRET, + KeyRings.HAS_DUPLICATE_USER_ID, + KeyRings.CREATION, }; String inMasterKeyList = null; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/SelectSignKeyIdListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/SelectSignKeyIdListFragment.java index e547d0145..e3768aa9b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/SelectSignKeyIdListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/SelectSignKeyIdListFragment.java @@ -154,6 +154,8 @@ public class SelectSignKeyIdListFragment extends ListFragmentWorkaround implemen KeyRings.HAS_ENCRYPT, KeyRings.VERIFIED, KeyRings.HAS_ANY_SECRET, + KeyRings.HAS_DUPLICATE_USER_ID, + KeyRings.CREATION, }; String selection = KeyRings.HAS_ANY_SECRET + " != 0"; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java index 65d7eca37..6f48b7455 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java @@ -263,6 +263,8 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T KeyRings.IS_REVOKED, KeyRings.HAS_ENCRYPT, KeyRings.VERIFIED, + KeyRings.HAS_DUPLICATE_USER_ID, + KeyRings.CREATION, }; String inMasterKeyList = null; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SelectKeyCursorAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SelectKeyCursorAdapter.java index 226fda20b..892e30a54 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SelectKeyCursorAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SelectKeyCursorAdapter.java @@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.ui.adapter; import android.content.Context; import android.database.Cursor; import android.support.v4.widget.CursorAdapter; +import android.text.format.DateFormat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -35,6 +36,10 @@ import org.sufficientlysecure.keychain.ui.util.Highlighter; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State; +import java.util.Calendar; +import java.util.Date; +import java.util.TimeZone; + /** * Yes this class is abstract! @@ -44,7 +49,8 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter { private String mQuery; private LayoutInflater mInflater; - protected int mIndexUserId, mIndexMasterKeyId, mIndexIsExpiry, mIndexIsRevoked; + protected int mIndexUserId, mIndexMasterKeyId, mIndexIsExpiry, mIndexIsRevoked, + mIndexDuplicateUserId, mIndexCreation; public SelectKeyCursorAdapter(Context context, Cursor c, int flags, ListView listView) { super(context, c, flags); @@ -75,6 +81,8 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter { mIndexMasterKeyId = cursor.getColumnIndexOrThrow(KeyRings.MASTER_KEY_ID); mIndexIsExpiry = cursor.getColumnIndexOrThrow(KeyRings.IS_EXPIRED); mIndexIsRevoked = cursor.getColumnIndexOrThrow(KeyRings.IS_REVOKED); + mIndexDuplicateUserId = cursor.getColumnIndexOrThrow(KeyRings.HAS_DUPLICATE_USER_ID); + mIndexCreation = cursor.getColumnIndexOrThrow(KeyRings.CREATION); } } @@ -90,7 +98,7 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter { public static class ViewHolderItem { public View view; - public TextView mainUserId, mainUserIdRest, keyId; + public TextView mainUserId, mainUserIdRest, creation; public ImageView statusIcon; public CheckBox selected; @@ -99,7 +107,7 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter { selected.setEnabled(enabled); mainUserId.setEnabled(enabled); mainUserIdRest.setEnabled(enabled); - keyId.setEnabled(enabled); + creation.setEnabled(enabled); statusIcon.setEnabled(enabled); // Sorta special: We set an item as clickable to disable it in the ListView. This works @@ -128,8 +136,20 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter { h.mainUserIdRest.setVisibility(View.GONE); } - long masterKeyId = cursor.getLong(mIndexMasterKeyId); - h.keyId.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(mContext, masterKeyId)); + boolean duplicate = cursor.getLong(mIndexDuplicateUserId) > 0; + if (duplicate) { + Date creationDate = new Date(cursor.getLong(mIndexCreation) * 1000); + Calendar creationCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + creationCal.setTime(creationDate); + // convert from UTC to time zone of device + creationCal.setTimeZone(TimeZone.getDefault()); + + h.creation.setText(context.getString(R.string.label_creation) + ": " + + DateFormat.getDateFormat(context).format(creationCal.getTime())); + h.creation.setVisibility(View.VISIBLE); + } else { + h.creation.setVisibility(View.GONE); + } boolean enabled; if (cursor.getInt(mIndexIsRevoked) != 0) { @@ -155,7 +175,7 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter { holder.view = view; holder.mainUserId = (TextView) view.findViewById(R.id.select_key_item_name); holder.mainUserIdRest = (TextView) view.findViewById(R.id.select_key_item_email); - holder.keyId = (TextView) view.findViewById(R.id.select_key_item_key_id); + holder.creation = (TextView) view.findViewById(R.id.select_key_item_creation); holder.statusIcon = (ImageView) view.findViewById(R.id.select_key_item_status_icon); holder.selected = (CheckBox) view.findViewById(R.id.selected); view.setTag(holder); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java index d20e2bc99..94a321f29 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java @@ -28,6 +28,7 @@ import android.support.v4.app.FragmentActivity; import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; +import android.text.format.DateFormat; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; @@ -51,9 +52,12 @@ import org.sufficientlysecure.keychain.util.ContactHelper; import org.sufficientlysecure.keychain.util.Log; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.Locale; +import java.util.TimeZone; public class EncryptKeyCompletionView extends TokenCompleteTextView { public EncryptKeyCompletionView(Context context) { @@ -125,7 +129,9 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView { KeyRings.USER_ID, KeyRings.FINGERPRINT, KeyRings.IS_EXPIRED, - KeyRings.HAS_ENCRYPT + KeyRings.HAS_ENCRYPT, + KeyRings.HAS_DUPLICATE_USER_ID, + KeyRings.CREATION }; String where = KeyRings.HAS_ENCRYPT + " NOT NULL AND " + KeyRings.IS_EXPIRED + " = 0 AND " @@ -153,7 +159,7 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView { public void onFocusChanged(boolean hasFocus, int direction, Rect previous) { super.onFocusChanged(hasFocus, direction, previous); if (hasFocus) { - ((InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE)) + ((InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE)) .showSoftInput(this, InputMethodManager.SHOW_IMPLICIT); } } @@ -180,25 +186,30 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView { private String mUserIdFull; private String[] mUserId; private long mKeyId; + private boolean mHasDuplicate; + private Date mCreation; private String mFingerprint; - public EncryptionKey(String userId, long keyId, String fingerprint) { - this.mUserId = KeyRing.splitUserId(userId); - this.mUserIdFull = userId; - this.mKeyId = keyId; - this.mFingerprint = fingerprint; + public EncryptionKey(String userId, long keyId, boolean hasDuplicate, Date creation, String fingerprint) { + mUserId = KeyRing.splitUserId(userId); + mUserIdFull = userId; + mKeyId = keyId; + mHasDuplicate = hasDuplicate; + mCreation = creation; + mFingerprint = fingerprint; } public EncryptionKey(Cursor cursor) { this(cursor.getString(cursor.getColumnIndexOrThrow(KeyRings.USER_ID)), cursor.getLong(cursor.getColumnIndexOrThrow(KeyRings.KEY_ID)), + cursor.getLong(cursor.getColumnIndexOrThrow(KeyRings.HAS_DUPLICATE_USER_ID)) > 0, + new Date(cursor.getLong(cursor.getColumnIndexOrThrow(KeyRings.CREATION)) * 1000), KeyFormattingUtils.convertFingerprintToHex( cursor.getBlob(cursor.getColumnIndexOrThrow(KeyRings.FINGERPRINT)))); - } public EncryptionKey(CachedPublicKeyRing ring) throws PgpKeyNotFoundException { - this(ring.getPrimaryUserId(), ring.extractOrGetMasterKeyId(), + this(ring.getPrimaryUserId(), ring.extractOrGetMasterKeyId(), false, null, KeyFormattingUtils.convertFingerprintToHex(ring.getFingerprint())); } @@ -222,13 +233,13 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView { if (mUserId[1] != null) { return mUserId[1]; } else { - return getKeyIdHex(); + return getCreationDate(); } } public String getTertiary() { if (mUserId[0] != null) { - return getKeyIdHex(); + return getCreationDate(); } else { return null; } @@ -238,6 +249,20 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView { return mKeyId; } + public String getCreationDate() { + if (mHasDuplicate) { + Calendar creationCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + creationCal.setTime(mCreation); + // convert from UTC to time zone of device + creationCal.setTimeZone(TimeZone.getDefault()); + + return getContext().getString(R.string.label_creation) + ": " + + DateFormat.getDateFormat(getContext()).format(creationCal.getTime()); + } else { + return null; + } + } + public String getKeyIdHex() { return KeyFormattingUtils.beautifyKeyIdWithPrefix(getContext(), mKeyId); } @@ -278,7 +303,7 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView { protected boolean keepObject(EncryptionKey obj, String mask) { String m = mask.toLowerCase(Locale.ENGLISH); return obj.getUserId().toLowerCase(Locale.ENGLISH).contains(m) || - obj.getKeyIdHex().toString().contains(m) || + obj.getKeyIdHex().contains(m) || obj.getKeyIdHexShort().startsWith(m); } } diff --git a/OpenKeychain/src/main/res/layout/select_key_item.xml b/OpenKeychain/src/main/res/layout/select_key_item.xml index e12892aae..aff0a8215 100644 --- a/OpenKeychain/src/main/res/layout/select_key_item.xml +++ b/OpenKeychain/src/main/res/layout/select_key_item.xml @@ -38,7 +38,7 @@ android:textAppearance="?android:attr/textAppearanceSmall" />