Search in sources :

Example 1 with EmailProviderCacheCursor

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;
}
Also used : EmailProviderCacheCursor(com.fsck.k9.cache.EmailProviderCacheCursor) Cursor(android.database.Cursor) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) ArrayList(java.util.ArrayList) List(java.util.List) EmailProviderCacheCursor(com.fsck.k9.cache.EmailProviderCacheCursor) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ContentResolver (android.content.ContentResolver)1 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 EmailProviderCacheCursor (com.fsck.k9.cache.EmailProviderCacheCursor)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1