Merge "Remove the confirmation dialog when linking duplicates via the overflow menu and quick contact."
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 4a27518..85b8898 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -207,15 +207,6 @@
     <!-- Warning dialog contents after users selects to delete a contact with ReadOnly and Writable sources. [CHAR LIMIT=NONE]-->
     <string name="readOnlyContactDeleteConfirmation">The contact to be deleted has details from multiple accounts. Details from read-only accounts will be hidden, not deleted.</string>
 
-    <!-- Warning dialog. Shown if user selects a single contact to link. [CHAR LIMIT=NONE]  -->
-    <string name="batch_link_single_contact_warning">You need at least two contacts selected to perform a link.</string>
-
-    <!-- Confirmation dialog. Shown after user selects to link contacts. [CHAR LIMIT=NONE]  -->
-    <string name="batch_link_confirmation">Link selected contacts?</string>
-
-    <!-- Positive button text from confirmation dialog. Shown after user selects to link contacts. [CHAR LIMIT=40]  -->
-    <string name="batch_link_confirmation_positive_button">Link</string>
-
     <!-- Confirmation dialog. Shown after user selects to delete one writable contact [CHAR LIMIT=NONE]  -->
     <string name="single_delete_confirmation">Delete this contact?</string>
 
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index 9fd73e6..b692bde 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -58,6 +58,7 @@
 import android.widget.Toast;
 
 import com.android.contacts.AppCompatContactsActivity;
+import com.android.contacts.ContactSaveService;
 import com.android.contacts.R;
 import com.android.contacts.activities.ActionBarAdapter.TabState;
 import com.android.contacts.common.ContactsUtils;
@@ -89,8 +90,6 @@
 import com.android.contacts.interactions.ContactDeletionInteraction;
 import com.android.contacts.interactions.ContactMultiDeletionInteraction;
 import com.android.contacts.interactions.ContactMultiDeletionInteraction.MultiContactDeleteListener;
-import com.android.contacts.interactions.JoinContactsDialogFragment;
-import com.android.contacts.interactions.JoinContactsDialogFragment.JoinContactsListener;
 import com.android.contacts.list.ContactsIntentResolver;
 import com.android.contacts.list.ContactsRequest;
 import com.android.contacts.list.ContactsUnavailableFragment;
@@ -123,7 +122,6 @@
         GroupsListener,
         ProviderStatusListener,
         MultiContactDeleteListener,
-        JoinContactsListener,
         NavigationView.OnNavigationItemSelectedListener {
 
     private static final String TAG = "PeopleActivity";
@@ -1310,11 +1308,16 @@
     }
 
     private void joinSelectedContacts() {
-        JoinContactsDialogFragment.start(this, mAllFragment.getSelectedContactIds());
-    }
+        final Long[] contactIdsArray = mAllFragment.getSelectedContactIds().toArray(
+                new Long[mAllFragment.getSelectedContactIds().size()]);
+        final long[] contactIdsArray2 = new long[contactIdsArray.length];
+        for (int i = 0; i < contactIdsArray.length; i++) {
+            contactIdsArray2[i] = contactIdsArray[i];
+        }
+        final Intent intent = ContactSaveService.createJoinSeveralContactsIntent(this,
+                contactIdsArray2);
+        this.startService(intent);
 
-    @Override
-    public void onContactsJoined() {
         mActionBarAdapter.setSelectionMode(false);
     }
 
@@ -1446,8 +1449,8 @@
                             Toast.LENGTH_SHORT).show();
                 }
                 break;
-        default:
-            Log.wtf(TAG, "Unexpected onClick event from " + view);
+            default:
+                Log.wtf(TAG, "Unexpected onClick event from " + view);
         }
     }
 
