mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Update app bar in ConversationActivity with received avatar
This commit is contained in:
committed by
Torsten Grote
parent
a52c97ecf7
commit
bf9ba13b68
@@ -233,7 +233,7 @@ public class ConversationActivity extends BriarActivity
|
||||
toolbarStatus = toolbar.findViewById(R.id.contactStatus);
|
||||
toolbarTitle = toolbar.findViewById(R.id.contactName);
|
||||
|
||||
observeOnce(viewModel.getContactItem(), this, contactItem -> {
|
||||
viewModel.getContactItem().observe(this, contactItem -> {
|
||||
requireNonNull(contactItem);
|
||||
setAvatar(toolbarAvatar, contactItem);
|
||||
});
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.briarproject.briar.android.util.UiUtils;
|
||||
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
||||
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
||||
import org.briarproject.briar.api.avatar.event.AvatarUpdatedEvent;
|
||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||
import org.briarproject.briar.api.identity.AuthorManager;
|
||||
import org.briarproject.briar.api.media.AttachmentHeader;
|
||||
@@ -151,9 +152,33 @@ public class ConversationViewModel extends DbViewModel
|
||||
runOnDbThread(() -> attachmentRetriever
|
||||
.loadAttachmentItem(a.getMessageId()));
|
||||
}
|
||||
} else if (e instanceof AvatarUpdatedEvent) {
|
||||
AvatarUpdatedEvent a = (AvatarUpdatedEvent) e;
|
||||
if (a.getContactId().equals(contactId)) {
|
||||
LOG.info("Avatar updated");
|
||||
updateAvatar(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void updateAvatar(AvatarUpdatedEvent a) {
|
||||
// Make sure that contactItem has been set by the task initiated
|
||||
// by loadContact() before we update the avatar.
|
||||
observeForeverOnce(contactItem, oldContactItem -> {
|
||||
requireNonNull(oldContactItem);
|
||||
|
||||
AuthorInfo oldAuthorInfo = oldContactItem.getAuthorInfo();
|
||||
|
||||
AuthorInfo newAuthorInfo = new AuthorInfo(oldAuthorInfo.getStatus(),
|
||||
oldAuthorInfo.getAlias(), a.getAttachmentHeader());
|
||||
ContactItem newContactItem =
|
||||
new ContactItem(oldContactItem.getContact(), newAuthorInfo);
|
||||
|
||||
contactItem.setValue(newContactItem);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Setting the {@link ContactId} automatically triggers loading of other
|
||||
* data.
|
||||
|
||||
Reference in New Issue
Block a user