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,21 +93,30 @@ public class CertifyKeySpinner extends KeySpinner {
mIndexIsRevoked = data.getColumnIndex(KeychainContract.KeyRings.IS_REVOKED);
mIndexIsExpired = data.getColumnIndex(KeychainContract.KeyRings.IS_EXPIRED);
// If there is more than one choice, pick a key
if (mAdapter.getCount() >= 2) {
// If:
// - 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
if (data.moveToPosition(0)) {
do {
int selection = -1;
while (data.moveToNext()) {
if (!data.isNull(mIndexHasCertify)) {
setSelection(data.getPosition() + 1);
break;
}
}
while (data.moveToNext());
if (selection == -1) {
selection = data.getPosition() + 1;
} else {
// if selection is already set, we have more than one certify key!
// get back to "none"!
selection = 0;
}
}
}
setSelection(selection);
}
}
}
@Override
boolean setStatus(Context context, Cursor cursor, ImageView statusView) {

View File

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