summaryrefslogtreecommitdiffstats
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.java49
1 files changed, 17 insertions, 32 deletions
diff --git a/java/com/android/dialer/contactsfragment/ContactsAdapter.java b/java/com/android/dialer/contactsfragment/ContactsAdapter.java
index 4692eff5d..309e034cc 100644
--- a/java/com/android/dialer/contactsfragment/ContactsAdapter.java
+++ b/java/com/android/dialer/contactsfragment/ContactsAdapter.java
@@ -23,10 +23,10 @@ import android.provider.ContactsContract.Contacts;
import android.support.v4.util.ArrayMap;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
+import android.view.View;
import android.view.ViewGroup;
-import android.widget.TextView;
import com.android.contacts.common.ContactPhotoManager;
-import com.android.dialer.common.Assert;
+import com.android.contacts.common.lettertiles.LetterTileDrawable;
/** List adapter for the union of all contacts associated with every account on the device. */
final class ContactsAdapter extends RecyclerView.Adapter<ContactViewHolder> {
@@ -70,7 +70,7 @@ final class ContactsAdapter extends RecyclerView.Adapter<ContactViewHolder> {
getPhotoId(cursor),
getPhotoUri(cursor),
name,
- 0);
+ LetterTileDrawable.TYPE_DEFAULT);
String photoDescription =
context.getString(com.android.contacts.common.R.string.description_quick_contact_for, name);
@@ -79,17 +79,23 @@ final class ContactsAdapter extends RecyclerView.Adapter<ContactViewHolder> {
// Always show the view holder's header if it's the first item in the list. Otherwise, compare
// it to the previous element and only show the anchored header if the row elements fall into
// the same sublists.
- if (position == 0) {
- contactViewHolder.bind(header, name, contactUri, true);
- } else {
- boolean showHeader = !header.equals(getHeaderString(position - 1));
- contactViewHolder.bind(header, name, contactUri, showHeader);
- }
+ boolean showHeader = position == 0 || !header.equals(getHeaderString(position - 1));
+ contactViewHolder.bind(header, name, contactUri, showHeader);
+ }
+
+ @Override
+ public void onViewRecycled(ContactViewHolder contactViewHolder) {
+ super.onViewRecycled(contactViewHolder);
+ holderMap.remove(contactViewHolder);
}
public void refreshHeaders() {
for (ContactViewHolder holder : holderMap.keySet()) {
- onBindViewHolder(holder, holderMap.get(holder));
+ int position = holderMap.get(holder);
+ boolean showHeader =
+ position == 0 || !getHeaderString(position).equals(getHeaderString(position - 1));
+ int visibility = showHeader ? View.VISIBLE : View.INVISIBLE;
+ holder.getHeaderView().setVisibility(visibility);
}
}
@@ -98,27 +104,6 @@ final class ContactsAdapter extends RecyclerView.Adapter<ContactViewHolder> {
return cursor == null ? 0 : cursor.getCount();
}
- public String getHeader(int position) {
- return getHolderAt(position).getHeader();
- }
-
- public TextView getHeaderView(int position) {
- return getHolderAt(position).getHeaderView();
- }
-
- public void setHeaderVisibility(int position, int visibility) {
- getHolderAt(position).getHeaderView().setVisibility(visibility);
- }
-
- private ContactViewHolder getHolderAt(int position) {
- for (ContactViewHolder holder : holderMap.keySet()) {
- if (holderMap.get(holder) == position) {
- return holder;
- }
- }
- throw Assert.createIllegalStateFailException("No holder for position: " + position);
- }
-
private static String getDisplayName(Cursor cursor) {
return cursor.getString(ContactsCursorLoader.CONTACT_DISPLAY_NAME);
}
@@ -138,7 +123,7 @@ final class ContactsAdapter extends RecyclerView.Adapter<ContactViewHolder> {
return Contacts.getLookupUri(contactId, lookupKey);
}
- private String getHeaderString(int position) {
+ public String getHeaderString(int position) {
int index = -1;
int sum = 0;
while (sum <= position) {