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

Commit 3a5f94ff authored by Walter Jang's avatar Walter Jang
Browse files

Revert "Load the raw contact's photo in picker dialog"

This reverts commit 21bdf08a.

Bug: 32096517
Bug: 32384257

Change-Id: I5f5f2790a394c9bf27da60b0630474eb92701e12
parent 1294cadc
Loading
Loading
Loading
Loading
+7 −16
Original line number Diff line number Diff line
@@ -830,7 +830,7 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
        } else {
            if (DEBUG) Log.d(TAG, "loadPhoto request: " + photoId);
            loadPhotoByIdOrUri(view, Request.createFromThumbnailId(photoId, darkTheme, isCircular,
                    defaultProvider, defaultImageRequest));
                    defaultProvider));
        }
    }

@@ -1178,8 +1178,6 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {

    /**
     * Stores the supplied bitmap in cache.
     * bytes should be null to indicate a failure to load the photo. An empty byte[] signifies
     * a successful load but no photo was available.
     */
    private void cacheBitmap(Object key, byte[] bytes, boolean preloading, int requestedExtent) {
        if (DEBUG) {
@@ -1205,11 +1203,10 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
        }

        if (bytes != null) {
            mBitmapHolderCache.put(key, holder);
            if (mBitmapHolderCache.get(key) != holder) {
                Log.w(TAG, "Bitmap too big to fit in cache.");
                mBitmapHolderCache.put(key, BITMAP_UNAVAILABLE);
            } else {
                mBitmapHolderCache.put(key, holder);
            }
        } else {
            mBitmapHolderCache.put(key, BITMAP_UNAVAILABLE);
@@ -1510,9 +1507,6 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
                    while (cursor.moveToNext()) {
                        Long id = cursor.getLong(0);
                        byte[] bytes = cursor.getBlob(1);
                        if (bytes == null) {
                            bytes = new byte[0];
                        }
                        cacheBitmap(id, bytes, preloading, -1);
                        mPhotoIds.remove(id);
                    }
@@ -1532,11 +1526,8 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
                                ContentUris.withAppendedId(Data.CONTENT_URI, id),
                                COLUMNS, null, null, null);
                        if (profileCursor != null && profileCursor.moveToFirst()) {
                            byte[] bytes = profileCursor.getBlob(1);
                            if (bytes == null) {
                                bytes = new byte[0];
                            }
                            cacheBitmap(profileCursor.getLong(0), bytes, preloading, -1);
                            cacheBitmap(profileCursor.getLong(0), profileCursor.getBlob(1),
                                    preloading, -1);
                        } else {
                            // Couldn't load a photo this way either.
                            cacheBitmap(id, null, preloading, -1);
@@ -1650,9 +1641,9 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
        }

        public static Request createFromThumbnailId(long id, boolean darkTheme, boolean isCircular,
                DefaultImageProvider defaultProvider, DefaultImageRequest defaultRequest) {
                DefaultImageProvider defaultProvider) {
            return new Request(id, null /* no URI */, -1, darkTheme, isCircular, defaultProvider,
                    defaultRequest);
                    /* defaultRequest */ null);
        }

        public static Request createFromUri(Uri uri, int requestedExtent, boolean darkTheme,
+10 −3
Original line number Diff line number Diff line
@@ -3,9 +3,12 @@ package com.android.contacts.editor;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract.RawContacts;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
@@ -127,12 +130,16 @@ public class PickRawContactDialogFragment extends DialogFragment {
            final ContactPhotoManager.DefaultImageRequest
                    request = new ContactPhotoManager.DefaultImageRequest(
                    displayName, String.valueOf(rawContact.id), /* isCircular = */ true);
            final Uri photoUri = Uri.withAppendedPath(
                    ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContact.id),
                    RawContacts.DisplayPhoto.CONTENT_DIRECTORY);

            ContactPhotoManager.getInstance(mContext).loadThumbnail(holder.photo,
                    rawContact.photoId,
            ContactPhotoManager.getInstance(mContext).loadDirectoryPhoto(holder.photo,
                    photoUri,
                    /* darkTheme = */ false,
                    /* isCircular = */ true,
                    request);

            return view;
        }

+1 −44
Original line number Diff line number Diff line
@@ -9,16 +9,12 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.Profile;
import android.provider.ContactsContract.RawContacts;

import com.android.contacts.common.model.AccountTypeManager;
import com.android.contacts.common.model.account.AccountType;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Loader for the pick a raw contact to edit activity. Loads all raw contact metadata for the
@@ -47,11 +43,6 @@ public class PickRawContactLoader extends
    private static final int DISPLAY_NAME_PRIMARY = 4;
    private static final int DISPLAY_NAME_ALTERNATIVE = 5;

    private static final String PHOTO_SELECTION_PREFIX =
            ContactsContract.Data.RAW_CONTACT_ID + " IN (";
    private static final String PHOTO_SELECTION_SUFFIX = ") AND " + ContactsContract.Data.MIMETYPE
            + "=" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE;

    public PickRawContactLoader(Context context, Uri contactUri) {
        super(context);
        mContactUri = ensureIsContactUri(contactUri);
@@ -101,51 +92,20 @@ public class PickRawContactLoader extends
        }

        rawContactCursor.moveToPosition(-1);
        final StringBuilder photoSelection = new StringBuilder(PHOTO_SELECTION_PREFIX);
        final Map<Long, RawContact> rawContactMap = new HashMap<>();
        try {
            while (rawContactCursor.moveToNext()) {
                RawContact rawContact = new RawContact();
                rawContact.id = rawContactCursor.getLong(RAW_CONTACT_ID);
                photoSelection.append(rawContact.id).append(',');
                rawContact.displayName = rawContactCursor.getString(DISPLAY_NAME_PRIMARY);
                rawContact.displayNameAlt = rawContactCursor.getString(DISPLAY_NAME_ALTERNATIVE);
                rawContact.accountName = rawContactCursor.getString(ACCOUNT_NAME);
                rawContact.accountType = rawContactCursor.getString(ACCOUNT_TYPE);
                rawContact.accountDataSet = rawContactCursor.getString(DATA_SET);
                result.rawContacts.add(rawContact);
                rawContactMap.put(rawContact.id, rawContact);
            }
        } finally {
            rawContactCursor.close();
        }

        // Remove the last ','
        if (photoSelection.length() > 0) {
            photoSelection.deleteCharAt(photoSelection.length() - 1);
        }
        photoSelection.append(PHOTO_SELECTION_SUFFIX);

        final Uri dataUri = result.isUserProfile
                ? Uri.withAppendedPath(Profile.CONTENT_URI, Data.CONTENT_URI.getPath())
                : Data.CONTENT_URI;
        final Cursor photoCursor = resolver.query(
                dataUri,
                new String[] {Data.RAW_CONTACT_ID, Contacts.Photo._ID},
                photoSelection.toString(), null, null);

        if (photoCursor != null) {
            try {
                photoCursor.moveToPosition(-1);
                while (photoCursor.moveToNext()) {
                    final long rawContactId = photoCursor.getLong(/* Data.RAW_CONTACT_ID */ 0);
                    rawContactMap.get(rawContactId).photoId =
                            photoCursor.getLong(/* PHOTO._ID */ 1);
                }
            } finally {
                photoCursor.close();
            }
        }
        return result;
    }

@@ -265,7 +225,6 @@ public class PickRawContactLoader extends
                };

        public long id;
        public long photoId;
        public String displayName;
        public String displayNameAlt;
        public String accountName;
@@ -276,7 +235,6 @@ public class PickRawContactLoader extends

        private RawContact(Parcel in) {
            id = in.readLong();
            photoId = in.readLong();
            displayName = in.readString();
            displayNameAlt = in.readString();
            accountName = in.readString();
@@ -292,7 +250,6 @@ public class PickRawContactLoader extends
        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeLong(id);
            dest.writeLong(photoId);
            dest.writeString(displayName);
            dest.writeString(displayNameAlt);
            dest.writeString(accountName);