Suggested Aggregations Color and Spacing Tweaks

In collapsed view
- modified image size, text.

In expanded view
- modified title text, help text and size,
- modified current contact photo and padding, added current contact info below contact name,
- modified suggestion photo and padding
- modified button color, and made it listen to the checkboxes

Bug: 25165935
Change-Id: I21a32c78d0bcc664693547641e0d0e8ca37a90e3
diff --git a/res/layout/quickcontact_collapsed_suggestion_card.xml b/res/layout/quickcontact_collapsed_suggestion_card.xml
index dbd3eee..494447f 100644
--- a/res/layout/quickcontact_collapsed_suggestion_card.xml
+++ b/res/layout/quickcontact_collapsed_suggestion_card.xml
@@ -16,7 +16,7 @@
 <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:card_view="http://schemas.android.com/apk/res-auto"
     style="@style/ExpandingEntryCardStyle"
-    android:layout_height="wrap_content"
+    android:layout_height="@dimen/quickcontact_collapse_view_height"
     android:layout_width="match_parent"
     android:visibility="gone"
     android:id="@+id/collapsed_suggestion_card">
@@ -30,22 +30,22 @@
 
         <ImageView
                 android:src="@drawable/quantum_ic_assistant_grey600_24"
-                android:layout_width="@dimen/detail_network_icon_size"
-                android:layout_height="@dimen/detail_network_icon_size"
-                android:layout_margin="16dip"
+                android:layout_width="@dimen/quickcontact_collapse_icon_size"
+                android:layout_height="@dimen/quickcontact_collapse_icon_size"
+                android:layout_margin="@dimen/quickcontact_collapse_image_padding"
                 android:layout_gravity="center_vertical"/>
 
         <TextView
                 android:id="@+id/collapsed_suggestion_card_title"
                 android:textSize="@dimen/expanding_entry_card_title_text_size"
+                android:layout_marginLeft="16dp"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_weight="1"
                 android:textColor="@color/quickcontact_entry_header_text_color"
                 android:singleLine="true"
                 android:ellipsize="end"
-                android:paddingTop="@dimen/quickcontact_suggestion_card_image_spacing"
-                android:paddingBottom="@dimen/quickcontact_suggestion_card_image_spacing"/>
+                android:paddingTop="@dimen/quickcontact_collapse_text_padding"/>
 
         <ImageView
                 android:src="@drawable/ic_menu_expander_minimized_holo_light"
diff --git a/res/layout/quickcontact_expand_suggestion_card.xml b/res/layout/quickcontact_expand_suggestion_card.xml
index c2c32cd..c5da833 100644
--- a/res/layout/quickcontact_expand_suggestion_card.xml
+++ b/res/layout/quickcontact_expand_suggestion_card.xml
@@ -45,7 +45,7 @@
 
         <TextView
             android:id="@+id/expand_suggestion_card_help"
-            android:textSize="@dimen/expanding_entry_card_title_text_size"
+            android:textSize="@dimen/quickcontact_expanding_help_text_size"
             android:text="@string/suggestion_card_help_message"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
@@ -66,10 +66,8 @@
             android:paddingStart="@dimen/quickcontact_suggestion_card_image_spacing"/>
 
         <LinearLayout
-            android:layout_height="wrap_content"
+            android:layout_height="@dimen/quickcontact_expanding_item_height"
             android:layout_width="match_parent"
-            android:layout_marginTop="@dimen/quickcontact_suggestion_card_layout_margin"
-            android:layout_marginBottom="@dimen/quickcontact_suggestion_card_layout_margin"
             android:orientation="horizontal">
 
             <ImageView
@@ -80,7 +78,16 @@
                 android:layout_marginStart="@dimen/quickcontact_suggestion_card_image_spacing"
                 android:scaleType="fitCenter" />
 
-            <TextView
+            <LinearLayout
+                android:id="@+id/suggestion_for_contact_info"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="@dimen/quickcontact_expanding_item_image_padding"
+                android:layout_weight="1"
+                android:orientation="vertical"
+                android:layout_gravity="center_vertical">
+
+                <TextView
                     android:id="@+id/suggestion_for_name"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
