diff --git a/src/org/thialfihar/android/apg/SelectPublicKeyListActivity.java b/src/org/thialfihar/android/apg/SelectPublicKeyListActivity.java index a487bc1ff..ef734a789 100644 --- a/src/org/thialfihar/android/apg/SelectPublicKeyListActivity.java +++ b/src/org/thialfihar/android/apg/SelectPublicKeyListActivity.java @@ -92,9 +92,7 @@ public class SelectPublicKeyListActivity extends BaseActivity { } long selectedKeyIds[] = null; - if (getIntent().getExtras() != null) { - selectedKeyIds = getIntent().getExtras().getLongArray(Apg.EXTRA_SELECTION); - } + selectedKeyIds = intent.getLongArrayExtra(Apg.EXTRA_SELECTION); if (selectedKeyIds == null) { Vector vector = new Vector(); diff --git a/src/org/thialfihar/android/apg/SelectPublicKeyListAdapter.java b/src/org/thialfihar/android/apg/SelectPublicKeyListAdapter.java index 1b5a20d31..9bb652248 100644 --- a/src/org/thialfihar/android/apg/SelectPublicKeyListAdapter.java +++ b/src/org/thialfihar/android/apg/SelectPublicKeyListAdapter.java @@ -25,6 +25,7 @@ import org.thialfihar.android.apg.provider.UserIds; import android.app.Activity; import android.content.Context; import android.database.Cursor; +import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteQueryBuilder; import android.view.LayoutInflater; @@ -63,6 +64,19 @@ public class SelectPublicKeyListAdapter extends BaseAdapter { UserIds.TABLE_NAME + "." + UserIds.KEY_ID + " AND " + UserIds.TABLE_NAME + "." + UserIds.RANK + " = '0') "); + String inIdList = null; + + if (selectedKeyIds != null && selectedKeyIds.length > 0) { + inIdList = KeyRings.TABLE_NAME + "." + KeyRings.MASTER_KEY_ID + " IN ("; + for (int i = 0; i < selectedKeyIds.length; ++i) { + if (i != 0) { + inIdList += ", "; + } + inIdList += DatabaseUtils.sqlEscapeString("" + selectedKeyIds[i]); + } + inIdList += ")"; + } + if (searchString != null && searchString.trim().length() > 0) { String[] chunks = searchString.trim().split(" +"); qb.appendWhere("(EXISTS (SELECT tmp." + UserIds._ID + " FROM " + @@ -75,21 +89,16 @@ public class SelectPublicKeyListAdapter extends BaseAdapter { } qb.appendWhere("))"); - if (selectedKeyIds != null && selectedKeyIds.length > 0) { - qb.appendWhere(" OR "); - - qb.appendWhere("(" + KeyRings.TABLE_NAME + "." + KeyRings.MASTER_KEY_ID + - " IN ("); - for (int i = 0; i < selectedKeyIds.length; ++i) { - if (i != 0) { - qb.appendWhere(", "); - } - qb.appendWhereEscapeString("" + selectedKeyIds[i]); - } - qb.appendWhere("))"); + if (inIdList != null) { + qb.appendWhere(" OR (" + inIdList + ")"); } } + String orderBy = UserIds.TABLE_NAME + "." + UserIds.USER_ID + " ASC"; + if (inIdList != null) { + orderBy = inIdList + " DESC, " + orderBy; + } + mCursor = qb.query(mDatabase, new String[] { KeyRings.TABLE_NAME + "." + KeyRings._ID, // 0 @@ -111,7 +120,7 @@ public class SelectPublicKeyListAdapter extends BaseAdapter { }, KeyRings.TABLE_NAME + "." + KeyRings.TYPE + " = ?", new String[] { "" + Id.database.type_public }, - null, null, UserIds.TABLE_NAME + "." + UserIds.USER_ID + " ASC"); + null, null, orderBy); activity.startManagingCursor(mCursor); }