Fix contact selection behavior when searching and clear search on selection.

This commit is contained in:
Alex Hart
2020-06-02 16:27:04 -03:00
committed by GitHub
parent ae87d23003
commit 7f2439f1e9
4 changed files with 88 additions and 20 deletions

View File

@@ -64,6 +64,8 @@ public class ContactSelectionListAdapter extends CursorRecyclerViewAdapter<ViewH
private final static int STYLE_ATTRIBUTES[] = new int[]{R.attr.contact_selection_push_user,
R.attr.contact_selection_lay_user};
public static final int PAYLOAD_SELECTION_CHANGE = 1;
private final boolean multiSelect;
private final LayoutInflater li;
private final TypedArray drawables;
@@ -175,6 +177,7 @@ public class ContactSelectionListAdapter extends CursorRecyclerViewAdapter<ViewH
@Override
public long getHeaderId(int i) {
if (!isActiveCursor()) return -1;
else if (i == -1) return -1;
int contactType = getContactType(i);
@@ -216,6 +219,24 @@ public class ContactSelectionListAdapter extends CursorRecyclerViewAdapter<ViewH
}
}
@Override
protected void onBindItemViewHolder(ViewHolder viewHolder, @NonNull Cursor cursor, @NonNull List<Object> payloads) {
if (!arePayloadsValid(payloads)) {
throw new AssertionError();
}
String rawId = cursor.getString(cursor.getColumnIndexOrThrow(ContactRepository.ID_COLUMN));
RecipientId id = rawId != null ? RecipientId.from(rawId) : null;
int numberType = cursor.getInt(cursor.getColumnIndexOrThrow(ContactRepository.NUMBER_TYPE_COLUMN));
String number = cursor.getString(cursor.getColumnIndexOrThrow(ContactRepository.NUMBER_COLUMN));
if (numberType == ContactRepository.NEW_USERNAME_TYPE) {
viewHolder.setChecked(selectedContacts.contains(SelectedContact.forUsername(id, number)));
} else {
viewHolder.setChecked(selectedContacts.contains(SelectedContact.forPhone(id, number)));
}
}
@Override
public int getItemViewType(@NonNull Cursor cursor) {
if (cursor.getInt(cursor.getColumnIndexOrThrow(ContactRepository.CONTACT_TYPE_COLUMN)) == ContactRepository.DIVIDER_TYPE) {
@@ -225,7 +246,6 @@ public class ContactSelectionListAdapter extends CursorRecyclerViewAdapter<ViewH
}
}
@Override
public HeaderViewHolder onCreateHeaderViewHolder(ViewGroup parent, int position) {
return new HeaderViewHolder(LayoutInflater.from(getContext()).inflate(R.layout.contact_selection_recyclerview_header, parent, false));
@@ -236,6 +256,11 @@ public class ContactSelectionListAdapter extends CursorRecyclerViewAdapter<ViewH
((TextView)viewHolder.itemView).setText(getSpannedHeaderString(position));
}
@Override
protected boolean arePayloadsValid(@NonNull List<Object> payloads) {
return payloads.size() == 1 && payloads.get(0).equals(PAYLOAD_SELECTION_CHANGE);
}
@Override
public void onItemViewRecycled(ViewHolder holder) {
holder.unbind(glideRequests);