diff --git a/jami-android/app/src/main/java/cx/ring/views/AvatarDrawable.kt b/jami-android/app/src/main/java/cx/ring/views/AvatarDrawable.kt index b220e4a9d30f91244a4e3a24386dbf5eee04c85d..b7815403de318eb1a79264fad7acbec8b76e0827 100644 --- a/jami-android/app/src/main/java/cx/ring/views/AvatarDrawable.kt +++ b/jami-android/app/src/main/java/cx/ring/views/AvatarDrawable.kt @@ -220,6 +220,12 @@ class AvatarDrawable : Drawable { fun withNameData(profileName: String?, username: String?) = withName(if (profileName.isNullOrEmpty()) username else profileName) + fun withUser(user: ContactViewModel?) = if (user == null) this else + withPhoto(user.profile.avatar as? Bitmap?) + .withId(user.contact.uri.toString()) + .withPresence(false) + .withNameData(user.profile.displayName, user.registeredName) + fun withContact(contact: ContactViewModel?) = if (contact == null) this else withPhoto(contact.profile.avatar as? Bitmap?) .withId(contact.contact.uri.toString()) @@ -237,8 +243,12 @@ class AvatarDrawable : Drawable { } val bitmaps: MutableList<Bitmap> = ArrayList(contacts.size) var notTheUser = 0 + var user: ContactViewModel? = null for (contact in contacts) { - if (contact.contact.isUser) continue + if (contact.contact.isUser) { + user = contact + continue + } notTheUser++ val bitmap = contact.profile.avatar as? Bitmap? if (bitmap != null) { @@ -251,13 +261,8 @@ class AvatarDrawable : Drawable { if (!contact.contact.isUser) return withContact(contact) } } - if (bitmaps.isEmpty()) { - // Fallback to the user avatar - for (contact in contacts) return withContact(contact) - } else { - return withPhotos(bitmaps) - } - return this + // If alone in group, fallback to the user avatar. + return if (bitmaps.isEmpty()) withUser(user) else withPhotos(bitmaps) } fun withConversation(conversation: Conversation, profile: Profile, contacts: List<ContactViewModel>): Builder =