summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/contactsfragment/ContactsAdapter.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/dialer/contactsfragment/ContactsAdapter.java')
-rw-r--r--java/com/android/dialer/contactsfragment/ContactsAdapter.java20
1 files changed, 13 insertions, 7 deletions
diff --git a/java/com/android/dialer/contactsfragment/ContactsAdapter.java b/java/com/android/dialer/contactsfragment/ContactsAdapter.java
index 8f2120cd7..44abe29da 100644
--- a/java/com/android/dialer/contactsfragment/ContactsAdapter.java
+++ b/java/com/android/dialer/contactsfragment/ContactsAdapter.java
@@ -29,8 +29,8 @@ import android.view.ViewGroup;
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
import com.android.dialer.contactphoto.ContactPhotoManager;
-import com.android.dialer.contactsfragment.ContactsFragment.ClickAction;
import com.android.dialer.contactsfragment.ContactsFragment.Header;
+import com.android.dialer.contactsfragment.ContactsFragment.OnContactSelectedListener;
import com.android.dialer.lettertile.LetterTileDrawable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -50,7 +50,7 @@ final class ContactsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
private final ArrayMap<ContactViewHolder, Integer> holderMap = new ArrayMap<>();
private final Context context;
private final @Header int header;
- private final @ClickAction int clickAction;
+ private final OnContactSelectedListener onContactSelectedListener;
// List of contact sublist headers
private String[] headers = new String[0];
@@ -59,10 +59,11 @@ final class ContactsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
// Cursor with list of contacts
private Cursor cursor;
- ContactsAdapter(Context context, @Header int header, @ClickAction int clickAction) {
+ ContactsAdapter(
+ Context context, @Header int header, OnContactSelectedListener onContactSelectedListener) {
this.context = context;
this.header = header;
- this.clickAction = clickAction;
+ this.onContactSelectedListener = Assert.isNotNull(onContactSelectedListener);
}
void updateCursor(Cursor cursor) {
@@ -92,7 +93,8 @@ final class ContactsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
LayoutInflater.from(context).inflate(R.layout.add_contact_row, parent, false));
case CONTACT_VIEW_TYPE:
return new ContactViewHolder(
- LayoutInflater.from(context).inflate(R.layout.contact_row, parent, false), clickAction);
+ LayoutInflater.from(context).inflate(R.layout.contact_row, parent, false),
+ onContactSelectedListener);
case UNKNOWN_VIEW_TYPE:
default:
throw Assert.createIllegalStateFailException("Invalid view type: " + viewType);
@@ -133,7 +135,7 @@ final class ContactsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
// it to the previous element and only show the anchored header if the row elements fall into
// the same sublists.
boolean showHeader = position == 0 || !header.equals(getHeaderString(position - 1));
- contactViewHolder.bind(header, name, contactUri, showHeader);
+ contactViewHolder.bind(header, name, contactUri, getContactId(cursor), showHeader);
}
/**
@@ -190,11 +192,15 @@ final class ContactsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
}
private static Uri getContactUri(Cursor cursor) {
- long contactId = cursor.getLong(ContactsCursorLoader.CONTACT_ID);
+ long contactId = getContactId(cursor);
String lookupKey = cursor.getString(ContactsCursorLoader.CONTACT_LOOKUP_KEY);
return Contacts.getLookupUri(contactId, lookupKey);
}
+ private static long getContactId(Cursor cursor) {
+ return cursor.getLong(ContactsCursorLoader.CONTACT_ID);
+ }
+
String getHeaderString(int position) {
if (header != Header.NONE) {
if (position == 0) {