mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 22:59:54 +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);
|
toolbarStatus = toolbar.findViewById(R.id.contactStatus);
|
||||||
toolbarTitle = toolbar.findViewById(R.id.contactName);
|
toolbarTitle = toolbar.findViewById(R.id.contactName);
|
||||||
|
|
||||||
observeOnce(viewModel.getContactItem(), this, contactItem -> {
|
viewModel.getContactItem().observe(this, contactItem -> {
|
||||||
requireNonNull(contactItem);
|
requireNonNull(contactItem);
|
||||||
setAvatar(toolbarAvatar, 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.DbViewModel;
|
||||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
||||||
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
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.AuthorInfo;
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
import org.briarproject.briar.api.media.AttachmentHeader;
|
import org.briarproject.briar.api.media.AttachmentHeader;
|
||||||
@@ -151,9 +152,33 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
runOnDbThread(() -> attachmentRetriever
|
runOnDbThread(() -> attachmentRetriever
|
||||||
.loadAttachmentItem(a.getMessageId()));
|
.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
|
* Setting the {@link ContactId} automatically triggers loading of other
|
||||||
* data.
|
* data.
|
||||||
|
|||||||
Reference in New Issue
Block a user