Add missing columns for projections, remove use of raw user id

This commit is contained in:
Dominik Schürmann
2017-01-27 00:52:54 +01:00
parent 732aa0de60
commit 78bbe20149
5 changed files with 30 additions and 73 deletions

View File

@@ -192,11 +192,11 @@ public class KeySectionedListAdapter extends SectionCursorAdapter<KeySectionedLi
return '#';
} else {
String userId = cursor.getRawUserId();
if (TextUtils.isEmpty(userId)) {
return '?';
String name = cursor.getName();
if (name != null) {
return Character.toUpperCase(name.charAt(0));
} else {
return Character.toUpperCase(userId.charAt(0));
return '?';
}
}
}
@@ -313,11 +313,11 @@ public class KeySectionedListAdapter extends SectionCursorAdapter<KeySectionedLi
return "My";
} else {
String userId = cursor.getRawUserId();
if (TextUtils.isEmpty(userId)) {
return null;
String name = cursor.getName();
if (name != null) {
return name.substring(0, 1).toUpperCase();
} else {
return userId.substring(0, 1).toUpperCase();
return null;
}
}
} else {

View File

@@ -32,7 +32,6 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.util.Log;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@@ -65,7 +64,7 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
* When using this constructor, {@link #FLAG_REGISTER_CONTENT_OBSERVER}
* will always be set.
*
* @param c The cursor from which to get the data.
* @param c The cursor from which to get the data.
* @param context The context
*/
public CursorAdapter(Context context, C c) {
@@ -76,9 +75,9 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
/**
* Recommended constructor.
*
* @param c The cursor from which to get the data.
* @param c The cursor from which to get the data.
* @param context The context
* @param flags Flags used to determine the behavior of the adapter
* @param flags Flags used to determine the behavior of the adapter
* @see #FLAG_REGISTER_CONTENT_OBSERVER
*/
public CursorAdapter(Context context, C c, int flags) {
@@ -109,6 +108,7 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
/**
* Returns the cursor.
*
* @return the cursor.
*/
public C getCursor() {
@@ -147,10 +147,9 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
}
/**
* @see android.support.v7.widget.RecyclerView.Adapter#getItemId(int)
*
* @param position Adapter position to query
* @return the id of the item
* @see android.support.v7.widget.RecyclerView.Adapter#getItemId(int)
*/
@Override
public long getItemId(int position) {
@@ -168,11 +167,12 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
/**
* Return the id of the item represented by the row the cursor
* is currently moved to.
*
* @param cursor The cursor moved to the correct position.
* @return The id of the dataset
*/
public long getIdFromCursor(C cursor) {
if(cursor != null) {
if (cursor != null) {
return cursor.getEntryId();
} else {
return RecyclerView.NO_ID;
@@ -182,28 +182,28 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
public void moveCursorOrThrow(int position)
throws IndexOutOfBoundsException, IllegalStateException {
if(position >= getItemCount() || position < -1) {
if (position >= getItemCount() || position < -1) {
throw new IndexOutOfBoundsException("Position: " + position
+ " is invalid for this data set!");
}
if(!mDataValid) {
if (!mDataValid) {
throw new IllegalStateException("Attempt to move cursor over invalid data set!");
}
if(!mCursor.moveToPosition(position)) {
if (!mCursor.moveToPosition(position)) {
throw new IllegalStateException("Couldn't move cursor from position: "
+ mCursor.getPosition() + " to position: " + position + "!");
}
}
public boolean moveCursor(int position) {
if(position >= getItemCount() || position < -1) {
if (position >= getItemCount() || position < -1) {
Log.w(TAG, "Position: %d is invalid for this data set!");
return false;
}
if(!mDataValid) {
if (!mDataValid) {
Log.d(TAG, "Attempt to move cursor over invalid data set!");
}
@@ -315,7 +315,7 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
}
public static abstract class AbstractCursor extends CursorWrapper {
public static final String[] PROJECTION = { "_id" };
public static final String[] PROJECTION = {"_id"};
public static <T extends AbstractCursor> T wrap(Cursor cursor, Class<T> type) {
if (cursor != null) {
@@ -356,10 +356,10 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
@Override
public final int getColumnIndexOrThrow(String colName) {
Integer colIndex = mColumnIndices.get(colName);
if(colIndex == null) {
if (colIndex == null) {
colIndex = super.getColumnIndexOrThrow(colName);
mColumnIndices.put(colName, colIndex);
} else if (colIndex < 0){
} else if (colIndex < 0) {
throw new IllegalArgumentException("Could not get column index for name: \"" + colName + "\"");
}
@@ -369,7 +369,7 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
@Override
public final int getColumnIndex(String colName) {
Integer colIndex = mColumnIndices.get(colName);
if(colIndex == null) {
if (colIndex == null) {
colIndex = super.getColumnIndex(colName);
mColumnIndices.put(colName, colIndex);
}
@@ -421,11 +421,6 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
return getLong(index);
}
public String getRawUserId() {
int index = getColumnIndexOrThrow(KeychainContract.KeyRings.USER_ID);
return getString(index);
}
public String getName() {
int index = getColumnIndexOrThrow(KeychainContract.KeyRings.NAME);
return getString(index);
@@ -441,11 +436,6 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
return getString(index);
}
@Deprecated
public OpenPgpUtils.UserId getUserId() {
return KeyRing.splitUserId(getRawUserId());
}
public boolean hasDuplicate() {
int index = getColumnIndexOrThrow(KeychainContract.KeyRings.HAS_DUPLICATE_USER_ID);
return getLong(index) > 0L;