Merge branch 'master' of github.com:open-keychain/open-keychain

This commit is contained in:
Dominik Schürmann 2014-09-07 19:01:28 +02:00
commit 6c3f6dc74a
4 changed files with 90 additions and 15 deletions

View File

@ -325,6 +325,7 @@ public class KeychainProvider extends ContentProvider {
+ " = " + Tables.KEYS + "." + Keys.MASTER_KEY_ID + " = " + Tables.KEYS + "." + Keys.MASTER_KEY_ID
+ " AND kS." + Keys.IS_REVOKED + " = 0" + " AND kS." + Keys.IS_REVOKED + " = 0"
+ " AND kS." + Keys.CAN_SIGN + " = 1" + " AND kS." + Keys.CAN_SIGN + " = 1"
+ " AND kS." + Keys.HAS_SECRET + " > 1"
+ " AND ( kS." + Keys.EXPIRY + " IS NULL OR kS." + Keys.EXPIRY + " AND ( kS." + Keys.EXPIRY + " IS NULL OR kS." + Keys.EXPIRY
+ " >= " + new Date().getTime() / 1000 + " )" + " >= " + new Date().getTime() / 1000 + " )"
+ ")" : "") + ")" : "")
@ -334,6 +335,7 @@ public class KeychainProvider extends ContentProvider {
+ " = " + Tables.KEYS + "." + Keys.MASTER_KEY_ID + " = " + Tables.KEYS + "." + Keys.MASTER_KEY_ID
+ " AND kC." + Keys.IS_REVOKED + " = 0" + " AND kC." + Keys.IS_REVOKED + " = 0"
+ " AND kC." + Keys.CAN_CERTIFY + " = 1" + " AND kC." + Keys.CAN_CERTIFY + " = 1"
+ " AND kC." + Keys.HAS_SECRET + " > 1"
+ " AND ( kC." + Keys.EXPIRY + " IS NULL OR kC." + Keys.EXPIRY + " AND ( kC." + Keys.EXPIRY + " IS NULL OR kC." + Keys.EXPIRY
+ " >= " + new Date().getTime() / 1000 + " )" + " >= " + new Date().getTime() / 1000 + " )"
+ ")" : "") + ")" : "")

View File

@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.ui.widget;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Color;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager; import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader; import android.support.v4.content.Loader;
@ -139,9 +140,24 @@ public abstract class KeySpinner extends Spinner implements LoaderManager.Loader
@Override @Override
public void bindView(View view, Context context, Cursor cursor) { public void bindView(View view, Context context, Cursor cursor) {
String[] userId = KeyRing.splitUserId(cursor.getString(mIndexUserId)); 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_email)).setText(userId[1]);
((TextView) view.findViewById(R.id.keyspinner_key_id)).setText(PgpKeyHelper.convertKeyIdToHex(cursor.getLong(mIndexKeyId))); ((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 @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); ((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_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 { } else {
v = inner.getView(position - 1, convertView, parent); v = inner.getView(position - 1, convertView, parent);
v.findViewById(R.id.keyspinner_key_email).setVisibility(View.VISIBLE); 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 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;
}
} }

View File

@ -24,6 +24,8 @@ import android.os.Bundle;
import android.support.v4.content.CursorLoader; import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader; import android.support.v4.content.Loader;
import android.util.AttributeSet; import android.util.AttributeSet;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
public class SignKeySpinner extends KeySpinner { public class SignKeySpinner extends KeySpinner {
@ -51,16 +53,41 @@ public class SignKeySpinner extends KeySpinner {
KeychainContract.KeyRings.MASTER_KEY_ID, KeychainContract.KeyRings.MASTER_KEY_ID,
KeychainContract.KeyRings.KEY_ID, KeychainContract.KeyRings.KEY_ID,
KeychainContract.KeyRings.USER_ID, KeychainContract.KeyRings.USER_ID,
KeychainContract.KeyRings.IS_REVOKED,
KeychainContract.KeyRings.IS_EXPIRED, KeychainContract.KeyRings.IS_EXPIRED,
KeychainContract.KeyRings.HAS_SIGN, KeychainContract.KeyRings.HAS_SIGN,
KeychainContract.KeyRings.HAS_ANY_SECRET KeychainContract.KeyRings.HAS_ANY_SECRET
}; };
String where = KeychainContract.KeyRings.HAS_ANY_SECRET + " = 1 AND " + KeychainContract.KeyRings.HAS_SIGN + " NOT NULL AND " String where = KeychainContract.KeyRings.HAS_ANY_SECRET + " = 1";
+ KeychainContract.KeyRings.IS_REVOKED + " = 0 AND " + KeychainContract.KeyRings.IS_EXPIRED + " = 0";
// Now create and return a CursorLoader that will take care of // Now create and return a CursorLoader that will take care of
// creating a Cursor for the data being displayed. // creating a Cursor for the data being displayed.
return new CursorLoader(getContext(), baseUri, projection, where, null, null); 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;
}
} }

View File

@ -26,14 +26,38 @@
android:layout_marginTop="-4dip" android:layout_marginTop="-4dip"
android:text="alice@example.com" /> android:text="alice@example.com" />
<TextView <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keyspinner_key_id" android:orientation="horizontal"
android:textColor="?android:attr/textColorTertiary" android:layout_width="match_parent"
android:textSize="14sp" android:padding="4dp"
android:layout_width="wrap_content" android:minHeight="24dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" android:id="@+id/keyspinner_key_row">
android:ellipsize="end"
android:typeface="monospace" <TextView
android:layout_marginTop="-4dip" /> android:id="@+id/keyspinner_key_id"
android:textColor="?android:attr/textColorTertiary"
android:textSize="14sp"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="end"
android:typeface="monospace"
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> </LinearLayout>