Pre-cache attachment content URIs

Saves us a DB read on the UI thread.

b/15939030

Change-Id: I1b8174880ccc9dc06df6b57df2bd8d44a2fe05d4
This commit is contained in:
Tony Mantler 2014-06-30 10:21:25 -07:00
parent 3c5af60cc2
commit e292027fa7

View File

@ -4130,23 +4130,32 @@ public class EmailProvider extends ContentProvider
private final int mContentUriIndex; private final int mContentUriIndex;
private final int mUriIndex; private final int mUriIndex;
private final Context mContext; private final Context mContext;
private final String[] mContentUriStrings;
public AttachmentsCursor(Context context, Cursor cursor) { public AttachmentsCursor(Context context, Cursor cursor) {
super(cursor); super(cursor);
mContentUriIndex = cursor.getColumnIndex(UIProvider.AttachmentColumns.CONTENT_URI); mContentUriIndex = cursor.getColumnIndex(UIProvider.AttachmentColumns.CONTENT_URI);
mUriIndex = cursor.getColumnIndex(UIProvider.AttachmentColumns.URI); mUriIndex = cursor.getColumnIndex(UIProvider.AttachmentColumns.URI);
mContext = context; mContext = context;
} mContentUriStrings = new String[cursor.getCount()];
if (mContentUriIndex == -1) {
@Override // Nothing to do here, move along
public String getString(int column) { return;
if (column == mContentUriIndex) { }
while (cursor.moveToNext()) {
final int index = cursor.getPosition();
final Uri uri = Uri.parse(getString(mUriIndex)); final Uri uri = Uri.parse(getString(mUriIndex));
final long id = Long.parseLong(uri.getLastPathSegment()); final long id = Long.parseLong(uri.getLastPathSegment());
final Attachment att = Attachment.restoreAttachmentWithId(mContext, id); final Attachment att = Attachment.restoreAttachmentWithId(mContext, id);
if (att == null) return "";
if (att == null) {
mContentUriStrings[index] = "";
continue;
}
if (!TextUtils.isEmpty(att.getCachedFileUri())) { if (!TextUtils.isEmpty(att.getCachedFileUri())) {
return att.getCachedFileUri(); mContentUriStrings[index] = att.getCachedFileUri();
continue;
} }
final String contentUri; final String contentUri;
@ -4172,8 +4181,16 @@ public class EmailProvider extends ContentProvider
.toString(); .toString();
} }
} }
return contentUri; mContentUriStrings[index] = contentUri;
}
cursor.moveToPosition(-1);
}
@Override
public String getString(int column) {
if (column == mContentUriIndex) {
return mContentUriStrings[getPosition()];
} else { } else {
return super.getString(column); return super.getString(column);
} }