From 86c3af88921e2e78f1bab275469dfd5e8ecca1ac Mon Sep 17 00:00:00 2001 From: cketti Date: Mon, 16 Mar 2020 22:52:48 +0100 Subject: [PATCH] Use CircleImageView instead of ContactBadge view in message list --- .../fsck/k9/fragment/MessageListAdapter.kt | 22 ++++++------------- .../com/fsck/k9/fragment/MessageViewHolder.kt | 3 +-- .../src/main/res/layout/message_list_item.xml | 4 ++-- .../k9/fragment/MessageListAdapterTest.kt | 4 ++-- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/app/ui/src/main/java/com/fsck/k9/fragment/MessageListAdapter.kt b/app/ui/src/main/java/com/fsck/k9/fragment/MessageListAdapter.kt index 7b100e265..fac254934 100644 --- a/app/ui/src/main/java/com/fsck/k9/fragment/MessageListAdapter.kt +++ b/app/ui/src/main/java/com/fsck/k9/fragment/MessageListAdapter.kt @@ -17,6 +17,7 @@ import android.view.View import android.view.View.OnClickListener import android.view.ViewGroup import android.widget.BaseAdapter +import android.widget.ImageView import android.widget.TextView import androidx.core.graphics.drawable.DrawableCompat import androidx.core.view.isVisible @@ -24,7 +25,6 @@ import com.fsck.k9.FontSizes import com.fsck.k9.contacts.ContactPictureLoader import com.fsck.k9.controller.MessageReference import com.fsck.k9.mail.Address -import com.fsck.k9.ui.ContactBadge import com.fsck.k9.ui.R import com.fsck.k9.ui.messagelist.MessageListAppearance import com.fsck.k9.ui.messagelist.MessageListItem @@ -105,7 +105,7 @@ class MessageListAdapter internal constructor( val holder = MessageViewHolder(view) - holder.contactBadge.isVisible = appearance.showContactPicture + holder.contactPicture.isVisible = appearance.showContactPicture holder.chip.isVisible = appearance.showAccountChip appearance.fontSizes.setViewTextSize(holder.subject, subjectViewFontSize) @@ -148,8 +148,8 @@ class MessageListAdapter internal constructor( holder.flagged.isChecked = isStarred } holder.position = position - if (holder.contactBadge.isVisible) { - updateContactBadge(holder.contactBadge, counterPartyAddress) + if (holder.contactPicture.isVisible) { + setContactPicture(holder.contactPicture, counterPartyAddress) } setBackgroundColor(view, isSelected, isRead, isActive) updateWithThreadCount(holder, displayThreadCount) @@ -223,19 +223,11 @@ class MessageListAdapter internal constructor( } } - private fun updateContactBadge(contactBadge: ContactBadge, counterpartyAddress: Address?) { + private fun setContactPicture(contactPictureView: ImageView, counterpartyAddress: Address?) { if (counterpartyAddress != null) { - contactBadge.setContact(counterpartyAddress) - /* - * At least in Android 2.2 a different background + padding is used when no - * email address is available. ListView reuses the views but ContactBadge - * doesn't reset the padding, so we do it ourselves. - */ - contactBadge.setPadding(0, 0, 0, 0) - contactsPictureLoader.setContactPicture(contactBadge, counterpartyAddress) + contactsPictureLoader.setContactPicture(contactPictureView, counterpartyAddress) } else { - contactBadge.assignContactUri(null) - contactBadge.setImageResource(R.drawable.ic_contact_picture) + contactPictureView.setImageResource(R.drawable.ic_contact_picture) } } diff --git a/app/ui/src/main/java/com/fsck/k9/fragment/MessageViewHolder.kt b/app/ui/src/main/java/com/fsck/k9/fragment/MessageViewHolder.kt index f49ee9bc3..e3cf4fa81 100644 --- a/app/ui/src/main/java/com/fsck/k9/fragment/MessageViewHolder.kt +++ b/app/ui/src/main/java/com/fsck/k9/fragment/MessageViewHolder.kt @@ -4,13 +4,12 @@ import android.view.View import android.widget.CheckBox import android.widget.ImageView import android.widget.TextView -import com.fsck.k9.ui.ContactBadge import com.fsck.k9.ui.R class MessageViewHolder(view: View) { var position = -1 - val contactBadge: ContactBadge = view.findViewById(R.id.contact_badge) + val contactPicture: ImageView = view.findViewById(R.id.contact_picture) val subject: TextView = view.findViewById(R.id.subject) val preview: TextView = view.findViewById(R.id.preview) val date: TextView = view.findViewById(R.id.date) diff --git a/app/ui/src/main/res/layout/message_list_item.xml b/app/ui/src/main/res/layout/message_list_item.xml index 2f872e117..216837f7b 100644 --- a/app/ui/src/main/res/layout/message_list_item.xml +++ b/app/ui/src/main/res/layout/message_list_item.xml @@ -7,8 +7,8 @@ android:layout_gravity="center_vertical" > -