summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcalderwoodra <calderwoodra@google.com>2018-04-19 12:23:08 -0700
committerCopybara-Service <copybara-piper@google.com>2018-04-19 12:25:38 -0700
commit8006c6cc6dabfb6c84fe51df506bbcf412c8f8fe (patch)
treeba71e6eadec7f605ee7dadf6d8cc95bd26031694
parent7c6d4125661f20e9ba57c30b8c6873f4ed4038ba (diff)
If the Speed Dial contact only has one channel, place the call immediately.
If the disambig dialog would only show one option, just skip the dialog and place the call directly. Don't save the number as a default entry though because the contact could potentially change later (become duo reachable, get another number, ect.) Bug: 36841782 Test: SpeedDialIntegrationTest PiperOrigin-RevId: 193555958 Change-Id: Icbb7e876b7a7c5aaa979980249bf074ec1d7a395
-rw-r--r--java/com/android/dialer/databasepopulator/ContactsPopulator.java1
-rw-r--r--java/com/android/dialer/speeddial/SpeedDialFragment.java89
2 files changed, 65 insertions, 25 deletions
diff --git a/java/com/android/dialer/databasepopulator/ContactsPopulator.java b/java/com/android/dialer/databasepopulator/ContactsPopulator.java
index f22552db7..f21e32512 100644
--- a/java/com/android/dialer/databasepopulator/ContactsPopulator.java
+++ b/java/com/android/dialer/databasepopulator/ContactsPopulator.java
@@ -152,6 +152,7 @@ public final class ContactsPopulator {
Assert.isWorkerThread();
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
addContact(SIMPLE_CONTACTS[0], operations);
+ addContact(SIMPLE_CONTACTS[3], operations);
addContact(SIMPLE_CONTACTS[5], operations);
try {
context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, operations);
diff --git a/java/com/android/dialer/speeddial/SpeedDialFragment.java b/java/com/android/dialer/speeddial/SpeedDialFragment.java
index c45ec5856..793169a81 100644
--- a/java/com/android/dialer/speeddial/SpeedDialFragment.java
+++ b/java/com/android/dialer/speeddial/SpeedDialFragment.java
@@ -21,6 +21,8 @@ import android.os.Bundle;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentActivity;
+import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
@@ -62,16 +64,12 @@ import com.google.common.collect.ImmutableList;
public class SpeedDialFragment extends Fragment {
private final SpeedDialHeaderListener headerListener = new SpeedDialFragmentHeaderListener();
- private final FavoriteContactsListener favoritesListener = new SpeedDialFavoritesListener();
private final SuggestedContactsListener suggestedListener = new SpeedDialSuggestedListener();
- private View rootLayout;
private ContextMenu contextMenu;
private FrameLayout contextMenuBackground;
- private ContextMenuItemListener contextMenuItemListener;
private SpeedDialAdapter adapter;
- private SpeedDialLayoutManager layoutManager;
private SupportUiListener<ImmutableList<SpeedDialUiItem>> speedDialLoaderListener;
/**
@@ -80,6 +78,8 @@ public class SpeedDialFragment extends Fragment {
*/
private boolean updateSpeedDialItemsOnResume = true;
+ private FavoriteContactsListener favoritesListener;
+
public static SpeedDialFragment newInstance() {
return new SpeedDialFragment();
}
@@ -89,14 +89,33 @@ public class SpeedDialFragment extends Fragment {
public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
LogUtil.enterBlock("SpeedDialFragment.onCreateView");
- rootLayout = inflater.inflate(R.layout.fragment_speed_dial, container, false);
+ View rootLayout = inflater.inflate(R.layout.fragment_speed_dial, container, false);
+
+ // Setup favorite contact context menu
+ contextMenu = rootLayout.findViewById(R.id.favorite_contact_context_menu);
+ contextMenuBackground = rootLayout.findViewById(R.id.context_menu_background);
+ contextMenuBackground.setOnClickListener(
+ v -> {
+ contextMenu.hideMenu();
+ contextMenuBackground.setVisibility(View.GONE);
+ });
// Setup our RecyclerView
- RecyclerView recyclerView = rootLayout.findViewById(R.id.speed_dial_recycler_view);
+ SpeedDialLayoutManager layoutManager =
+ new SpeedDialLayoutManager(getContext(), 3 /* spanCount */);
+ favoritesListener =
+ new SpeedDialFavoritesListener(
+ getActivity(),
+ getChildFragmentManager(),
+ rootLayout,
+ contextMenu,
+ contextMenuBackground,
+ new SpeedDialContextMenuItemListener(),
+ layoutManager);
adapter =
new SpeedDialAdapter(getContext(), favoritesListener, suggestedListener, headerListener);
- layoutManager = new SpeedDialLayoutManager(getContext(), 3 /* spanCount */);
layoutManager.setSpanSizeLookup(adapter.getSpanSizeLookup());
+ RecyclerView recyclerView = rootLayout.findViewById(R.id.speed_dial_recycler_view);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);
@@ -106,16 +125,6 @@ public class SpeedDialFragment extends Fragment {
touchHelper.attachToRecyclerView(recyclerView);
adapter.setItemTouchHelper(touchHelper);
- // Setup favorite contact context menu
- contextMenu = rootLayout.findViewById(R.id.favorite_contact_context_menu);
- contextMenuBackground = rootLayout.findViewById(R.id.context_menu_background);
- contextMenuBackground.setOnClickListener(
- v -> {
- contextMenu.hideMenu();
- contextMenuBackground.setVisibility(View.GONE);
- });
- contextMenuItemListener = new SpeedDialContextMenuItemListener();
-
speedDialLoaderListener =
DialerExecutorComponent.get(getContext())
.createUiListener(getChildFragmentManager(), "speed_dial_loader_listener");
@@ -181,26 +190,56 @@ public class SpeedDialFragment extends Fragment {
}
}
- private final class SpeedDialFavoritesListener implements FavoriteContactsListener {
+ private static final class SpeedDialFavoritesListener implements FavoriteContactsListener {
+
+ private final FragmentActivity activity;
+ private final FragmentManager childFragmentManager;
+ private final View rootLayout;
+ private final ContextMenu contextMenu;
+ private final View contextMenuBackground;
+ private final ContextMenuItemListener contextMenuListener;
+ private final SpeedDialLayoutManager layoutManager;
+
+ SpeedDialFavoritesListener(
+ FragmentActivity activity,
+ FragmentManager childFragmentManager,
+ View rootLayout,
+ ContextMenu contextMenu,
+ View contextMenuBackground,
+ ContextMenuItemListener contextMenuListener,
+ SpeedDialLayoutManager layoutManager) {
+ this.activity = activity;
+ this.childFragmentManager = childFragmentManager;
+ this.rootLayout = rootLayout;
+ this.contextMenu = contextMenu;
+ this.contextMenuBackground = contextMenuBackground;
+ this.contextMenuListener = contextMenuListener;
+ this.layoutManager = layoutManager;
+ }
@Override
public void onAmbiguousContactClicked(SpeedDialUiItem speedDialUiItem) {
- DisambigDialog.show(speedDialUiItem, getChildFragmentManager());
+ // If there is only one channel, skip the menu and place a call directly
+ if (speedDialUiItem.channels().size() == 1) {
+ onClick(speedDialUiItem.channels().get(0));
+ return;
+ }
+
+ DisambigDialog.show(speedDialUiItem, childFragmentManager);
}
@Override
public void onClick(Channel channel) {
if (channel.technology() == Channel.DUO) {
- Logger.get(getContext())
+ Logger.get(activity)
.logImpression(DialerImpression.Type.LIGHTBRINGER_VIDEO_REQUESTED_FOR_FAVORITE_CONTACT);
- Intent intent =
- DuoComponent.get(getContext()).getDuo().getIntent(getContext(), channel.number());
- getActivity().startActivityForResult(intent, ActivityRequestCodes.DIALTACTS_DUO);
+ Intent intent = DuoComponent.get(activity).getDuo().getIntent(activity, channel.number());
+ activity.startActivityForResult(intent, ActivityRequestCodes.DIALTACTS_DUO);
return;
}
PreCall.start(
- getContext(),
+ activity,
new CallIntentBuilder(channel.number(), CallInitiationType.Type.SPEED_DIAL)
.setIsVideoCall(channel.isVideoTechnology()));
}
@@ -208,7 +247,7 @@ public class SpeedDialFragment extends Fragment {
@Override
public void showContextMenu(View view, SpeedDialUiItem speedDialUiItem) {
layoutManager.setScrollEnabled(false);
- contextMenu.showMenu(rootLayout, view, speedDialUiItem, contextMenuItemListener);
+ contextMenu.showMenu(rootLayout, view, speedDialUiItem, contextMenuListener);
}
@Override