diff options
author | Tobias Thierer <tobiast@google.com> | 2017-06-09 14:16:05 +0000 |
---|---|---|
committer | Tobias Thierer <tobiast@google.com> | 2017-06-09 14:16:05 +0000 |
commit | cded3beaf28a703e1ef8f71bbc6836e6806c3736 (patch) | |
tree | c1b5e8199b5996fc848e7455d04126b9cdbb3c39 /java/com/android/dialer/contactsfragment/ContactsAdapter.java | |
parent | c67d658e7daa453fe9ad9fd1a37f81eaf2048c44 (diff) |
Revert "Update AOSP Dialer source from internal google3 repository at cl/158012278. am: 91ce7d2a47"
This reverts commit c67d658e7daa453fe9ad9fd1a37f81eaf2048c44.
Reason for revert: This CL broke the sailfish-userdebug_javac-all target on master.
Change-Id: I9b54333a654c00154ca84f4ece84bea4f07cc19b
Diffstat (limited to 'java/com/android/dialer/contactsfragment/ContactsAdapter.java')
-rw-r--r-- | java/com/android/dialer/contactsfragment/ContactsAdapter.java | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/java/com/android/dialer/contactsfragment/ContactsAdapter.java b/java/com/android/dialer/contactsfragment/ContactsAdapter.java index 309e034cc..4692eff5d 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.contacts.common.lettertiles.LetterTileDrawable; +import com.android.dialer.common.Assert; /** 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, - LetterTileDrawable.TYPE_DEFAULT); + 0); String photoDescription = context.getString(com.android.contacts.common.R.string.description_quick_contact_for, name); @@ -79,23 +79,17 @@ 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. - 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); + if (position == 0) { + contactViewHolder.bind(header, name, contactUri, true); + } else { + boolean showHeader = !header.equals(getHeaderString(position - 1)); + contactViewHolder.bind(header, name, contactUri, showHeader); + } } public void refreshHeaders() { for (ContactViewHolder holder : holderMap.keySet()) { - 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); + onBindViewHolder(holder, holderMap.get(holder)); } } @@ -104,6 +98,27 @@ 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); } @@ -123,7 +138,7 @@ final class ContactsAdapter extends RecyclerView.Adapter<ContactViewHolder> { return Contacts.getLookupUri(contactId, lookupKey); } - public String getHeaderString(int position) { + private String getHeaderString(int position) { int index = -1; int sum = 0; while (sum <= position) { |