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

Commit 44819eb1 authored by Cody Thomas's avatar Cody Thomas Committed by Android (Google) Code Review
Browse files

Merge "Remove the confirmation dialog when linking duplicates via the overflow...

Merge "Remove the confirmation dialog when linking duplicates via the overflow menu and quick contact."
parents bbd0e7d3 f32dc990
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -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>

+12 −9
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import android.widget.ImageButton;
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.AccountFiltersFragment.AccountFiltersLi
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 @@ public class PeopleActivity extends AppCompatContactsActivity implements
        GroupsListener,
        ProviderStatusListener,
        MultiContactDeleteListener,
        JoinContactsListener,
        NavigationView.OnNavigationItemSelectedListener {

    private static final String TAG = "PeopleActivity";
@@ -1310,11 +1308,16 @@ public class PeopleActivity extends AppCompatContactsActivity implements
    }

    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);
    }

+0 −126
Original line number Diff line number Diff line
/*
 * 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);
        }
    }

}
+14 −10
Original line number Diff line number Diff line
@@ -157,8 +157,6 @@ import com.android.contacts.interactions.CalendarInteractionsLoader;
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 @@ import java.util.concurrent.ConcurrentHashMap;
 * {@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,16 +648,22 @@ public class QuickContactActivity extends ContactsActivity
                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];
                }

    @Override
    public void onContactsJoined() {
                final Intent intent = ContactSaveService.createJoinSeveralContactsIntent(
                        QuickContactActivity.this, contactIdsArray2);
                QuickContactActivity.this.startService(intent);

                disableLinkButton();
            }
        });
    }

    private void disableLinkButton() {
        mSuggestionsLinkButton.setClickable(false);