key spinner fixes

This commit is contained in:
Dominik Schürmann 2014-09-21 12:03:25 +02:00
parent 08ad0cb305
commit 1d38365a61
3 changed files with 50 additions and 33 deletions

View File

@ -335,13 +335,13 @@ public class KeychainProvider extends ContentProvider {
+ " >= " + new Date().getTime() / 1000 + " )"
+ ")" : "")
+ (plist.contains(KeyRings.HAS_AUTHENTICATE) ?
" LEFT JOIN " + Tables.KEYS + " AS kS ON ("
+"kS." + Keys.MASTER_KEY_ID
" LEFT JOIN " + Tables.KEYS + " AS kA ON ("
+"kA." + Keys.MASTER_KEY_ID
+ " = " + Tables.KEYS + "." + Keys.MASTER_KEY_ID
+ " AND kS." + Keys.IS_REVOKED + " = 0"
+ " AND kS." + Keys.CAN_AUTHENTICATE + " = 1"
+ " AND kS." + Keys.HAS_SECRET + " > 1"
+ " AND ( kS." + Keys.EXPIRY + " IS NULL OR kS." + Keys.EXPIRY
+ " AND kA." + Keys.IS_REVOKED + " = 0"
+ " AND kA." + Keys.CAN_AUTHENTICATE + " = 1"
+ " AND kA." + Keys.HAS_SECRET + " > 1"
+ " AND ( kA." + Keys.EXPIRY + " IS NULL OR kA." + Keys.EXPIRY
+ " >= " + new Date().getTime() / 1000 + " )"
+ ")" : "")
+ (plist.contains(KeyRings.HAS_CERTIFY) ?

View File

@ -237,7 +237,7 @@ public class CertifyKeyFragment extends LoaderFragment
if (data.moveToFirst()) {
mPubKeyId = data.getLong(INDEX_MASTER_KEY_ID);
mCertifyKeySpinner.setHiddenMasterKeyId(mPubKeyId);
String keyIdStr = KeyFormattingUtils.convertKeyIdToHex(mPubKeyId);
String keyIdStr = KeyFormattingUtils.beautifyKeyId(mPubKeyId);
mInfoKeyId.setText(keyIdStr);
String mainUserId = data.getString(INDEX_USER_ID);

View File

@ -151,7 +151,28 @@ public abstract class KeySpinner extends Spinner implements LoaderManager.Loader
vKeyId.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(getContext(), cursor.getLong(mIndexKeyId)));
boolean valid = setStatus(getContext(), cursor, vKeyStatus);
if (valid) {
setItemEnabled(view, valid);
}
@Override
public long getItemId(int position) {
try {
return ((Cursor) getItem(position)).getLong(mIndexMasterKeyId);
} catch (Exception e) {
// This can happen on concurrent modification :(
return Constants.key.none;
}
}
};
}
private void setItemEnabled(View view, boolean enabled) {
TextView vKeyName = (TextView) view.findViewById(R.id.keyspinner_key_name);
ImageView vKeyStatus = (ImageView) view.findViewById(R.id.keyspinner_key_status);
TextView vKeyEmail = (TextView) view.findViewById(R.id.keyspinner_key_email);
TextView vKeyId = (TextView) view.findViewById(R.id.keyspinner_key_id);
if (enabled) {
vKeyName.setTextColor(Color.BLACK);
vKeyEmail.setTextColor(Color.BLACK);
vKeyId.setTextColor(Color.BLACK);
@ -168,18 +189,6 @@ public abstract class KeySpinner extends Spinner implements LoaderManager.Loader
}
}
@Override
public long getItemId(int position) {
try {
return ((Cursor) getItem(position)).getLong(mIndexMasterKeyId);
} catch (Exception e) {
// This can happen on concurrent modification :(
return Constants.key.none;
}
}
};
}
public Cursor swapCursor(Cursor newCursor) {
if (newCursor == null) return inner.swapCursor(null);
@ -227,23 +236,31 @@ public abstract class KeySpinner extends Spinner implements LoaderManager.Loader
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
View v;
View view;
if (position == 0) {
if (convertView == null) {
v = inner.newView(null, null, parent);
view = inner.newView(null, null, parent);
} else {
v = convertView;
view = convertView;
}
((TextView) v.findViewById(R.id.keyspinner_key_name)).setText(R.string.choice_none);
v.findViewById(R.id.keyspinner_key_email).setVisibility(View.GONE);
v.findViewById(R.id.keyspinner_key_id).setVisibility(View.GONE);
v.findViewById(R.id.keyspinner_key_status).setVisibility(View.GONE);
TextView vKeyName = (TextView) view.findViewById(R.id.keyspinner_key_name);
ImageView vKeyStatus = (ImageView) view.findViewById(R.id.keyspinner_key_status);
TextView vKeyEmail = (TextView) view.findViewById(R.id.keyspinner_key_email);
TextView vKeyId = (TextView) view.findViewById(R.id.keyspinner_key_id);
vKeyName.setText(R.string.choice_none);
vKeyEmail.setVisibility(View.GONE);
vKeyId.setVisibility(View.GONE);
vKeyStatus.setVisibility(View.GONE);
setItemEnabled(view, true);
} else {
v = inner.getView(position - 1, convertView, parent);
v.findViewById(R.id.keyspinner_key_email).setVisibility(View.VISIBLE);
v.findViewById(R.id.keyspinner_key_id).setVisibility(View.VISIBLE);
view = inner.getView(position - 1, convertView, parent);
TextView vKeyEmail = (TextView) view.findViewById(R.id.keyspinner_key_email);
TextView vKeyId = (TextView) view.findViewById(R.id.keyspinner_key_id);
vKeyEmail.setVisibility(View.VISIBLE);
vKeyId.setVisibility(View.VISIBLE);
}
return v;
return view;
}
}