diff --git a/src/com/android/contacts/interactions/JoinContactsDialogFragment.java b/src/com/android/contacts/interactions/JoinContactsDialogFragment.java
deleted file mode 100644
index 37ced3f..0000000
--- a/src/com/android/contacts/interactions/JoinContactsDialogFragment.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.contacts.interactions;
-
-
-import com.android.contacts.ContactSaveService;
-import com.android.contacts.R;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.DialogFragment;
-import android.app.FragmentTransaction;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.os.Bundle;
-
-import java.util.TreeSet;
-
-/**
- * An interaction invoked to join multiple contacts together.
- */
-public class JoinContactsDialogFragment extends DialogFragment {
-
-    public static final String FRAGMENT_TAG = "joinDialog";
-    public static final String KEY_POSITION = "position";
-
-    private static final String KEY_CONTACT_IDS = "contactIds";
-
-    public interface JoinContactsListener {
-        void onContactsJoined();
-    }
-
-    public static void start(Activity activity, TreeSet<Long> contactIds) {
-        final FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
-        final JoinContactsDialogFragment newFragment
-                = JoinContactsDialogFragment.newInstance(contactIds);
-        newFragment.show(ft, FRAGMENT_TAG);
-    }
-
-    public static JoinContactsDialogFragment newInstance(TreeSet<Long> contactIds) {
-        return newInstance(contactIds, -1);
-    }
-
-    /**
-     * Creates a new instance of {@link JoinContactsDialogFragment} with passed in arguments.
-     * 
-     * Position parameter is passed back to target fragment if this instance of the join dialog
-     * was launched from a list fragment that needs to know which item position in the list
-     * the dialog was launched from.
-     */
-    public static JoinContactsDialogFragment newInstance(TreeSet<Long> contactIds, int position) {
-        final JoinContactsDialogFragment fragment = new JoinContactsDialogFragment();
-        Bundle arguments = new Bundle();
-        arguments.putSerializable(KEY_CONTACT_IDS, contactIds);
-        arguments.putInt(KEY_POSITION, position);
-        fragment.setArguments(arguments);
-        return fragment;
-    }
-
-    @Override
-    public Dialog onCreateDialog(Bundle savedInstanceState) {
-        final TreeSet<Long> contactIds =
-                (TreeSet<Long>) getArguments().getSerializable(KEY_CONTACT_IDS);
-        if (contactIds.size() <= 1) {
-            return new AlertDialog.Builder(getActivity())
-                    .setIconAttribute(android.R.attr.alertDialogIcon)
-                    .setMessage(R.string.batch_link_single_contact_warning)
-                    .setPositiveButton(android.R.string.ok, null)
-                    .create();
-        }
-        return new AlertDialog.Builder(getActivity())
-                .setIconAttribute(android.R.attr.alertDialogIcon)
-                .setMessage(R.string.batch_link_confirmation)
-                .setNegativeButton(android.R.string.cancel, null)
-                .setPositiveButton(R.string.batch_link_confirmation_positive_button,
-                        new DialogInterface.OnClickListener() {
-                            @Override
-                            public void onClick(DialogInterface dialog, int whichButton) {
-                                joinContacts(contactIds);
-                            }
-                        }
-                )
-                .create();
-    }
-
-    private void joinContacts(TreeSet<Long> contactIds) {
-        final Long[] contactIdsArray = contactIds.toArray(new Long[contactIds.size()]);
-        final long[] contactIdsArray2 = new long[contactIdsArray.length];
-        for (int i = 0; i < contactIds.size(); i++) {
-            contactIdsArray2[i] = contactIdsArray[i];
-        }
-
-        final Intent intent = ContactSaveService.createJoinSeveralContactsIntent(getActivity(),
-                contactIdsArray2);
-        getActivity().startService(intent);
-
-        notifyListener();
-    }
-
-    private void notifyListener() {
-        if (getActivity() instanceof JoinContactsListener) {
-            ((JoinContactsListener) getActivity()).onContactsJoined();
-        } else if (getTargetFragment() != null) {
-            final Intent intent = new Intent()
-                    .putExtra(KEY_POSITION, getArguments().getInt(KEY_POSITION));
-            getTargetFragment().onActivityResult(getTargetRequestCode(),
-                    Activity.RESULT_OK, intent);
-        }
-    }
-
-}
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index e9efd66..c9a4d32 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -157,8 +157,6 @@
 import com.android.contacts.interactions.CallLogInteractionsLoader;
 import com.android.contacts.interactions.ContactDeletionInteraction;
 import com.android.contacts.interactions.ContactInteraction;
-import com.android.contacts.interactions.JoinContactsDialogFragment;
-import com.android.contacts.interactions.JoinContactsDialogFragment.JoinContactsListener;
 import com.android.contacts.interactions.SmsInteractionsLoader;
 import com.android.contacts.quickcontact.ExpandingEntryCardView.Entry;
 import com.android.contacts.quickcontact.ExpandingEntryCardView.EntryContextMenuInfo;
@@ -197,7 +195,7 @@
  * {@link Intent#getSourceBounds()}.
  */
 public class QuickContactActivity extends ContactsActivity
-        implements AggregationSuggestionEngine.Listener, JoinContactsListener {
+        implements AggregationSuggestionEngine.Listener {
 
     /**
      * QuickContacts immediately takes up the full screen. All possible information is shown.
@@ -650,17 +648,23 @@
                 if (!mSelectedAggregationIds.contains(mContactData.getId())) {
                     mSelectedAggregationIds.add(mContactData.getId());
                 }
-                JoinContactsDialogFragment.start(
-                        QuickContactActivity.this, mSelectedAggregationIds);
+
+                final Long[] contactIdsArray = mSelectedAggregationIds.toArray(
+                        new Long[mSelectedAggregationIds.size()]);
+                final long[] contactIdsArray2 = new long[contactIdsArray.length];
+                for (int i = 0; i < contactIdsArray.length; i++) {
+                    contactIdsArray2[i] = contactIdsArray[i];
+                }
+
+                final Intent intent = ContactSaveService.createJoinSeveralContactsIntent(
+                        QuickContactActivity.this, contactIdsArray2);
+                QuickContactActivity.this.startService(intent);
+
+                disableLinkButton();
             }
         });
     }
 
-    @Override
-    public void onContactsJoined() {
-        disableLinkButton();
-    }
-
     private void disableLinkButton() {
         mSuggestionsLinkButton.setClickable(false);
         mSuggestionsLinkButton.getBackground().setColorFilter(