actually disable non-enabled items in keyspinner (in keyadapter) (fixes #1366)

This commit is contained in:
Vincent Breitmoser
2015-07-06 17:18:56 +02:00
parent e172f132e4
commit 148867ae86
3 changed files with 34 additions and 15 deletions

View File

@@ -21,7 +21,6 @@ package org.sufficientlysecure.keychain.ui.adapter;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@@ -107,7 +106,7 @@ public class KeyAdapter extends CursorAdapter {
mCreationDate = (TextView) view.findViewById(R.id.key_list_item_creation); 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; 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 { // set edit button and status, specific by key type
mMasterKeyId = item.mKeyId; mMasterKeyId = item.mKeyId;
int textColor;
// Note: order is important! // Note: order is important!
if (item.mIsRevoked) { if (item.mIsRevoked) {
KeyFormattingUtils KeyFormattingUtils
.setStatusImage(context, mStatus, null, State.REVOKED, R.color.bg_gray); .setStatusImage(context, mStatus, null, State.REVOKED, R.color.bg_gray);
mStatus.setVisibility(View.VISIBLE); mStatus.setVisibility(View.VISIBLE);
mSlinger.setVisibility(View.GONE); mSlinger.setVisibility(View.GONE);
mMainUserId.setTextColor(context.getResources().getColor(R.color.bg_gray)); textColor = R.color.bg_gray;
mMainUserIdRest.setTextColor(context.getResources().getColor(R.color.bg_gray));
} else if (item.mIsExpired) { } else if (item.mIsExpired) {
KeyFormattingUtils.setStatusImage(context, mStatus, null, State.EXPIRED, R.color.bg_gray); KeyFormattingUtils.setStatusImage(context, mStatus, null, State.EXPIRED, R.color.bg_gray);
mStatus.setVisibility(View.VISIBLE); mStatus.setVisibility(View.VISIBLE);
mSlinger.setVisibility(View.GONE); mSlinger.setVisibility(View.GONE);
mMainUserId.setTextColor(context.getResources().getColor(R.color.bg_gray)); textColor = R.color.bg_gray;
mMainUserIdRest.setTextColor(context.getResources().getColor(R.color.bg_gray));
} else if (item.mIsSecret) { } else if (item.mIsSecret) {
mStatus.setVisibility(View.GONE); mStatus.setVisibility(View.GONE);
if (mSlingerButton.hasOnClickListeners()) { if (mSlingerButton.hasOnClickListeners()) {
@@ -154,8 +157,7 @@ public class KeyAdapter extends CursorAdapter {
} else { } else {
mSlinger.setVisibility(View.GONE); mSlinger.setVisibility(View.GONE);
} }
mMainUserId.setTextColor(context.getResources().getColor(R.color.black)); textColor = R.color.black;
mMainUserIdRest.setTextColor(context.getResources().getColor(R.color.black));
} else { } else {
// this is a public key - show if it's verified // this is a public key - show if it's verified
if (item.mIsVerified) { if (item.mIsVerified) {
@@ -166,10 +168,16 @@ public class KeyAdapter extends CursorAdapter {
mStatus.setVisibility(View.VISIBLE); mStatus.setVisibility(View.VISIBLE);
} }
mSlinger.setVisibility(View.GONE); mSlinger.setVisibility(View.GONE);
mMainUserId.setTextColor(context.getResources().getColor(R.color.black)); textColor = R.color.black;
mMainUserIdRest.setTextColor(context.getResources().getColor(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) { if (item.mHasDuplicate) {
String dateTime = DateUtils.formatDateTime(context, String dateTime = DateUtils.formatDateTime(context,
item.mCreation.getTime(), item.mCreation.getTime(),
@@ -205,9 +213,11 @@ public class KeyAdapter extends CursorAdapter {
@Override @Override
public void bindView(View view, Context context, Cursor cursor) { public void bindView(View view, Context context, Cursor cursor) {
Highlighter highlighter = new Highlighter(context, mQuery); Highlighter highlighter = new Highlighter(context, mQuery);
KeyItemViewHolder h = (KeyItemViewHolder) view.getTag();
KeyItem item = new KeyItem(cursor); 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) { public boolean isSecretAvailable(int id) {

View File

@@ -109,14 +109,18 @@ public class CertifyKeySpinner extends KeySpinner {
@Override @Override
boolean isItemEnabled(Cursor cursor) { boolean isItemEnabled(Cursor cursor) {
// "none" entry is always enabled!
if (cursor.getPosition() == 0) {
return true;
}
if (cursor.getInt(KeyAdapter.INDEX_IS_REVOKED) != 0) { if (cursor.getInt(KeyAdapter.INDEX_IS_REVOKED) != 0) {
return false; return false;
} }
if (cursor.getInt(KeyAdapter.INDEX_IS_EXPIRED) != 0) { if (cursor.getInt(KeyAdapter.INDEX_IS_EXPIRED) != 0) {
return false; return false;
} }
// don't invalidate the "None" entry, which is also null! if (cursor.isNull(mIndexHasCertify)) {
if (cursor.getPosition() != 0 && cursor.isNull(mIndexHasCertify)) {
return false; return false;
} }

View File

@@ -72,13 +72,18 @@ public class SignKeySpinner extends KeySpinner {
@Override @Override
boolean isItemEnabled(Cursor cursor) { boolean isItemEnabled(Cursor cursor) {
// "none" entry is always enabled!
if (cursor.getPosition() == 0) {
return true;
}
if (cursor.getInt(KeyAdapter.INDEX_IS_REVOKED) != 0) { if (cursor.getInt(KeyAdapter.INDEX_IS_REVOKED) != 0) {
return false; return false;
} }
if (cursor.getInt(KeyAdapter.INDEX_IS_EXPIRED) != 0) { if (cursor.getInt(KeyAdapter.INDEX_IS_EXPIRED) != 0) {
return false; return false;
} }
if (cursor.getInt(mIndexHasSign) == 0) { if (cursor.isNull(mIndexHasSign)) {
return false; return false;
} }