mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
flag revoked, epired and unavailable keys in selection spinner
This commit is contained in:
parent
857fc43873
commit
0b091aa642
@ -325,6 +325,7 @@ public class KeychainProvider extends ContentProvider {
|
||||
+ " = " + Tables.KEYS + "." + Keys.MASTER_KEY_ID
|
||||
+ " AND kS." + Keys.IS_REVOKED + " = 0"
|
||||
+ " AND kS." + Keys.CAN_SIGN + " = 1"
|
||||
+ " AND kS." + Keys.HAS_SECRET + " > 1"
|
||||
+ " AND ( kS." + Keys.EXPIRY + " IS NULL OR kS." + Keys.EXPIRY
|
||||
+ " >= " + new Date().getTime() / 1000 + " )"
|
||||
+ ")" : "")
|
||||
@ -334,6 +335,7 @@ public class KeychainProvider extends ContentProvider {
|
||||
+ " = " + Tables.KEYS + "." + Keys.MASTER_KEY_ID
|
||||
+ " AND kC." + Keys.IS_REVOKED + " = 0"
|
||||
+ " AND kC." + Keys.CAN_CERTIFY + " = 1"
|
||||
+ " AND kC." + Keys.HAS_SECRET + " > 1"
|
||||
+ " AND ( kC." + Keys.EXPIRY + " IS NULL OR kC." + Keys.EXPIRY
|
||||
+ " >= " + new Date().getTime() / 1000 + " )"
|
||||
+ ")" : "")
|
||||
|
@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.ui.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.Loader;
|
||||
@ -139,9 +140,24 @@ public abstract class KeySpinner extends Spinner implements LoaderManager.Loader
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
String[] userId = KeyRing.splitUserId(cursor.getString(mIndexUserId));
|
||||
((TextView) view.findViewById(R.id.keyspinner_key_name)).setText(userId[2] == null ? userId[0] : (userId[0] + " (" + userId[2] + ")"));
|
||||
TextView vKeyName = ((TextView) view.findViewById(R.id.keyspinner_key_name));
|
||||
TextView vKeyStatus = ((TextView) view.findViewById(R.id.keyspinner_key_status));
|
||||
vKeyName.setText(userId[2] == null ? userId[0] : (userId[0] + " (" + userId[2] + ")"));
|
||||
((TextView) view.findViewById(R.id.keyspinner_key_email)).setText(userId[1]);
|
||||
((TextView) view.findViewById(R.id.keyspinner_key_id)).setText(PgpKeyHelper.convertKeyIdToHex(cursor.getLong(mIndexKeyId)));
|
||||
String status = getStatus(getContext(), cursor);
|
||||
if (status == null) {
|
||||
vKeyName.setTextColor(Color.BLACK);
|
||||
vKeyStatus.setVisibility(View.GONE);
|
||||
view.setClickable(false);
|
||||
} else {
|
||||
vKeyName.setTextColor(Color.GRAY);
|
||||
vKeyStatus.setVisibility(View.VISIBLE);
|
||||
vKeyStatus.setText(status);
|
||||
// this is a HACK. the trick is, if the element itself is clickable, the
|
||||
// click is not passed on to the view list
|
||||
view.setClickable(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -212,13 +228,19 @@ public abstract class KeySpinner extends Spinner implements LoaderManager.Loader
|
||||
}
|
||||
((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_row).setVisibility(View.GONE);
|
||||
} 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);
|
||||
v.findViewById(R.id.keyspinner_key_row).setVisibility(View.VISIBLE);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
/** Return a string which should be the disabled status of the key, or null if the key is enabled. */
|
||||
String getStatus(Context context, Cursor cursor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ import android.os.Bundle;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
|
||||
public class SignKeySpinner extends KeySpinner {
|
||||
@ -51,16 +53,41 @@ public class SignKeySpinner extends KeySpinner {
|
||||
KeychainContract.KeyRings.MASTER_KEY_ID,
|
||||
KeychainContract.KeyRings.KEY_ID,
|
||||
KeychainContract.KeyRings.USER_ID,
|
||||
KeychainContract.KeyRings.IS_REVOKED,
|
||||
KeychainContract.KeyRings.IS_EXPIRED,
|
||||
KeychainContract.KeyRings.HAS_SIGN,
|
||||
KeychainContract.KeyRings.HAS_ANY_SECRET
|
||||
};
|
||||
|
||||
String where = KeychainContract.KeyRings.HAS_ANY_SECRET + " = 1 AND " + KeychainContract.KeyRings.HAS_SIGN + " NOT NULL AND "
|
||||
+ KeychainContract.KeyRings.IS_REVOKED + " = 0 AND " + KeychainContract.KeyRings.IS_EXPIRED + " = 0";
|
||||
String where = KeychainContract.KeyRings.HAS_ANY_SECRET + " = 1";
|
||||
|
||||
// Now create and return a CursorLoader that will take care of
|
||||
// creating a Cursor for the data being displayed.
|
||||
return new CursorLoader(getContext(), baseUri, projection, where, null, null);
|
||||
}
|
||||
|
||||
private int mIndexHasSign, mIndexIsRevoked, mIndexIsExpired;
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
|
||||
super.onLoadFinished(loader, cursor);
|
||||
mIndexHasSign = cursor.getColumnIndex(KeychainContract.KeyRings.HAS_SIGN);
|
||||
mIndexIsRevoked = cursor.getColumnIndex(KeychainContract.KeyRings.IS_REVOKED);
|
||||
mIndexIsExpired = cursor.getColumnIndex(KeychainContract.KeyRings.IS_EXPIRED);
|
||||
}
|
||||
|
||||
@Override
|
||||
String getStatus(Context context, Cursor cursor) {
|
||||
if (cursor.getInt(mIndexIsRevoked) != 0) {
|
||||
return context.getString(R.string.revoked);
|
||||
}
|
||||
if (cursor.getInt(mIndexHasSign) == 0) {
|
||||
return context.getString(R.string.key_unavailable);
|
||||
}
|
||||
if (cursor.getInt(mIndexIsExpired) != 0) {
|
||||
return context.getString(R.string.expired);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,14 +26,38 @@
|
||||
android:layout_marginTop="-4dip"
|
||||
android:text="alice@example.com" />
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:padding="4dp"
|
||||
android:minHeight="24dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/keyspinner_key_row">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/keyspinner_key_id"
|
||||
android:textColor="?android:attr/textColorTertiary"
|
||||
android:textSize="14sp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end"
|
||||
android:typeface="monospace"
|
||||
android:layout_marginTop="-4dip" />
|
||||
android:layout_marginTop="-4dip"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/keyspinner_key_status"
|
||||
android:textColor="#e00"
|
||||
android:textSize="12sp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end"
|
||||
android:layout_gravity="right"
|
||||
android:text="status"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user