actually disable non-enabled items in keyspinner (in keyadapter) (fixes #1366)
This commit is contained in:
@@ -21,7 +21,6 @@ package org.sufficientlysecure.keychain.ui.adapter;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -107,7 +106,7 @@ public class KeyAdapter extends CursorAdapter {
|
||||
mCreationDate = (TextView) view.findViewById(R.id.key_list_item_creation);
|
||||
}
|
||||
|
||||
public void setData(Context context, KeyItem item, Highlighter highlighter) {
|
||||
public void setData(Context context, KeyItem item, Highlighter highlighter, boolean enabled) {
|
||||
|
||||
mDisplayedItem = item;
|
||||
|
||||
@@ -126,24 +125,28 @@ public class KeyAdapter extends CursorAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
// sort of a hack: if this item isn't enabled, we make it clickable
|
||||
// to intercept its click events
|
||||
mView.setClickable(!enabled);
|
||||
|
||||
{ // set edit button and status, specific by key type
|
||||
|
||||
mMasterKeyId = item.mKeyId;
|
||||
|
||||
int textColor;
|
||||
|
||||
// Note: order is important!
|
||||
if (item.mIsRevoked) {
|
||||
KeyFormattingUtils
|
||||
.setStatusImage(context, mStatus, null, State.REVOKED, R.color.bg_gray);
|
||||
mStatus.setVisibility(View.VISIBLE);
|
||||
mSlinger.setVisibility(View.GONE);
|
||||
mMainUserId.setTextColor(context.getResources().getColor(R.color.bg_gray));
|
||||
mMainUserIdRest.setTextColor(context.getResources().getColor(R.color.bg_gray));
|
||||
textColor = R.color.bg_gray;
|
||||
} else if (item.mIsExpired) {
|
||||
KeyFormattingUtils.setStatusImage(context, mStatus, null, State.EXPIRED, R.color.bg_gray);
|
||||
mStatus.setVisibility(View.VISIBLE);
|
||||
mSlinger.setVisibility(View.GONE);
|
||||
mMainUserId.setTextColor(context.getResources().getColor(R.color.bg_gray));
|
||||
mMainUserIdRest.setTextColor(context.getResources().getColor(R.color.bg_gray));
|
||||
textColor = R.color.bg_gray;
|
||||
} else if (item.mIsSecret) {
|
||||
mStatus.setVisibility(View.GONE);
|
||||
if (mSlingerButton.hasOnClickListeners()) {
|
||||
@@ -154,8 +157,7 @@ public class KeyAdapter extends CursorAdapter {
|
||||
} else {
|
||||
mSlinger.setVisibility(View.GONE);
|
||||
}
|
||||
mMainUserId.setTextColor(context.getResources().getColor(R.color.black));
|
||||
mMainUserIdRest.setTextColor(context.getResources().getColor(R.color.black));
|
||||
textColor = R.color.black;
|
||||
} else {
|
||||
// this is a public key - show if it's verified
|
||||
if (item.mIsVerified) {
|
||||
@@ -166,10 +168,16 @@ public class KeyAdapter extends CursorAdapter {
|
||||
mStatus.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mSlinger.setVisibility(View.GONE);
|
||||
mMainUserId.setTextColor(context.getResources().getColor(R.color.black));
|
||||
mMainUserIdRest.setTextColor(context.getResources().getColor(R.color.black));
|
||||
textColor = R.color.black;
|
||||
}
|
||||
|
||||
if (!enabled) {
|
||||
textColor = R.color.bg_gray;
|
||||
}
|
||||
|
||||
mMainUserId.setTextColor(context.getResources().getColor(textColor));
|
||||
mMainUserIdRest.setTextColor(context.getResources().getColor(textColor));
|
||||
|
||||
if (item.mHasDuplicate) {
|
||||
String dateTime = DateUtils.formatDateTime(context,
|
||||
item.mCreation.getTime(),
|
||||
@@ -205,9 +213,11 @@ public class KeyAdapter extends CursorAdapter {
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
Highlighter highlighter = new Highlighter(context, mQuery);
|
||||
KeyItemViewHolder h = (KeyItemViewHolder) view.getTag();
|
||||
KeyItem item = new KeyItem(cursor);
|
||||
h.setData(context, item, highlighter);
|
||||
boolean isEnabled = isEnabled(cursor);
|
||||
|
||||
KeyItemViewHolder h = (KeyItemViewHolder) view.getTag();
|
||||
h.setData(context, item, highlighter, isEnabled);
|
||||
}
|
||||
|
||||
public boolean isSecretAvailable(int id) {
|
||||
|
||||
@@ -109,14 +109,18 @@ public class CertifyKeySpinner extends KeySpinner {
|
||||
|
||||
@Override
|
||||
boolean isItemEnabled(Cursor cursor) {
|
||||
// "none" entry is always enabled!
|
||||
if (cursor.getPosition() == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (cursor.getInt(KeyAdapter.INDEX_IS_REVOKED) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (cursor.getInt(KeyAdapter.INDEX_IS_EXPIRED) != 0) {
|
||||
return false;
|
||||
}
|
||||
// don't invalidate the "None" entry, which is also null!
|
||||
if (cursor.getPosition() != 0 && cursor.isNull(mIndexHasCertify)) {
|
||||
if (cursor.isNull(mIndexHasCertify)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,13 +72,18 @@ public class SignKeySpinner extends KeySpinner {
|
||||
|
||||
@Override
|
||||
boolean isItemEnabled(Cursor cursor) {
|
||||
// "none" entry is always enabled!
|
||||
if (cursor.getPosition() == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (cursor.getInt(KeyAdapter.INDEX_IS_REVOKED) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (cursor.getInt(KeyAdapter.INDEX_IS_EXPIRED) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (cursor.getInt(mIndexHasSign) == 0) {
|
||||
if (cursor.isNull(mIndexHasSign)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user