diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-04-13 23:31:31 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-04-13 23:31:31 +0000 |
commit | d94c00d6629da03c96a101781fbc21e0daca8db8 (patch) | |
tree | a59d481b856647dd26a0aefd0ea3be8e82784303 /java/com/android/dialer/speeddial/FavoritesViewHolder.java | |
parent | 91004eccd1f2c95ac85f4ab15ba0d6b2aaaaac5b (diff) | |
parent | 5621909c288e785ff9c8a6cc12d3dae8ed837b66 (diff) |
Merge "Implement drag to remove contacts in SpeedDialFragment."
Diffstat (limited to 'java/com/android/dialer/speeddial/FavoritesViewHolder.java')
-rw-r--r-- | java/com/android/dialer/speeddial/FavoritesViewHolder.java | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/java/com/android/dialer/speeddial/FavoritesViewHolder.java b/java/com/android/dialer/speeddial/FavoritesViewHolder.java index 4f0cf65a0..56d9f36d9 100644 --- a/java/com/android/dialer/speeddial/FavoritesViewHolder.java +++ b/java/com/android/dialer/speeddial/FavoritesViewHolder.java @@ -19,9 +19,11 @@ package com.android.dialer.speeddial; import android.content.Context; import android.provider.ContactsContract.Contacts; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.helper.ItemTouchHelper; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; +import android.view.ViewConfiguration; import android.widget.FrameLayout; import android.widget.QuickContactBadge; import android.widget.TextView; @@ -29,12 +31,14 @@ import com.android.dialer.common.Assert; import com.android.dialer.glidephotomanager.GlidePhotoManagerComponent; import com.android.dialer.glidephotomanager.PhotoInfo; import com.android.dialer.speeddial.database.SpeedDialEntry.Channel; +import com.android.dialer.speeddial.draghelper.SpeedDialFavoritesViewHolderOnTouchListener; +import com.android.dialer.speeddial.draghelper.SpeedDialFavoritesViewHolderOnTouchListener.OnTouchFinishCallback; import com.android.dialer.speeddial.loader.SpeedDialUiItem; import java.util.List; /** ViewHolder for starred/favorite contacts in {@link SpeedDialFragment}. */ public class FavoritesViewHolder extends RecyclerView.ViewHolder - implements OnClickListener, OnLongClickListener { + implements OnClickListener, OnLongClickListener, OnTouchFinishCallback { private final FavoriteContactsListener listener; @@ -45,7 +49,7 @@ public class FavoritesViewHolder extends RecyclerView.ViewHolder private SpeedDialUiItem speedDialUiItem; - public FavoritesViewHolder(View view, FavoriteContactsListener listener) { + public FavoritesViewHolder(View view, ItemTouchHelper helper, FavoriteContactsListener listener) { super(view); photoView = view.findViewById(R.id.avatar); nameView = view.findViewById(R.id.name); @@ -53,6 +57,9 @@ public class FavoritesViewHolder extends RecyclerView.ViewHolder videoCallIcon = view.findViewById(R.id.video_call_container); view.setOnClickListener(this); view.setOnLongClickListener(this); + view.setOnTouchListener( + new SpeedDialFavoritesViewHolderOnTouchListener( + ViewConfiguration.get(view.getContext()), helper, this, this)); photoView.setClickable(false); this.listener = listener; } @@ -96,12 +103,16 @@ public class FavoritesViewHolder extends RecyclerView.ViewHolder @Override public boolean onLongClick(View view) { - // TODO(calderwoodra): implement drag and drop logic // TODO(calderwoodra): add bounce/sin wave scale animation - listener.onLongClick(photoView, speedDialUiItem); + listener.showContextMenu(photoView, speedDialUiItem); return true; } + @Override + public void onTouchFinished(boolean closeContextMenu) { + listener.onTouchFinished(closeContextMenu); + } + /** Listener/callback for {@link FavoritesViewHolder} actions. */ public interface FavoriteContactsListener { @@ -112,6 +123,9 @@ public class FavoritesViewHolder extends RecyclerView.ViewHolder void onClick(Channel channel); /** Called when the user long clicks on a favorite contact. */ - void onLongClick(View view, SpeedDialUiItem speedDialUiItem); + void showContextMenu(View view, SpeedDialUiItem speedDialUiItem); + + /** Called when the user is no longer touching the favorite contact. */ + void onTouchFinished(boolean closeContextMenu); } } |