Update app bar in ConversationActivity with received avatar

This commit is contained in:
Sebastian Kürten
2020-12-08 12:36:37 +01:00
committed by Torsten Grote
parent a52c97ecf7
commit bf9ba13b68
2 changed files with 26 additions and 1 deletions

View File

@@ -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);
});

View File

@@ -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.