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

Commit 84cac440 authored by Dave Santoro's avatar Dave Santoro
Browse files

App changes for handling profile DB split.

- Added a custom loader to load in the profile and contact list.
- Made the CursorLoader for ContactEntryListFragment and its
  subclasses pluggable, so the default one could substitute in
  the combined profile-and-contact list loader.
- The photo manager needs some awareness of the profile ID-space,
  since it's doing bulk photo queries using a custom selection.
- Adapted Isaac's change to the section indexer to handle the
  profile being out of consideration when doing the address book
  index query.
- Removed uses of the ALLOW_PROFILE param, since it no longer exists.

Bug 5204577
Bug 5136432
Bug 5140891

Change-Id: I676b4cdeabe87b1b585c6c8df2cde51605777106
parent ac76896f
Loading
Loading
Loading
Loading
+25 −5
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import com.google.android.collect.Lists;
import com.google.android.collect.Sets;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
@@ -642,7 +643,6 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
                        ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(Directory.DEFAULT))
                        .appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY,
                                String.valueOf(MAX_PHOTOS_TO_PRELOAD))
                        .appendQueryParameter(ContactsContract.ALLOW_PROFILE, "1")
                        .build();
                cursor = mResolver.query(uri, new String[] { Contacts.PHOTO_ID },
                        Contacts.PHOTO_ID + " NOT NULL AND " + Contacts.PHOTO_ID + "!=0",
@@ -698,8 +698,7 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {

            Cursor cursor = null;
            try {
                cursor = mResolver.query(Data.CONTENT_URI.buildUpon()
                        .appendQueryParameter(ContactsContract.ALLOW_PROFILE, "1").build(),
                cursor = mResolver.query(Data.CONTENT_URI,
                        COLUMNS,
                        mStringBuilder.toString(),
                        mPhotoIdsAsStrings.toArray(EMPTY_STRING_ARRAY),
@@ -719,10 +718,31 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
                }
            }

            // Remaining photos were not found in the database - mark the cache accordingly.
            // Remaining photos were not found in the contacts database (but might be in profile).
            for (Long id : mPhotoIds) {
                if (ContactsContract.isProfileId(id)) {
                    Cursor profileCursor = null;
                    try {
                        profileCursor = mResolver.query(
                                ContentUris.withAppendedId(Data.CONTENT_URI, id),
                                COLUMNS, null, null, null);
                        if (profileCursor != null && profileCursor.moveToFirst()) {
                            cacheBitmap(profileCursor.getLong(0), profileCursor.getBlob(1),
                                    preloading);
                        } else {
                            // Couldn't load a photo this way either.
                            cacheBitmap(id, null, preloading);
                        }
                    } finally {
                        if (profileCursor != null) {
                            profileCursor.close();
                        }
                    }
                } else {
                    // Not a profile photo and not found - mark the cache accordingly
                    cacheBitmap(id, null, preloading);
                }
            }

            mMainThreadHandler.sendEmptyMessage(MESSAGE_PHOTOS_LOADED);
        }
+5 −1
Original line number Diff line number Diff line
@@ -351,7 +351,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
            mAdapter.configureDirectoryLoader(loader);
            return loader;
        } else {
            CursorLoader loader = new CursorLoader(mContext, null, null, null, null, null);
            CursorLoader loader = createCursorLoader();
            long directoryId = args != null && args.containsKey(DIRECTORY_ID_ARG_KEY)
                    ? args.getLong(DIRECTORY_ID_ARG_KEY)
                    : Directory.DEFAULT;
@@ -360,6 +360,10 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
        }
    }

    public CursorLoader createCursorLoader() {
        return new CursorLoader(mContext, null, null, null, null, null);
    }

    private void startLoadingDirectoryPartition(int partitionIndex) {
        DirectoryPartition partition = (DirectoryPartition)mAdapter.getPartition(partitionIndex);
        partition.setStatus(DirectoryPartition.STATUS_LOADING);
+0 −5
Original line number Diff line number Diff line
@@ -144,11 +144,6 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter {
                .appendQueryParameter(ContactCounts.ADDRESS_BOOK_INDEX_EXTRAS, "true").build();
    }

    protected static Uri includeProfileEntry(Uri uri) {
        return uri.buildUpon()
                .appendQueryParameter(ContactsContract.ALLOW_PROFILE, "true").build();
    }

    public boolean getHasPhoneNumber(int position) {
        return ((Cursor)getItem(position)).getInt(CONTACT_HAS_PHONE_COLUMN_INDEX) != 0;
    }
+22 −5
Original line number Diff line number Diff line
@@ -26,9 +26,9 @@ import java.util.Arrays;
 */
public class ContactsSectionIndexer implements SectionIndexer {

    private final String[] mSections;
    private final int[] mPositions;
    private final int mCount;
    private String[] mSections;
    private int[] mPositions;
    private int mCount;

    /**
     * Constructor.
@@ -95,8 +95,25 @@ public class ContactsSectionIndexer implements SectionIndexer {
    }

    public void setProfileHeader(String header) {
        if (mSections != null && mSections.length > 0) {
            mSections[0] = header;
        if (mSections != null) {
            // Don't do anything if the header is already set properly.
            if (mSections.length > 0 && header.equals(mSections[0])) {
                return;
            }

            // Since the section indexer isn't aware of the profile at the top, we need to add a
            // special section at the top for it and shift everything else down.
            String[] tempSections = new String[mSections.length + 1];
            int[] tempPositions = new int[mPositions.length + 1];
            tempSections[0] = header;
            tempPositions[0] = 0;
            for (int i = 1; i <= mPositions.length; i++) {
                tempSections[i] = mSections[i - 1];
                tempPositions[i] = mPositions[i - 1] + 1;
            }
            mSections = tempSections;
            mPositions = tempPositions;
            mCount++;
        }
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.contacts.list;
import com.android.contacts.R;
import com.android.contacts.editor.ContactEditorFragment;

import android.content.CursorLoader;
import android.content.Intent;
import android.database.Cursor;
import android.provider.ContactsContract.Contacts;
@@ -55,6 +56,11 @@ public class DefaultContactBrowseListFragment extends ContactBrowseListFragment
        setVisibleScrollbarEnabled(true);
    }

    @Override
    public CursorLoader createCursorLoader() {
        return new ProfileAndContactsLoader(getActivity());
    }

    @Override
    protected void onItemClick(int position, long id) {
        viewContact(getAdapter().getContactUri(position));
Loading