From 6e2b21b6b70c12995027f81acedb68c6069c5fb8 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 6 Apr 2014 02:27:21 +0200 Subject: [PATCH] certs: fix CertifyKeyActivity and improve user id list --- .../keychain/ui/CertifyKeyActivity.java | 32 ++++++++----------- .../keychain/ui/ViewKeyMainFragment.java | 7 +--- .../ui/adapter/ViewKeyUserIdsAdapter.java | 25 ++++++++++----- .../main/res/layout/certify_key_activity.xml | 5 +-- .../main/res/layout/view_key_userids_item.xml | 7 ++-- 5 files changed, 39 insertions(+), 37 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyActivity.java index 2efa8a69c..7027c114e 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyActivity.java @@ -46,8 +46,8 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.Preferences; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; -import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.KeychainDatabase; +import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; +import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; @@ -148,43 +148,37 @@ public class CertifyKeyActivity extends ActionBarActivity implements mUserIdsAdapter = new ViewKeyUserIdsAdapter(this, null, 0, true); mUserIds.setAdapter(mUserIdsAdapter); + mUserIds.setOnItemClickListener(mUserIdsAdapter); getSupportLoaderManager().initLoader(LOADER_ID_KEYRING, null, this); getSupportLoaderManager().initLoader(LOADER_ID_USER_IDS, null, this); } + static final String USER_IDS_SELECTION = UserIds.IS_REVOKED + " = 0"; + static final String[] KEYRING_PROJECTION = new String[] { - KeychainContract.KeyRings._ID, - KeychainContract.Keys.MASTER_KEY_ID, - KeychainContract.Keys.FINGERPRINT, - KeychainContract.UserIds.USER_ID, + KeyRings._ID, + KeyRings.MASTER_KEY_ID, + KeyRings.FINGERPRINT, + KeyRings.USER_ID, }; static final int INDEX_MASTER_KEY_ID = 1; static final int INDEX_FINGERPRINT = 2; static final int INDEX_USER_ID = 3; - static final String[] USER_IDS_PROJECTION = - new String[]{ - KeychainContract.UserIds._ID, - KeychainContract.UserIds.USER_ID, - KeychainContract.UserIds.RANK, - "verified" - }; - static final String USER_IDS_SORT_ORDER = - KeychainDatabase.Tables.USER_IDS + "." + KeychainContract.UserIds.RANK + " ASC"; - @Override public Loader onCreateLoader(int id, Bundle args) { switch(id) { case LOADER_ID_KEYRING: { - Uri uri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri); + Uri uri = KeyRings.buildUnifiedKeyRingUri(mDataUri); return new CursorLoader(this, uri, KEYRING_PROJECTION, null, null, null); } case LOADER_ID_USER_IDS: { - Uri uri = KeychainContract.UserIds.buildUserIdsUri(mDataUri); - return new CursorLoader(this, uri, USER_IDS_PROJECTION, null, null, USER_IDS_SORT_ORDER); + Uri uri = UserIds.buildUserIdsUri(mDataUri); + return new CursorLoader(this, uri, + ViewKeyUserIdsAdapter.USER_IDS_PROJECTION, USER_IDS_SELECTION, null, null); } } return null; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java index 60df6970d..d12f00547 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java @@ -174,11 +174,6 @@ public class ViewKeyMainFragment extends Fragment implements static final int INDEX_UNIFIED_CREATION = 7; static final int INDEX_UNIFIED_EXPIRY = 8; - static final String[] USER_IDS_PROJECTION = new String[] { - UserIds._ID, UserIds.USER_ID, UserIds.RANK, - UserIds.VERIFIED, UserIds.IS_PRIMARY, UserIds.IS_REVOKED - }; - static final String[] KEYS_PROJECTION = new String[] { Keys._ID, Keys.KEY_ID, Keys.RANK, Keys.ALGORITHM, Keys.KEY_SIZE, @@ -195,7 +190,7 @@ public class ViewKeyMainFragment extends Fragment implements } case LOADER_ID_USER_IDS: { Uri baseUri = UserIds.buildUserIdsUri(mDataUri); - return new CursorLoader(getActivity(), baseUri, USER_IDS_PROJECTION, null, null, null); + return new CursorLoader(getActivity(), baseUri, ViewKeyUserIdsAdapter.USER_IDS_PROJECTION, null, null, null); } case LOADER_ID_KEYS: { Uri baseUri = Keys.buildKeysUri(mDataUri); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ViewKeyUserIdsAdapter.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ViewKeyUserIdsAdapter.java index 023d3d660..09137f745 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ViewKeyUserIdsAdapter.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ViewKeyUserIdsAdapter.java @@ -23,6 +23,7 @@ import android.support.v4.widget.CursorAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.ImageView; @@ -34,7 +35,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import java.util.ArrayList; -public class ViewKeyUserIdsAdapter extends CursorAdapter { +public class ViewKeyUserIdsAdapter extends CursorAdapter implements AdapterView.OnItemClickListener { private LayoutInflater mInflater; private int mIndexUserId, mIndexRank; @@ -42,6 +43,11 @@ public class ViewKeyUserIdsAdapter extends CursorAdapter { private final ArrayList mCheckStates; + public static final String[] USER_IDS_PROJECTION = new String[] { + UserIds._ID, UserIds.USER_ID, UserIds.RANK, + UserIds.VERIFIED, UserIds.IS_PRIMARY, UserIds.IS_REVOKED + }; + public ViewKeyUserIdsAdapter(Context context, Cursor c, int flags, boolean showCheckBoxes) { super(context, c, flags); @@ -67,7 +73,7 @@ public class ViewKeyUserIdsAdapter extends CursorAdapter { for(int i = 0; i < count; i++) { newCursor.moveToPosition(i); int verified = newCursor.getInt(mVerifiedId); - mCheckStates.add(verified == 0); + mCheckStates.add(verified != Certs.VERIFIED_SECRET); } } } @@ -114,6 +120,7 @@ public class ViewKeyUserIdsAdapter extends CursorAdapter { vAddress.setText(userId[1]); if(cursor.getInt(mIsRevoked) > 0) { + vRank.setText(" "); vVerified.setImageResource(android.R.drawable.presence_away); } else { int verified = cursor.getInt(mVerifiedId); @@ -141,15 +148,17 @@ public class ViewKeyUserIdsAdapter extends CursorAdapter { mCheckStates.set(position, b); } }); - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - vCheckBox.toggle(); - } - }); + vCheckBox.setClickable(false); } + public void onItemClick(AdapterView adapter, View view, int position, long id) { + CheckBox box = ((CheckBox) view.findViewById(R.id.checkBox)); + if(box != null) { + box.toggle(); + } + } + public ArrayList getSelectedUserIds() { ArrayList result = new ArrayList(); for (int i = 0; i < mCheckStates.size(); i++) { diff --git a/OpenPGP-Keychain/src/main/res/layout/certify_key_activity.xml b/OpenPGP-Keychain/src/main/res/layout/certify_key_activity.xml index 6cd140739..3fa0468de 100644 --- a/OpenPGP-Keychain/src/main/res/layout/certify_key_activity.xml +++ b/OpenPGP-Keychain/src/main/res/layout/certify_key_activity.xml @@ -2,7 +2,7 @@ + android:layout_height="wrap_content" + android:descendantFocusability="blocksDescendants" /> + android:id="@+id/checkBox" + android:clickable="false" + android:focusable="false" /> + android:layout_gravity="center_vertical" + android:width="30sp" />