@@ -89,8 +96,18 @@
                     android:textColor="@color/quickcontact_entry_header_text_color"
                     android:singleLine="true"
                     android:ellipsize="end"
-                    android:layout_marginStart="@dimen/expanding_entry_card_item_image_spacing"
-                    android:layout_marginEnd="@dimen/expanding_entry_card_item_image_spacing"/>
+                    android:layout_marginTop="@dimen/quickcontact_suggestion_card_layout_margin" />
+
+                <TextView
+                    android:id="@+id/suggestion_for_contacts_number"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:textAppearance="?android:attr/textAppearanceSmall"
+                    android:layout_marginBottom="@dimen/quickcontact_suggestion_card_layout_margin"
+                    android:singleLine="true"
+                    android:ellipsize="end" />
+
+            </LinearLayout>
 
         </LinearLayout>
 
@@ -114,8 +131,11 @@
 
         <LinearLayout
             android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
+            android:layout_height="@dimen/quickcontact_expanding_button_section_height"
             android:layout_gravity="center_vertical|end"
+            android:layout_marginRight="@dimen/quickcontact_expanding_button_right_padding"
+            android:layout_marginTop="@dimen/quickcontact_expanding_button_section_padding"
+            android:layout_marginBottom="@dimen/quickcontact_expanding_button_section_padding"
             android:orientation="horizontal">
 
             <Button
@@ -127,11 +147,9 @@
 
             <Button
                 android:id="@+id/link_button"
-                style="?android:attr/buttonBarButtonStyle"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:text="@string/quickcontact_suggestion_link_button"
-                android:paddingEnd="@dimen/quickcontact_suggestion_card_image_spacing"/>
+                android:text="@string/quickcontact_suggestion_link_button"/>
         </LinearLayout>
     </LinearLayout>
 </android.support.v7.widget.CardView>
\ No newline at end of file
diff --git a/res/layout/quickcontact_suggestion_contact_item.xml b/res/layout/quickcontact_suggestion_contact_item.xml
index e7c5af6..127dfcc 100644
--- a/res/layout/quickcontact_suggestion_contact_item.xml
+++ b/res/layout/quickcontact_suggestion_contact_item.xml
@@ -17,9 +17,8 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="horizontal"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:layout_marginTop="@dimen/quickcontact_suggestion_card_layout_margin"
-    android:layout_marginBottom="@dimen/quickcontact_suggestion_card_layout_margin">
+    android:layout_height="@dimen/quickcontact_expanding_item_height"
+    android:paddingTop="@dimen/quickcontact_expanding_item_padding">
 
     <ImageView
         android:id="@+id/aggregation_suggestion_photo"
@@ -33,7 +32,7 @@
         android:id="@+id/suggestion_contact_item"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginStart="@dimen/expanding_entry_card_item_image_spacing"
+        android:layout_marginStart="@dimen/quickcontact_expanding_item_image_padding"
         android:layout_weight="1"
         android:orientation="vertical"
         android:layout_gravity="center_vertical">
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 7b20f82..0025a41 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -68,6 +68,12 @@
     <!-- Color of button background in compact photo picker. -->
     <color name="google_grey_600">#757575</color>
 
-    <!-- Color of button text color in compact photo picker, 85% white. -->
+    <!-- Color of button text in compact photo picker, 85% white. -->
     <color name="photo_action_button_color">#D9FFFFFF</color>
+
+    <!-- Color of text on disabled link contacts button, 25% black. -->
+    <color name="disabled_button_text">#40000000</color>
+
+    <!-- Color of background of disabled link contacts button, 15% black. -->
+    <color name="disabled_button_background">#26000000</color>
 </resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 16bc213..5a75e59 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -231,11 +231,22 @@
     <dimen name="expanding_entry_card_item_header_only_margin_bottom">2dp</dimen>
     <dimen name="expanding_entry_card_item_no_icon_margin_top">6dp</dimen>
 
