Refactor AvatarImageView#setAvatarClickHandler.

This triggered a call to Recipient#isGroup when rendering a view, which
itself could trigger a DB read. This delays the call to #isGroup to
lower the possibility of doing DB reads on the main thread.
This commit is contained in:
Greyson Parrelli 2019-12-18 16:45:39 -05:00
parent d7c350f987
commit 848101a783

View file

@ -136,17 +136,17 @@ public final class AvatarImageView extends AppCompatImageView {
} }
private void setAvatarClickHandler(final Recipient recipient, boolean quickContactEnabled) { private void setAvatarClickHandler(final Recipient recipient, boolean quickContactEnabled) {
if (!recipient.isGroup() && quickContactEnabled) { super.setOnClickListener(v -> {
super.setOnClickListener(v -> { if (!recipient.isGroup() && quickContactEnabled) {
if (recipient.getContactUri() != null) { if (recipient.getContactUri() != null) {
ContactsContract.QuickContact.showQuickContact(getContext(), AvatarImageView.this, recipient.getContactUri(), ContactsContract.QuickContact.MODE_LARGE, null); ContactsContract.QuickContact.showQuickContact(getContext(), AvatarImageView.this, recipient.getContactUri(), ContactsContract.QuickContact.MODE_LARGE, null);
} else { } else {
getContext().startActivity(RecipientExporter.export(recipient).asAddContactIntent()); getContext().startActivity(RecipientExporter.export(recipient).asAddContactIntent());
} }
}); } else {
} else { listener.onClick(v);
super.setOnClickListener(listener); }
} });
} }
private static class RecipientContactPhoto { private static class RecipientContactPhoto {