From 0b9308753d7339251f9051316b00f6f0c9b0efbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Sun, 5 Oct 2014 04:09:55 +0200 Subject: use status icons in public key selection --- .../keychain/ui/KeyListFragment.java | 4 +-- .../keychain/ui/SelectPublicKeyFragment.java | 20 +++++++++---- .../ui/adapter/SelectKeyCursorAdapter.java | 34 ++++++++++++---------- 3 files changed, 34 insertions(+), 24 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index 0e8444316..9c261cc49 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -59,7 +59,6 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.ExportHelper; import org.sufficientlysecure.keychain.util.KeyUpdateHelper; -import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; @@ -224,7 +223,6 @@ public class KeyListFragment extends LoaderFragment */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mStickyList.setFastScrollAlwaysVisible(true); - mStickyList.addHeaderView(); mStickyList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mStickyList.getWrappedList().setMultiChoiceModeListener(new MultiChoiceModeListener() { @@ -554,7 +552,7 @@ public class KeyListFragment extends LoaderFragment ItemViewHolder holder = new ItemViewHolder(); holder.mMainUserId = (TextView) view.findViewById(R.id.mainUserId); holder.mMainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest); - holder.mStatus = (ImageView) view.findViewById(R.id.status_image); + holder.mStatus = (ImageView) view.findViewById(R.id.status_icon); view.setTag(holder); return view; } 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 9343b166a..621b6b7e1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java @@ -42,9 +42,11 @@ import android.widget.TextView; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.ListFragmentWorkaround; +import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; import org.sufficientlysecure.keychain.ui.adapter.SelectKeyCursorAdapter; +import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import java.util.Vector; @@ -257,9 +259,10 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T KeyRings._ID, KeyRings.MASTER_KEY_ID, KeyRings.USER_ID, - KeyRings.EXPIRY, + KeyRings.IS_EXPIRED, KeyRings.IS_REVOKED, KeyRings.HAS_ENCRYPT, + KeyRings.VERIFIED, }; String inMasterKeyList = null; @@ -344,7 +347,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T private class SelectPublicKeyCursorAdapter extends SelectKeyCursorAdapter { - private int mIndexHasEncrypt; + private int mIndexHasEncrypt, mIndexIsVerified; public SelectPublicKeyCursorAdapter(Context context, Cursor c, int flags, ListView listView) { super(context, c, flags, listView); @@ -355,6 +358,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T super.initIndex(cursor); if (cursor != null) { mIndexHasEncrypt = cursor.getColumnIndexOrThrow(KeyRings.HAS_ENCRYPT); + mIndexIsVerified = cursor.getColumnIndexOrThrow(KeyRings.VERIFIED); } } @@ -369,12 +373,18 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T h.selected.setChecked(getListView().isItemChecked(cursor.getPosition())); boolean enabled = false; - if((Boolean) h.status.getTag()) { + if((Boolean) h.statusIcon.getTag()) { // Check if key is viable for our purposes if (cursor.getInt(mIndexHasEncrypt) == 0) { - h.status.setText(R.string.no_key); + h.statusIcon.setVisibility(View.VISIBLE); + KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, KeyFormattingUtils.STATE_UNAVAILABLE); + enabled = false; + } else if (cursor.getInt(mIndexIsVerified) != 0) { + h.statusIcon.setVisibility(View.VISIBLE); + KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, KeyFormattingUtils.STATE_VERIFIED); + enabled = true; } else { - h.status.setText(R.string.can_encrypt); + h.statusIcon.setVisibility(View.GONE); enabled = true; } } 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 6947fc1ff..c864c7138 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 @@ -24,6 +24,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CheckBox; +import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; @@ -33,8 +34,6 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.ui.util.Highlighter; -import java.util.Date; - /** * Yes this class is abstract! @@ -44,7 +43,7 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter { private String mQuery; private LayoutInflater mInflater; - protected int mIndexUserId, mIndexMasterKeyId, mIndexRevoked, mIndexExpiry; + protected int mIndexUserId, mIndexMasterKeyId, mIndexIsExpiry, mIndexIsRevoked; public SelectKeyCursorAdapter(Context context, Cursor c, int flags, ListView listView) { super(context, c, flags); @@ -73,8 +72,8 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter { if (cursor != null) { mIndexUserId = cursor.getColumnIndexOrThrow(KeyRings.USER_ID); mIndexMasterKeyId = cursor.getColumnIndexOrThrow(KeyRings.MASTER_KEY_ID); - mIndexExpiry = cursor.getColumnIndexOrThrow(KeyRings.EXPIRY); - mIndexRevoked = cursor.getColumnIndexOrThrow(KeyRings.IS_REVOKED); + mIndexIsExpiry = cursor.getColumnIndexOrThrow(KeyRings.IS_EXPIRED); + mIndexIsRevoked = cursor.getColumnIndexOrThrow(KeyRings.IS_REVOKED); } } @@ -90,7 +89,8 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter { public static class ViewHolderItem { public View view; - public TextView mainUserId, mainUserIdRest, keyId, status; + public TextView mainUserId, mainUserIdRest, keyId; + public ImageView statusIcon; public CheckBox selected; public void setEnabled(boolean enabled) { @@ -99,7 +99,7 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter { mainUserId.setEnabled(enabled); mainUserIdRest.setEnabled(enabled); keyId.setEnabled(enabled); - status.setEnabled(enabled); + statusIcon.setEnabled(enabled); // Sorta special: We set an item as clickable to disable it in the ListView. This works // because the list item will handle the clicks itself (which is a nop) @@ -130,19 +130,21 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter { long masterKeyId = cursor.getLong(mIndexMasterKeyId); h.keyId.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(mContext, masterKeyId)); - boolean enabled = true; - if (cursor.getInt(mIndexRevoked) != 0) { - h.status.setText(R.string.revoked); + boolean enabled; + if (cursor.getInt(mIndexIsRevoked) != 0) { + h.statusIcon.setVisibility(View.VISIBLE); + KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, KeyFormattingUtils.STATE_REVOKED); enabled = false; - } else if (!cursor.isNull(mIndexExpiry) - && new Date(cursor.getLong(mIndexExpiry) * 1000).before(new Date())) { - h.status.setText(R.string.expired); + } else if (cursor.getInt(mIndexIsExpiry) != 0) { + h.statusIcon.setVisibility(View.VISIBLE); + KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, KeyFormattingUtils.STATE_EXPIRED); enabled = false; } else { - h.status.setText(""); + h.statusIcon.setVisibility(View.GONE); + enabled = true; } - h.status.setTag(enabled); + h.statusIcon.setTag(enabled); } @Override @@ -153,7 +155,7 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter { holder.mainUserId = (TextView) view.findViewById(R.id.mainUserId); holder.mainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest); holder.keyId = (TextView) view.findViewById(R.id.subkey_item_key_id); - holder.status = (TextView) view.findViewById(R.id.status); + holder.statusIcon = (ImageView) view.findViewById(R.id.status_icon); holder.selected = (CheckBox) view.findViewById(R.id.selected); view.setTag(holder); return view; -- cgit v1.2.3