-    <dimen name="quickcontact_suggestion_card_icon_height">24dp</dimen>
-    <dimen name="quickcontact_suggestion_card_icon_width">24dp</dimen>
+    <dimen name="quickcontact_suggestion_card_icon_height">40dp</dimen>
+    <dimen name="quickcontact_suggestion_card_icon_width">40dp</dimen>
     <dimen name="quickcontact_suggestion_card_image_spacing">20dp</dimen>
     <dimen name="quickcontact_suggestion_card_layout_margin">8dp</dimen>
     <dimen name="quickcontact_suggestion_card_checkbox_right_margin">16dp</dimen>
+    <dimen name="quickcontact_collapse_view_height">48dp</dimen>
+    <dimen name="quickcontact_collapse_icon_size">24dp</dimen>
+    <dimen name="quickcontact_collapse_text_padding">12dp</dimen>
+    <dimen name="quickcontact_collapse_image_padding">16dp</dimen>
+    <dimen name="quickcontact_expanding_help_text_size">14sp</dimen>
+    <dimen name="quickcontact_expanding_button_right_padding">16dp</dimen>
+    <dimen name="quickcontact_expanding_item_height">72dp</dimen>
+    <dimen name="quickcontact_expanding_item_padding">8dp</dimen>
+    <dimen name="quickcontact_expanding_item_image_padding">12dp</dimen>
+    <dimen name="quickcontact_expanding_button_section_height">48dp</dimen>
+    <dimen name="quickcontact_expanding_button_section_padding">8dp</dimen>
 
     <!-- The width the that the tabs occupy in the ActionBar when in landscape mode.
          426dp is the height of a "small" screen. We should leave 240dp for
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3f721b3..935937c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -776,6 +776,9 @@
     <!-- Label for the linked contacts selector which indicates the number of raw contacts which have been linked together into the aggregate being viewed. [CHAR LIMIT=40] -->
     <string name="compact_editor_linked_contacts_selector_title">Linked contacts (<xliff:g id="count">%d</xliff:g>)</string>
 
+    <!-- Number of linked contacts of the current contact, only shown when there are more than 2 linked contacts (plural only!!!) [CHAR LIMIT=60] -->
+    <string name="quickcontact_contacts_number"><xliff:g id="count">%d</xliff:g> linked contacts</string>
+
     <!-- Quick contact display name with phonetic name -->
     <string name="quick_contact_display_name_with_phonetic"><xliff:g id="display_name">%s</xliff:g> (<xliff:g id="phonetic_name">%s</xliff:g>)</string>
 
@@ -787,8 +790,8 @@
 
     <!-- Suggestion card title in quick contact UI [CHAR LIMIT=100] -->
     <plurals name="quickcontact_suggestion_card_title">
-        <item quantity="one">1 Duplicate Detected</item>
-        <item quantity="other"><xliff:g id="count">%d</xliff:g> Duplicates Detected</item>
+        <item quantity="one">1 Possible duplicate detected</item>
+        <item quantity="other"><xliff:g id="count">%d</xliff:g> Possible duplicates detected</item>
     </plurals>
 
     <!-- Suggestions number in quick contact suggestion card [CHAR LIMIT=60] -->
@@ -810,10 +813,10 @@
     <string name="suggestion_card_this_contact_title">This contact</string>
 
     <!-- "Duplicates" title showing in suggestion card in Quick contact. [CHAR LIMIT=30]-->
-    <string name="suggestion_card_duplicates_title">Duplicates</string>
+    <string name="suggestion_card_duplicates_title">Possible duplicates</string>
 
     <!-- Help message showing in suggestion card in Quick contact. [CHAR LIMIT=500]-->
-    <string name="suggestion_card_help_message">Clean up duplicate contacts to see all info in one place. For more details on a contact tap on the avatar. You can always change the profile photo or separate contacts at anytime.</string>
+    <string name="suggestion_card_help_message">Clean up duplicate contacts for the same person by linking them together.</string>
 
     <!-- Linked contacts title showing in contact editor UI. [CHAR LIMIT=30]-->
     <string name="compact_editor_linked_contacts_title">Linked contacts</string>
@@ -830,4 +833,7 @@
     <!-- Title of photo picker [CHAR LIMIT=30]-->
     <string name="photo_picker_title">Choose photo</string>
 
