summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/speeddial
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/dialer/speeddial')
-rw-r--r--java/com/android/dialer/speeddial/SpeedDialFragment.java89
1 files changed, 64 insertions, 25 deletions
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