use of com.fsck.k9.cache.EmailProviderCacheCursor in project k-9 by k9mail.
the class EmailProvider method query.
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
int match = URI_MATCHER.match(uri);
if (match < 0) {
throw new IllegalArgumentException("Unknown URI: " + uri);
}
ContentResolver contentResolver = getContext().getContentResolver();
Cursor cursor = null;
switch(match) {
case MESSAGES:
case MESSAGES_THREADED:
case MESSAGES_THREAD:
{
List<String> segments = uri.getPathSegments();
String accountUuid = segments.get(1);
List<String> dbColumnNames = new ArrayList<String>(projection.length);
Map<String, String> specialColumns = new HashMap<String, String>();
for (String columnName : projection) {
if (SpecialColumns.ACCOUNT_UUID.equals(columnName)) {
specialColumns.put(SpecialColumns.ACCOUNT_UUID, accountUuid);
} else {
dbColumnNames.add(columnName);
}
}
String[] dbProjection = dbColumnNames.toArray(new String[0]);
if (match == MESSAGES) {
cursor = getMessages(accountUuid, dbProjection, selection, selectionArgs, sortOrder);
} else if (match == MESSAGES_THREADED) {
cursor = getThreadedMessages(accountUuid, dbProjection, selection, selectionArgs, sortOrder);
} else if (match == MESSAGES_THREAD) {
String threadId = segments.get(3);
cursor = getThread(accountUuid, dbProjection, threadId, sortOrder);
} else {
throw new RuntimeException("Not implemented");
}
Uri notificationUri = Uri.withAppendedPath(CONTENT_URI, "account/" + accountUuid + "/messages");
cursor.setNotificationUri(contentResolver, notificationUri);
cursor = new SpecialColumnsCursor(new IdTrickeryCursor(cursor), projection, specialColumns);
cursor = new EmailProviderCacheCursor(accountUuid, cursor, getContext());
break;
}
case STATS:
{
List<String> segments = uri.getPathSegments();
String accountUuid = segments.get(1);
cursor = getAccountStats(accountUuid, projection, selection, selectionArgs);
Uri notificationUri = Uri.withAppendedPath(CONTENT_URI, "account/" + accountUuid + "/messages");
cursor.setNotificationUri(contentResolver, notificationUri);
break;
}
}
return cursor;
}
Aggregations