+    <!-- Message below contact name, showing from which account [CHAR LIMIT=NONE]-->
+    <string name="contact_from_account_name">From <xliff:g id="account_name">%s</xliff:g></string>
+
 </resources>
diff --git a/src/com/android/contacts/editor/AggregationSuggestionEngine.java b/src/com/android/contacts/editor/AggregationSuggestionEngine.java
index fe7a653..aa5f988 100644
--- a/src/com/android/contacts/editor/AggregationSuggestionEngine.java
+++ b/src/com/android/contacts/editor/AggregationSuggestionEngine.java
@@ -71,6 +71,7 @@
     public static final class Suggestion {
 
         public long contactId;
+        public long photoId;
         public String lookupKey;
         public String name;
         public String phoneNumber;
@@ -459,6 +460,7 @@
                     long photoId = mDataCursor.getLong(DataQuery.PHOTO_ID);
                     if (dataId == photoId && !mDataCursor.isNull(DataQuery.PHOTO)) {
                         suggestion.photo = mDataCursor.getBlob(DataQuery.PHOTO);
+                        suggestion.photoId = photoId;
                     }
                 }
             }
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 589c58d..cd70e07 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -148,6 +148,7 @@
 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;
@@ -180,13 +181,16 @@
 import java.util.TreeSet;
 import java.util.concurrent.ConcurrentHashMap;
 
+import android.graphics.PorterDuff;
+import android.support.v4.content.ContextCompat;
+
 /**
  * Mostly translucent {@link Activity} that shows QuickContact dialog. It loads
  * data asynchronously, and then shows a popup with details centered around
  * {@link Intent#getSourceBounds()}.
  */
 public class QuickContactActivity extends ContactsActivity
