Show member count in contact selection list.

This commit is contained in:
Cody Henthorne
2020-06-09 13:32:48 -04:00
committed by GitHub
parent 2751fd7efc
commit cea6a83d8a
2 changed files with 22 additions and 1 deletions

View File

@@ -112,10 +112,14 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientF
@SuppressLint("SetTextI18n")
private void setText(@Nullable Recipient recipient, int type, String name, String number, String label) {
if (number == null || number.isEmpty() || GroupId.isEncodedGroup(number)) {
if (number == null || number.isEmpty()) {
this.nameView.setEnabled(false);
this.numberView.setText("");
this.labelView.setVisibility(View.GONE);
} else if (recipient != null && recipient.isGroup()) {
this.nameView.setEnabled(false);
this.numberView.setText(getGroupMemberCount(recipient));
this.labelView.setVisibility(View.GONE);
} else if (type == ContactRepository.PUSH_TYPE) {
this.numberView.setText(number);
this.nameView.setEnabled(true);
@@ -149,6 +153,14 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientF
return chipName;
}
private String getGroupMemberCount(@NonNull Recipient recipient) {
if (!recipient.isGroup()) {
throw new AssertionError();
}
int memberCount = recipient.getParticipants().size();
return getContext().getResources().getQuantityString(R.plurals.contact_selection_list_item__number_of_members, memberCount, memberCount);
}
public @Nullable LiveRecipient getRecipient() {
return recipient;
}
@@ -165,5 +177,8 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientF
public void onRecipientChanged(@NonNull Recipient recipient) {
contactPhotoImage.setAvatar(glideRequests, recipient, false);
nameView.setText(recipient);
if (recipient.isGroup()) {
numberView.setText(getGroupMemberCount(recipient));
}
}
}