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

Commit f333e204 authored by Gary Mai's avatar Gary Mai Committed by Android (Google) Code Review
Browse files

Merge "Promote aggregation suggestions to all contacts"

parents 84ca9b68 e4874665
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -100,6 +100,11 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
        this(context, lookupUri, false, false, postViewNotification, false);
    }

    public ContactLoader(Context context, Uri lookupUri, boolean postViewNotification,
            boolean loadGroupMetaData) {
        this(context, lookupUri, loadGroupMetaData, false, postViewNotification, false);
    }

    public ContactLoader(Context context, Uri lookupUri, boolean loadGroupMetaData,
            boolean loadInvitableAccountTypes,
            boolean postViewNotification, boolean computeFormattedPhoneNumber) {
+1 −1
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ public class AggregationSuggestionEngine extends HandlerThread {
    private ContentObserver mContentObserver;
    private Uri mSuggestionsUri;
    private int mSuggestionsLimit = 3;
    private boolean mPruneInvisibleContacts = true;
    private boolean mPruneInvisibleContacts = false;

    public AggregationSuggestionEngine(Context context) {
        super("AggregationSuggestions", Process.THREAD_PRIORITY_BACKGROUND);
+8 −3
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ import com.android.contacts.common.util.ImplicitIntentsUtil;
import com.android.contacts.common.util.MaterialColorMapUtils;
import com.android.contacts.editor.AggregationSuggestionEngine.Suggestion;
import com.android.contacts.list.UiIntentActions;
import com.android.contacts.quickcontact.InvisibleContactUtil;
import com.android.contacts.quickcontact.QuickContactActivity;
import com.android.contacts.util.ContactPhotoUtils;
import com.android.contacts.util.HelpUtils;
@@ -127,7 +128,6 @@ public class CompactContactEditorFragment extends Fragment implements
    private static final String KEY_DISABLE_DELETE_MENU_OPTION = "disableDeleteMenuOption";
    private static final String KEY_NEW_LOCAL_PROFILE = "newLocalProfile";
    private static final String KEY_MATERIAL_PALETTE = "materialPalette";
    private static final String KEY_PHOTO_ID = "photoId";

    private static final String KEY_VIEW_ID_GENERATOR = "viewidgenerator";

@@ -408,7 +408,9 @@ public class CompactContactEditorFragment extends Fragment implements
                @Override
                public Loader<Contact> onCreateLoader(int id, Bundle args) {
                    mLoaderStartTime = SystemClock.elapsedRealtime();
                    return new ContactLoader(mContext, mLookupUri, true);
                    return new ContactLoader(mContext, mLookupUri,
                            /* postViewNotification */ true,
                            /* loadGroupMetaData */ true);
                }

                @Override
@@ -1141,7 +1143,6 @@ public class CompactContactEditorFragment extends Fragment implements
            Log.v(TAG, "Ignoring background change. This will have to be rebased later");
            return;
        }

        mRawContacts = contact.getRawContacts();

        String readOnlyDisplayName = null;
@@ -1161,6 +1162,10 @@ public class CompactContactEditorFragment extends Fragment implements
        // This also adds deltas to list.  If readOnlyDisplayName is null at this point it is
        // simply ignored later on by the editor.
        setStateForExistingContact(readOnlyDisplayName, contact.isUserProfile(), mRawContacts);
        if (mAutoAddToDefaultGroup
                && InvisibleContactUtil.isInvisibleAndAddable(contact, getContext())) {
            InvisibleContactUtil.markAddToDefaultGroup(contact, mState, getContext());
        }
    }

    /**
+23 −17
Original line number Diff line number Diff line
package com.android.contacts.quickcontact;


import com.google.common.collect.Iterables;
import android.content.Context;
import android.content.Intent;
import android.provider.ContactsContract.CommonDataKinds.GroupMembership;

import com.android.contacts.ContactSaveService;
import com.android.contacts.common.model.AccountTypeManager;
@@ -17,9 +19,7 @@ import com.android.contacts.common.model.dataitem.DataKind;
import com.android.contacts.common.model.dataitem.GroupMembershipDataItem;
import com.android.contacts.group.GroupMetaData;

import android.content.Context;
import android.content.Intent;
import android.provider.ContactsContract.CommonDataKinds.GroupMembership;
import com.google.common.collect.Iterables;

import java.util.List;

@@ -70,14 +70,28 @@ public class InvisibleContactUtil {
    }

    public static void addToDefaultGroup(Contact contactData, Context context) {
        final RawContactDeltaList contactDeltaList = contactData.createRawContactDeltaList();
        if (markAddToDefaultGroup(contactData, contactDeltaList, context)) {
            // Fire off the intent. we don't need a callback, as the database listener
            // should update the ui
            final Intent intent = ContactSaveService.createSaveContactIntent(
                    context,
                    contactDeltaList, "", 0, false, QuickContactActivity.class,
                    Intent.ACTION_VIEW, null, /* joinContactIdExtraKey =*/ null,
                /* joinContactId =*/ null);
            ContactSaveService.startService(context, intent);
        }
    }

    public static boolean markAddToDefaultGroup(Contact contactData,
            RawContactDeltaList rawContactDeltaList, Context context) {
        final long defaultGroupId = getDefaultGroupId(contactData.getGroupMetaData());
        // there should always be a default group (otherwise the button would be invisible),
        // but let's be safe here
        if (defaultGroupId == -1) return;
        if (defaultGroupId == -1) return false;

        // add the group membership to the current state
        final RawContactDeltaList contactDeltaList = contactData.createRawContactDeltaList();
        final RawContactDelta rawContactEntityDelta = contactDeltaList.get(0);
        final RawContactDelta rawContactEntityDelta = rawContactDeltaList.get(0);

        final AccountTypeManager accountTypes = AccountTypeManager.getInstance(
                context);
@@ -86,17 +100,9 @@ public class InvisibleContactUtil {
                GroupMembership.CONTENT_ITEM_TYPE);
        final ValuesDelta entry = RawContactModifier.insertChild(rawContactEntityDelta,
                groupMembershipKind);
        if (entry == null) return;
        if (entry == null) return false;
        entry.setGroupRowId(defaultGroupId);

        // and fire off the intent. we don't need a callback, as the database listener
        // should update the ui
        final Intent intent = ContactSaveService.createSaveContactIntent(
                context,
                contactDeltaList, "", 0, false, QuickContactActivity.class,
                Intent.ACTION_VIEW, null, /* joinContactIdExtraKey =*/ null,
                /* joinContactId =*/ null);
        ContactSaveService.startService(context, intent);
        return true;
    }

    /** return default group id or -1 if no group or several groups are marked as default */