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

Commit 142c471d authored by Makoto Onuki's avatar Makoto Onuki Committed by Android (Google) Code Review
Browse files

Merge "Only show "add connection" button if relevant" into ics-mr0

parents bb0adc9e 08bcf715
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -850,17 +850,15 @@ public class ContactLoader extends Loader<ContactLoader.Result> {

        /**
         * Sets the "invitable" account types to {@link Result#mInvitableAccountTypes}.
         *
         * TODO Exclude the ones with no raw contacts in the database.
         */
        private void loadInvitableAccountTypes(Result contactData) {
            Map<AccountTypeWithDataSet, AccountType> allInvitables =
                    AccountTypeManager.getInstance(getContext()).getInvitableAccountTypes();
            if (allInvitables.isEmpty()) {
            Map<AccountTypeWithDataSet, AccountType> invitables =
                    AccountTypeManager.getInstance(getContext()).getUsableInvitableAccountTypes();
            if (invitables.isEmpty()) {
                return;
            }

            HashMap<AccountTypeWithDataSet, AccountType> result = Maps.newHashMap(allInvitables);
            HashMap<AccountTypeWithDataSet, AccountType> result = Maps.newHashMap(invitables);

            // Remove the ones that already have a raw contact in the current contact
            for (Entity entity : contactData.getEntities()) {
+24 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import com.android.i18n.phonenumbers.PhoneNumberUtil;
import android.content.Context;
import android.content.Intent;
import android.location.CountryDetector;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Im;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.telephony.PhoneNumberUtils;
@@ -184,4 +186,26 @@ public class ContactsUtils {
                AccountTypeManager.getInstance(context).getGroupWritableAccounts();
        return !accounts.isEmpty();
    }

    /**
     * Returns the intent to launch for the given invitable account type and contact lookup URI.
     * This will return null if the account type is not invitable (i.e. there is no
     * {@link AccountType#getInviteContactActivityClassName()} or
     * {@link AccountType#resPackageName}).
     */
    public static Intent getInvitableIntent(AccountType accountType, Uri lookupUri) {
        String resPackageName = accountType.resPackageName;
        String className = accountType.getInviteContactActivityClassName();
        if (TextUtils.isEmpty(resPackageName) || TextUtils.isEmpty(className)) {
            return null;
        }
        Intent intent = new Intent();
        intent.setClassName(resPackageName, className);

        intent.setAction(ContactsContract.Intents.INVITE_CONTACT);

        // Data is the lookup URI.
        intent.setData(lookupUri);
        return intent;
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -244,6 +244,9 @@ public class ContactDetailActivity extends ContactsActivity {
            new ContactDetailFragment.Listener() {
        @Override
        public void onItemClicked(Intent intent) {
            if (intent == null) {
                return;
            }
            try {
                startActivity(intent);
            } catch (ActivityNotFoundException e) {
+3 −0
Original line number Diff line number Diff line
@@ -1098,6 +1098,9 @@ public class PeopleActivity extends ContactsActivity
    public class ContactDetailFragmentListener implements ContactDetailFragment.Listener {
        @Override
        public void onItemClicked(Intent intent) {
            if (intent == null) {
                return;
            }
            try {
                startActivity(intent);
            } catch (ActivityNotFoundException e) {
+5 −16
Original line number Diff line number Diff line
@@ -878,8 +878,10 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position,
                    long id) {
                if (mListener != null) {
                    mListener.onItemClicked(popupAdapter.getIntent(mContext, position));
                if (mListener != null && mContactData != null) {
                    mListener.onItemClicked(ContactsUtils.getInvitableIntent(
                            popupAdapter.getItem(position) /* account type */,
                            mContactData.getLookupUri()));
                }
            }
        };
@@ -2102,7 +2104,7 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen

    public static interface Listener {
        /**
         * User clicked a single item (e.g. mail)
         * User clicked a single item (e.g. mail). The intent passed in could be null.
         */
        public void onItemClicked(Intent intent);

@@ -2167,19 +2169,6 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen
            return resultView;
        }

        public Intent getIntent(Context context, int position) {
            final AccountType accountType = mAccountTypes.get(position);
            Intent intent = new Intent();
            intent.setClassName(accountType.resPackageName,
                    accountType.getInviteContactActivityClassName());

            intent.setAction(ContactsContract.Intents.INVITE_CONTACT);

            // Data is the lookup URI.
            intent.setData(mContactData.getLookupUri());
            return intent;
        }

        @Override
        public int getCount() {
            return mAccountTypes.size();
Loading