Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6e11b111 authored by Chiao Cheng's avatar Chiao Cheng Committed by Android (Google) Code Review
Browse files

Merge "Add support for multiple items in a single mime type." into klp-dev

parents 637a38ec 1668d2ab
Loading
Loading
Loading
Loading
+30 −15
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

@@ -405,8 +406,28 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
        final Iterator keys = items.keys();
        while (keys.hasNext()) {
            final String mimetype = (String) keys.next();
            final JSONObject item = items.getJSONObject(mimetype);

            // Could be single object or array.
            final JSONObject obj = items.optJSONObject(mimetype);
            if (obj == null) {
                final JSONArray array = items.getJSONArray(mimetype);
                for (int i = 0; i < array.length(); i++) {
                    final JSONObject item = array.getJSONObject(i);
                    processOneRecord(rawContact, item, mimetype);
                }
            } else {
                processOneRecord(rawContact, obj, mimetype);
            }
        }

        contact.setRawContacts(new ImmutableList.Builder<RawContact>()
                .add(rawContact)
                .build());
        return contact;
    }

    private void processOneRecord(RawContact rawContact, JSONObject item, String mimetype)
            throws JSONException {
        final ContentValues itemValues = new ContentValues();
        itemValues.put(Data.MIMETYPE, mimetype);
        itemValues.put(Data._ID, -1);
@@ -424,12 +445,6 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
        rawContact.addDataItemValues(itemValues);
    }

        contact.setRawContacts(new ImmutableList.Builder<RawContact>()
                .add(rawContact)
                .build());
        return contact;
    }

    private Contact loadContactEntity(ContentResolver resolver, Uri contactUri) {
        Uri entityUri = Uri.withAppendedPath(contactUri, Contacts.Entity.CONTENT_DIRECTORY);
        Cursor cursor = resolver.query(entityUri, ContactQuery.COLUMNS, null, null,