From d707cb30b50977caede5eb43d3764316b01f52c3 Mon Sep 17 00:00:00 2001 From: Luc Calaresu Date: Tue, 5 Mar 2019 05:52:09 +0100 Subject: [PATCH] Display the right contact photo #1264 (#1375) In case different contacts share the same phone number, the displayed photo got mixed-up. This bug was due to the fact that the contact's first phone number was always used. This commit makes sure we keep using the right combination of phone/contact. --- .../com/moez/QKSMS/common/widget/AvatarView.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/presentation/src/main/java/com/moez/QKSMS/common/widget/AvatarView.kt b/presentation/src/main/java/com/moez/QKSMS/common/widget/AvatarView.kt index 7fd4b936..1f12c557 100644 --- a/presentation/src/main/java/com/moez/QKSMS/common/widget/AvatarView.kt +++ b/presentation/src/main/java/com/moez/QKSMS/common/widget/AvatarView.kt @@ -89,10 +89,14 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet } } + /** + * If the [recipient] has a contact: use the contact's avatar, but keep the address. + * Use the recipient address otherwise. + */ fun setContact(recipient: Recipient?) { // If the recipient has a contact, just use that and return recipient?.contact?.let { contact -> - setContact(contact) + setContact(contact, recipient.address) return } @@ -102,10 +106,15 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet updateView() } - fun setContact(contact: Contact?) { + /** + * Use the [contact] information to display the avatar. + * A specific [contactAddress] can be specified (useful when the contact has several addresses). + */ + fun setContact(contact: Contact?, contactAddress: String? = null) { lookupKey = contact?.lookupKey name = contact?.name - address = contact?.numbers?.firstOrNull()?.address + // If a contactAddress has been given, we use it. Use the contact address otherwise. + address = contactAddress ?: contact?.numbers?.firstOrNull()?.address updateView() }