-        implements AggregationSuggestionEngine.Listener {
+        implements AggregationSuggestionEngine.Listener, JoinContactsListener {
 
     /**
      * QuickContacts immediately takes up the full screen. All possible information is shown.
@@ -202,6 +206,7 @@
     private static final String KEY_SELECTED_SUGGESTION_CONTACTS = "selected_suggestion_contacts";
     private static final String KEY_PREVIOUS_CONTACT_ID = "previous_contact_id";
     private static final String KEY_SUGGESTIONS_AUTO_SELECTED = "suggestions_auto_seleted";
+    private static final String KEY_SELECTED_SUGGESTION_NUMBER = "selected_suggestion_number";
 
     private static final int ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION = 150;
     private static final int REQUEST_CODE_CONTACT_EDITOR_ACTIVITY = 1;
@@ -254,6 +259,7 @@
     private TextView mExpandSuggestionCardTitle;
     private ImageView mSuggestionSummaryPhoto;
     private TextView mSuggestionForName;
+    private TextView mSuggestionContactsNumber;
     private LinearLayout mSuggestionList;
     private Button mSuggestionsCancelButton;
     private Button mSuggestionsLinkButton;
@@ -499,14 +505,18 @@
             return;
         }
 
+        ContactPhotoManager.DefaultImageRequest
+                request = new ContactPhotoManager.DefaultImageRequest(
+                suggestionForName, mContactData.getLookupKey(), ContactPhotoManager.TYPE_DEFAULT,
+                /* isCircular */ true );
+        final long photoId = mContactData.getPhotoId();
         final byte[] photoBytes = mContactData.getThumbnailPhotoBinaryData();
         if (photoBytes != null) {
-            mSuggestionSummaryPhoto.setImageBitmap(BitmapFactory.decodeByteArray(
-                    photoBytes, 0, photoBytes.length));
+            ContactPhotoManager.getInstance(this).loadThumbnail(mSuggestionSummaryPhoto, photoId,
+                /* darkTheme */ false , /* isCircular */ true , request, null);
         } else {
-            mSuggestionSummaryPhoto.setImageDrawable(
-                    ContactPhotoManager.getDefaultAvatarDrawableForContact(
-                            getResources(), false, null));
+            ContactPhotoManager.DEFAULT_AVATAR.applyDefaultImage(mSuggestionSummaryPhoto,
+                    -1, false, request);
         }
 
         final String suggestionTitle = getResources().getQuantityString(
@@ -515,6 +525,16 @@
         mExpandSuggestionCardTitle.setText(suggestionTitle);
 
         mSuggestionForName.setText(suggestionForName);
+        final int linkedContactsNumber = mContactData.getRawContacts().size();
+        final String contactsInfo;
+        if (linkedContactsNumber == 1) {
+            contactsInfo = getResources().getString(R.string.contact_from_account_name,
+                    mContactData.getRawContacts().get(0).getAccountName());
+        } else {
+            contactsInfo = getResources().getString(
+                    R.string.quickcontact_contacts_number, linkedContactsNumber);
+        }
+        mSuggestionContactsNumber.setText(contactsInfo);
 
         final Set<Long> suggestionContactIds = new HashSet<>();
         for (Suggestion suggestion : mSuggestions) {
@@ -551,14 +571,17 @@
         final View suggestionView = layoutInflater.inflate(
                 R.layout.quickcontact_suggestion_contact_item, null);
 
+        ContactPhotoManager.DefaultImageRequest
+                request = new ContactPhotoManager.DefaultImageRequest(
+                suggestion.name, suggestion.lookupKey, ContactPhotoManager.TYPE_DEFAULT, /*
+                isCircular */ true);
         final ImageView photo = (ImageView) suggestionView.findViewById(
                 R.id.aggregation_suggestion_photo);
         if (suggestion.photo != null) {
-            photo.setImageBitmap(BitmapFactory.decodeByteArray(
-                    suggestion.photo, 0, suggestion.photo.length));
+            ContactPhotoManager.getInstance(this).loadThumbnail(photo, suggestion.photoId,
+                   /* darkTheme */ false, /* isCircular */ true, null, null);
         } else {
-            photo.setImageDrawable(ContactPhotoManager.getDefaultAvatarDrawableForContact(
-                    getResources(), false, null));
+            ContactPhotoManager.DEFAULT_AVATAR.applyDefaultImage(photo, -1, false, request);
         }
 
         final TextView name = (TextView) suggestionView.findViewById(R.id.aggregation_suggestion_name);
@@ -568,7 +591,8 @@
                 R.id.aggregation_suggestion_account_name);
         final String accountName = suggestion.rawContacts.get(0).accountName;
         if (!TextUtils.isEmpty(accountName)) {
-            accountNameView.setText("From " + accountName);
+            accountNameView.setText(
+                    getResources().getString(R.string.contact_from_account_name, accountName));
         } else {
             accountNameView.setVisibility(View.GONE);
         }
@@ -585,11 +609,20 @@
             public void onClick(View v) {
                 final CheckBox checkBox = (CheckBox) v;
                 final Long contactId = (Long) checkBox.getTag();
+                if (mSelectedAggregationIds.contains(mContactData.getId())) {
+                    mSelectedAggregationIds.remove(mContactData.getId());
+                }
                 if (checkBox.isChecked()) {
                     mSelectedAggregationIds.add(contactId);
+                    if (mSelectedAggregationIds.size() >= 1) {
+                        enableLinkButton();
+                    }
                 } else {
                     mSelectedAggregationIds.remove(contactId);
                     mSuggestionsShouldAutoSelected = false;
+                    if (mSelectedAggregationIds.isEmpty()) {
+                        disableLinkButton();
+                    }
                 }
             }
         });
@@ -597,6 +630,40 @@
         return suggestionView;
     }
 
