Fixes for selection of certify key

This commit is contained in:
Dominik Schürmann 2015-03-15 16:24:06 +01:00
parent ff60e80d42
commit e873bac880
2 changed files with 21 additions and 10 deletions

View File

@ -93,22 +93,31 @@ public class CertifyKeySpinner extends KeySpinner {
mIndexIsRevoked = data.getColumnIndex(KeychainContract.KeyRings.IS_REVOKED); mIndexIsRevoked = data.getColumnIndex(KeychainContract.KeyRings.IS_REVOKED);
mIndexIsExpired = data.getColumnIndex(KeychainContract.KeyRings.IS_EXPIRED); mIndexIsExpired = data.getColumnIndex(KeychainContract.KeyRings.IS_EXPIRED);
// If there is more than one choice, pick a key // If:
if (mAdapter.getCount() >= 2) { // - no key has been pre-selected (e.g. by SageSlinger)
// - there are actually keys (not just "none" entry)
// Then:
// - select key that is capable of certifying, but only if there is only one key capable of it
if (mSelectedKeyId == Constants.key.none && mAdapter.getCount() > 1) {
// preselect if key can certify // preselect if key can certify
if (data.moveToPosition(0)) { int selection = -1;
do { while (data.moveToNext()) {
if (!data.isNull(mIndexHasCertify)) { if (!data.isNull(mIndexHasCertify)) {
setSelection(data.getPosition() + 1); if (selection == -1) {
break; selection = data.getPosition() + 1;
} else {
// if selection is already set, we have more than one certify key!
// get back to "none"!
selection = 0;
} }
} }
while (data.moveToNext());
} }
setSelection(selection);
} }
} }
} }
@Override @Override
boolean setStatus(Context context, Cursor cursor, ImageView statusView) { boolean setStatus(Context context, Cursor cursor, ImageView statusView) {
if (cursor.getInt(mIndexIsRevoked) != 0) { if (cursor.getInt(mIndexIsRevoked) != 0) {

View File

@ -55,7 +55,7 @@ public abstract class KeySpinner extends TintSpinner implements LoaderManager.Lo
public void onKeyChanged(long masterKeyId); public void onKeyChanged(long masterKeyId);
} }
protected long mSelectedKeyId; protected long mSelectedKeyId = Constants.key.none;
protected SelectKeyAdapter mAdapter = new SelectKeyAdapter(); protected SelectKeyAdapter mAdapter = new SelectKeyAdapter();
protected OnKeyChangedListener mListener; protected OnKeyChangedListener mListener;
@ -227,7 +227,9 @@ public abstract class KeySpinner extends TintSpinner implements LoaderManager.Lo
mIndexUserId = newCursor.getColumnIndex(KeychainContract.KeyRings.USER_ID); mIndexUserId = newCursor.getColumnIndex(KeychainContract.KeyRings.USER_ID);
mIndexMasterKeyId = newCursor.getColumnIndex(KeychainContract.KeyRings.MASTER_KEY_ID); mIndexMasterKeyId = newCursor.getColumnIndex(KeychainContract.KeyRings.MASTER_KEY_ID);
mIndexCreationDate = newCursor.getColumnIndex(KeychainContract.KeyRings.CREATION); mIndexCreationDate = newCursor.getColumnIndex(KeychainContract.KeyRings.CREATION);
if (newCursor.moveToFirst()) {
// pre-select key if mSelectedKeyId is given
if (mSelectedKeyId != Constants.key.none && newCursor.moveToFirst()) {
do { do {
if (newCursor.getLong(mIndexMasterKeyId) == mSelectedKeyId) { if (newCursor.getLong(mIndexMasterKeyId) == mSelectedKeyId) {
setSelection(newCursor.getPosition() + 1); setSelection(newCursor.getPosition() + 1);