Stop observing LiveRecipient in contact list when detached.

This commit is contained in:
Greyson Parrelli 2021-11-04 11:09:27 -04:00
parent cae5dad5d8
commit ff633ddd59
2 changed files with 11 additions and 2 deletions

View file

@ -141,7 +141,7 @@ public class ContactSelectionListAdapter extends CursorRecyclerViewAdapter<ViewH
@Override
public void unbind(@NonNull GlideRequests glideRequests) {
getView().unbind(glideRequests);
getView().unbind();
}
@Override

View file

@ -71,6 +71,12 @@ public class ContactSelectionListItem extends ConstraintLayout implements Recipi
ViewUtil.setTextViewGravityStart(this.nameView, getContext());
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
unbind();
}
public void set(@NonNull GlideRequests glideRequests,
@Nullable RecipientId recipientId,
int type,
@ -92,6 +98,9 @@ public class ContactSelectionListItem extends ConstraintLayout implements Recipi
this.recipient = null;
this.contactPhotoImage.setAvatar(glideRequests, null, false);
} else if (recipientId != null) {
if (this.recipient != null) {
this.recipient.removeForeverObserver(this);
}
this.recipient = Recipient.live(recipientId);
this.recipient.observeForever(this);
}
@ -150,7 +159,7 @@ public class ContactSelectionListItem extends ConstraintLayout implements Recipi
this.checkBox.setEnabled(enabled);
}
public void unbind(GlideRequests glideRequests) {
public void unbind() {
if (recipient != null) {
recipient.removeForeverObserver(this);
recipient = null;