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

Commit ba10be29 authored by Gary Mai's avatar Gary Mai
Browse files

Fix regression with editing me profile

Use Profile.CONTENT_RAW_CONTACTS_URI in PickRawContactLoader
if we're loading the me profile.
Changed rendering accounts attribution to be consistent with
the duplicates view.
  * Me profile -> "My local profile"
  * Focus Google account -> account name
  * All others -> account type display string (Google+, LinkedIn etc.)

Test:
Edit me-profile with G+ account attached
Edit me-profile without G+ account
Edit linked contact with device raw contacts
Edit linked contact with SIM raw contacts
Edit linked contact with Samsung raw contact

Bug:32113893

Change-Id: I904e64eee262d0ddf95240915911228439c2c46f
parent 89a8f840
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ public class ContactEditorSpringBoardActivity extends AppCompatContactsActivity
    private Uri mUri;
    private Cursor mCursor;
    private MaterialPalette mMaterialPalette;
    private boolean mIsUserProfile;

    /**
     * The contact data loader listener.
@@ -59,6 +60,7 @@ public class ContactEditorSpringBoardActivity extends AppCompatContactsActivity
                        return;
                    }
                    mCursor = cursor;
                    mIsUserProfile = ((PickRawContactLoader) loader).isUserProfile();
                    if (mCursor.getCount() == 1) {
                        loadEditor();
                    } else {
@@ -128,8 +130,8 @@ public class ContactEditorSpringBoardActivity extends AppCompatContactsActivity
        if (oldFragment != null) {
            ft.remove(oldFragment);
        }
        final PickRawContactDialogFragment newFragment =
                PickRawContactDialogFragment.getInstance(mUri, mCursor, mMaterialPalette);
        final PickRawContactDialogFragment newFragment = PickRawContactDialogFragment.getInstance(
                mUri, mCursor, mMaterialPalette, mIsUserProfile);
        ft.add(newFragment, TAG_RAW_CONTACTS_DIALOG);
        // commitAllowingStateLoss is safe in this activity because the fragment entirely depends
        // on the result of the loader. Even if we lose the fragment because the activity was
+52 −16
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ import android.database.Cursor;
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;
import android.view.ViewGroup;
@@ -21,7 +22,11 @@ import android.widget.TextView;
import com.android.contacts.R;
import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.model.AccountTypeManager;
import com.android.contacts.common.model.account.AccountDisplayInfo;
import com.android.contacts.common.model.account.AccountDisplayInfoFactory;
import com.android.contacts.common.model.account.AccountType;
import com.android.contacts.common.model.account.AccountWithDataSet;
import com.android.contacts.common.model.account.GoogleAccountType;
import com.android.contacts.common.preference.ContactsPreferences;
import com.android.contacts.common.util.ImplicitIntentsUtil;
import com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette;
@@ -34,14 +39,20 @@ public class PickRawContactDialogFragment extends DialogFragment {
    /**
     * Used to list the account info for the given raw contacts list.
     */
    private static final class RawContactAccountListAdapter extends CursorAdapter {
    private final class RawContactAccountListAdapter extends CursorAdapter {
        private final LayoutInflater mInflater;
        private final Context mContext;
        private final AccountDisplayInfoFactory mAccountDisplayInfoFactory;
        private final AccountTypeManager mAccountTypeManager;
        private final ContactsPreferences mPreferences;

        public RawContactAccountListAdapter(Context context, Cursor cursor) {
            super(context, cursor, 0);
            mContext = context;
            mInflater = LayoutInflater.from(context);
            mAccountDisplayInfoFactory = AccountDisplayInfoFactory.forWritableAccounts(context);
            mAccountTypeManager = AccountTypeManager.getInstance(context);
            mPreferences = new ContactsPreferences(context);
        }

        @Override
@@ -50,22 +61,18 @@ public class PickRawContactDialogFragment extends DialogFragment {
            final String accountName = cursor.getString(PickRawContactLoader.ACCOUNT_NAME);
            final String accountType = cursor.getString(PickRawContactLoader.ACCOUNT_TYPE);
            final String dataSet = cursor.getString(PickRawContactLoader.DATA_SET);
            final AccountType account = AccountTypeManager.getInstance(mContext)
                    .getAccountType(accountType, dataSet);
            final AccountType account = mAccountTypeManager.getAccountType(accountType, dataSet);

            final ContactsPreferences prefs = new ContactsPreferences(mContext);
            final int displayNameColumn =
                    prefs.getDisplayOrder() == ContactsPreferences.DISPLAY_ORDER_PRIMARY
                    mPreferences.getDisplayOrder() == ContactsPreferences.DISPLAY_ORDER_PRIMARY
                            ? PickRawContactLoader.DISPLAY_NAME_PRIMARY
                            : PickRawContactLoader.DISPLAY_NAME_ALTERNATIVE;

            String displayName = cursor.getString(displayNameColumn);

            final TextView nameView = (TextView) view.findViewById(
                    R.id.display_name);
            final TextView accountTextView = (TextView) view.findViewById(
                    R.id.account_name);
            final ImageView accountIconView = (ImageView) view.findViewById(
                    R.id.account_icon);
            if (TextUtils.isEmpty(displayName)) {
                displayName = mContext.getString(R.string.missing_name);
            }

            if (!account.areContactsWritable()) {
                displayName = mContext
@@ -74,19 +81,42 @@ public class PickRawContactDialogFragment extends DialogFragment {
            } else {
                view.setAlpha(1f);
            }

            final TextView nameView = (TextView) view.findViewById(
                    R.id.display_name);
            nameView.setText(displayName);
            accountTextView.setText(accountName);

            final String accountDisplayLabel;

            // Use the same string as editor if it's an editable user profile raw contact.
            if (mIsUserProfile && account.areContactsWritable()) {
                final AccountDisplayInfo displayInfo =
                        mAccountDisplayInfoFactory.getAccountDisplayInfo(
                                new AccountWithDataSet(accountName, accountType, dataSet));
                accountDisplayLabel = EditorUiUtils.getAccountHeaderLabelForMyProfile(mContext,
                        displayInfo);
            }
            else if (GoogleAccountType.ACCOUNT_TYPE.equals(accountType)
                    && account.dataSet == null) {
                // Focus Google accounts have the account name shown
                accountDisplayLabel = accountName;
            } else {
                accountDisplayLabel = account.getDisplayLabel(mContext).toString();
            }
            final TextView accountTextView = (TextView) view.findViewById(
                    R.id.account_name);
            final ImageView accountIconView = (ImageView) view.findViewById(
                    R.id.account_icon);
            accountTextView.setText(accountDisplayLabel);
            accountIconView.setImageDrawable(account.getDisplayIcon(mContext));

            final ContactPhotoManager.DefaultImageRequest
                    request = new ContactPhotoManager.DefaultImageRequest(
                    displayName, String.valueOf(rawContactId), /* isCircular = */ true);
            final ImageView photoView = (ImageView) view.findViewById(
                    R.id.photo);
            final Uri photoUri = Uri.withAppendedPath(
                    ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId),
                    RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
            final ImageView photoView = (ImageView) view.findViewById(
                    R.id.photo);
            ContactPhotoManager.getInstance(mContext).loadDirectoryPhoto(photoView,
                    photoUri,
                    /* darkTheme = */ false,
@@ -112,13 +142,15 @@ public class PickRawContactDialogFragment extends DialogFragment {
    private Uri mUri;
    private CursorAdapter mAdapter;
    private MaterialPalette mMaterialPalette;
    private boolean mIsUserProfile;

    public static PickRawContactDialogFragment getInstance(Uri uri, Cursor cursor,
            MaterialPalette materialPalette) {
            MaterialPalette materialPalette, boolean isUserProfile) {
        final PickRawContactDialogFragment fragment = new PickRawContactDialogFragment();
        fragment.setUri(uri);
        fragment.setCursor(cursor);
        fragment.setMaterialPalette(materialPalette);
        fragment.setIsUserProfile(isUserProfile);
        return fragment;
    }

@@ -163,6 +195,10 @@ public class PickRawContactDialogFragment extends DialogFragment {
        mMaterialPalette = materialPalette;
    }

    private void setIsUserProfile(boolean isUserProfile) {
        mIsUserProfile = isUserProfile;
    }

    private void finishActivity() {
        if (getActivity() != null && !getActivity().isFinishing()) {
            getActivity().finish();
+15 −3
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import android.content.Context;
import android.content.CursorLoader;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.RawContacts;

@@ -13,6 +14,7 @@ import android.provider.ContactsContract.RawContacts;
 */
public class PickRawContactLoader extends CursorLoader {
    private Uri mContactUri;
    private boolean mIsUserProfile;

    public static final String[] COLUMNS = new String[] {
            RawContacts.ACCOUNT_NAME,
@@ -41,7 +43,7 @@ public class PickRawContactLoader extends CursorLoader {
    public Cursor loadInBackground() {
        // Get the id of the contact we're looking at.
        final Cursor cursor = getContext().getContentResolver()
                .query(mContactUri, new String[] { Contacts._ID }, null,
                .query(mContactUri, new String[] { Contacts._ID, Contacts.IS_USER_PROFILE }, null,
                null, null);

        if (cursor == null) {
@@ -54,14 +56,24 @@ public class PickRawContactLoader extends CursorLoader {
        }

        cursor.moveToFirst();
        final long contactId = cursor.getLong(0);
        final long contactId = cursor.getLong(/* Contacts._ID */ 0);
        mIsUserProfile = cursor.getInt(/* Contacts.IS_USER_PROFILE */ 1) == 1;

        cursor.close();
        // Update selection arguments and uri.
        setSelectionArgs(new String[]{ Long.toString(contactId) });
        if (mIsUserProfile) {
            setUri(ContactsContract.Profile.CONTENT_RAW_CONTACTS_URI);
        } else {
            setUri(RawContacts.CONTENT_URI);
        }
        return super.loadInBackground();
    }

    public boolean isUserProfile() {
        return mIsUserProfile;
    }

    /**
     * Ensures that this is a valid contact URI. If invalid, then an exception is
     * thrown. Otherwise, the original URI is returned.