+    private void enableLinkButton() {
+        mSuggestionsLinkButton.setClickable(true);
+        mSuggestionsLinkButton.getBackground().setColorFilter(
+                ContextCompat.getColor(this, R.color.primary_color), PorterDuff.Mode.MULTIPLY);
+        mSuggestionsLinkButton.setElevation(6.0f); // reset elevation
+        mSuggestionsLinkButton.setTextColor(getResources().getColor(android.R.color.white, null));
+        mSuggestionsLinkButton.setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                // Join selected contacts.
+                if (!mSelectedAggregationIds.contains(mContactData.getId())) {
+                    mSelectedAggregationIds.add(mContactData.getId());
+                }
+                JoinContactsDialogFragment.start(
+                        QuickContactActivity.this, mSelectedAggregationIds);
+            }
+        });
+    }
+
+    @Override
+    public void onContactsJoined() {
+        disableLinkButton();
+    }
+
+    private void disableLinkButton() {
+        mSuggestionsLinkButton.setClickable(false);
+        mSuggestionsLinkButton.getBackground().setColorFilter(
+                ContextCompat.getColor(this, R.color.disabled_button_background),
+                PorterDuff.Mode.MULTIPLY);
+        mSuggestionsLinkButton.setElevation(0.0f); // makes it look flat and removed shadow
+        mSuggestionsLinkButton.setTextColor(
+                getResources().getColor(R.color.disabled_button_text, null));
+    }
+
     private interface ContextMenuIds {
         static final int COPY_TEXT = 0;
         static final int CLEAR_DEFAULT = 1;
@@ -878,9 +945,11 @@
         mExpandSuggestionCardTitle = (TextView) findViewById(R.id.expand_suggestion_card_title);
         mSuggestionSummaryPhoto = (ImageView) findViewById(R.id.suggestion_icon);
         mSuggestionForName = (TextView) findViewById(R.id.suggestion_for_name);
+        mSuggestionContactsNumber = (TextView) findViewById(R.id.suggestion_for_contacts_number);
         mSuggestionList = (LinearLayout) findViewById(R.id.suggestion_list);
         mSuggestionsCancelButton= (Button) findViewById(R.id.cancel_button);
         mSuggestionsLinkButton = (Button) findViewById(R.id.link_button);
+        final int previousSelectedSuggestion;
         if (savedInstanceState != null) {
             mIsSuggestionListCollapsed = savedInstanceState.getBoolean(
                     KEY_IS_SUGGESTION_LIST_COLLAPSED, true);
@@ -889,11 +958,17 @@
                     KEY_SUGGESTIONS_AUTO_SELECTED, true);
             mSelectedAggregationIds = (TreeSet<Long>)
                     savedInstanceState.getSerializable(KEY_SELECTED_SUGGESTION_CONTACTS);
+            previousSelectedSuggestion = savedInstanceState.getInt(KEY_SELECTED_SUGGESTION_NUMBER);
         } else {
             mIsSuggestionListCollapsed = true;
             mSelectedAggregationIds.clear();
+            previousSelectedSuggestion = -1;
         }
-
+        if (previousSelectedSuggestion == -1 || previousSelectedSuggestion > 0) {
+            enableLinkButton();
+        } else {
+            disableLinkButton();
+        }
         mCollapasedSuggestionHeader.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View view) {
@@ -913,18 +988,6 @@
             }
         });
 
-        mSuggestionsLinkButton.setOnClickListener(new OnClickListener() {
-            @Override
-            public void onClick(View view) {
-                // Join selected contacts.
-                if (!mSelectedAggregationIds.contains(mContactData.getId())) {
-                    mSelectedAggregationIds.add(mContactData.getId());
-                }
-                JoinContactsDialogFragment.start(
-                        QuickContactActivity.this, mSelectedAggregationIds);
-            }
-        });
-
         mNoContactDetailsCard.setOnClickListener(mEntryClickHandler);
         mContactCard.setOnClickListener(mEntryClickHandler);
         mContactCard.setExpandButtonText(
@@ -1060,6 +1123,13 @@
                 KEY_SUGGESTIONS_AUTO_SELECTED, mSuggestionsShouldAutoSelected);
         savedInstanceState.putSerializable(
                 KEY_SELECTED_SUGGESTION_CONTACTS, mSelectedAggregationIds);
+        final int selectedSuggestion;
+        if (mSelectedAggregationIds.contains(mContactData.getId())) {
+            selectedSuggestion = mSelectedAggregationIds.size() - 1;
+        } else {
+            selectedSuggestion = mSelectedAggregationIds.size();
+        }
+        savedInstanceState.putInt(KEY_SELECTED_SUGGESTION_NUMBER, selectedSuggestion);
     }
 
     private void processIntent(Intent intent) {