Merge pull request #5003 from k9mail/show_recipient_name
Show recipient name for all messages in Sent, Drafts, and Outbox folders
This commit is contained in:
commit
e3178a5117
13 changed files with 66 additions and 65 deletions
|
@ -8,6 +8,8 @@ interface CoreResourceProvider {
|
|||
fun externalStorageProviderName(): String
|
||||
|
||||
fun contactDisplayNamePrefix(): String
|
||||
fun contactUnknownSender(): String
|
||||
fun contactUnknownRecipient(): String
|
||||
|
||||
fun messageHeaderFrom(): String
|
||||
fun messageHeaderTo(): String
|
||||
|
|
|
@ -46,19 +46,23 @@ public class MessageHelper {
|
|||
this.resourceProvider = resourceProvider;
|
||||
}
|
||||
|
||||
public CharSequence getDisplayName(Account account, Address[] fromAddrs, Address[] toAddrs) {
|
||||
final Contacts contactHelper = K9.isShowContactName() ? Contacts.getInstance(mContext) : null;
|
||||
|
||||
CharSequence displayName;
|
||||
if (fromAddrs.length > 0 && account.isAnIdentity(fromAddrs[0])) {
|
||||
CharSequence to = toFriendly(toAddrs, contactHelper);
|
||||
displayName = new SpannableStringBuilder(
|
||||
resourceProvider.contactDisplayNamePrefix()).append(to);
|
||||
} else {
|
||||
displayName = toFriendly(fromAddrs, contactHelper);
|
||||
public CharSequence getSenderDisplayName(Address address) {
|
||||
if (address == null) {
|
||||
return resourceProvider.contactUnknownSender();
|
||||
}
|
||||
|
||||
return displayName;
|
||||
Contacts contactHelper = K9.isShowContactName() ? Contacts.getInstance(mContext) : null;
|
||||
return toFriendly(address, contactHelper);
|
||||
}
|
||||
|
||||
public CharSequence getRecipientDisplayNames(Address[] addresses) {
|
||||
if (addresses == null || addresses.length == 0) {
|
||||
return resourceProvider.contactUnknownRecipient();
|
||||
}
|
||||
|
||||
Contacts contactHelper = K9.isShowContactName() ? Contacts.getInstance(mContext) : null;
|
||||
CharSequence recipients = toFriendly(addresses, contactHelper);
|
||||
return new SpannableStringBuilder(resourceProvider.contactDisplayNamePrefix()).append(recipients);
|
||||
}
|
||||
|
||||
public boolean toMe(Account account, Address[] toAddrs) {
|
||||
|
|
|
@ -14,6 +14,8 @@ class TestCoreResourceProvider : CoreResourceProvider {
|
|||
}
|
||||
|
||||
override fun contactDisplayNamePrefix() = "To:"
|
||||
override fun contactUnknownSender() = "<Unknown Sender>"
|
||||
override fun contactUnknownRecipient() = "<Unknown Recipient>"
|
||||
|
||||
override fun messageHeaderFrom() = "From:"
|
||||
override fun messageHeaderTo() = "To:"
|
||||
|
|
|
@ -15,6 +15,8 @@ class K9CoreResourceProvider(private val context: Context) : CoreResourceProvide
|
|||
context.getString(R.string.local_storage_provider_external_label)
|
||||
|
||||
override fun contactDisplayNamePrefix(): String = context.getString(R.string.message_to_label)
|
||||
override fun contactUnknownSender(): String = context.getString(R.string.unknown_sender)
|
||||
override fun contactUnknownRecipient(): String = context.getString(R.string.unknown_recipient)
|
||||
|
||||
override fun messageHeaderFrom(): String = context.getString(R.string.message_compose_quote_header_from)
|
||||
override fun messageHeaderTo(): String = context.getString(R.string.message_compose_quote_header_to)
|
||||
|
|
|
@ -15,6 +15,8 @@ class K9CoreResourceProvider(private val context: Context) : CoreResourceProvide
|
|||
context.getString(R.string.local_storage_provider_external_label)
|
||||
|
||||
override fun contactDisplayNamePrefix(): String = context.getString(R.string.message_to_label)
|
||||
override fun contactUnknownSender(): String = context.getString(R.string.unknown_sender)
|
||||
override fun contactUnknownRecipient(): String = context.getString(R.string.unknown_recipient)
|
||||
|
||||
override fun messageHeaderFrom(): String = context.getString(R.string.message_compose_quote_header_from)
|
||||
override fun messageHeaderTo(): String = context.getString(R.string.message_compose_quote_header_to)
|
||||
|
|
|
@ -165,7 +165,7 @@ class MessageListAdapter internal constructor(
|
|||
}
|
||||
holder.position = position
|
||||
if (appearance.showContactPicture && holder.contactPicture.isVisible) {
|
||||
setContactPicture(holder.contactPicture, counterPartyAddress)
|
||||
setContactPicture(holder.contactPicture, displayAddress)
|
||||
}
|
||||
setBackgroundColor(view, isSelected, isRead, isActive)
|
||||
updateWithThreadCount(holder, displayThreadCount)
|
||||
|
@ -239,9 +239,9 @@ class MessageListAdapter internal constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun setContactPicture(contactPictureView: ImageView, counterpartyAddress: Address?) {
|
||||
if (counterpartyAddress != null) {
|
||||
contactsPictureLoader.setContactPicture(contactPictureView, counterpartyAddress)
|
||||
private fun setContactPicture(contactPictureView: ImageView, displayAddress: Address?) {
|
||||
if (displayAddress != null) {
|
||||
contactsPictureLoader.setContactPicture(contactPictureView, displayAddress)
|
||||
} else {
|
||||
contactPictureView.setImageResource(R.drawable.ic_contact_picture)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.fsck.k9.ui.helper
|
||||
|
||||
import com.fsck.k9.Account
|
||||
|
||||
object DisplayAddressHelper {
|
||||
fun shouldShowRecipients(account: Account, folderId: Long): Boolean {
|
||||
return when (folderId) {
|
||||
account.sentFolderId -> true
|
||||
account.draftsFolderId -> true
|
||||
account.outboxFolderId -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import com.fsck.k9.helper.MessageHelper
|
|||
import com.fsck.k9.helper.map
|
||||
import com.fsck.k9.mail.Address
|
||||
import com.fsck.k9.mailstore.DatabasePreviewType
|
||||
import com.fsck.k9.ui.helper.DisplayAddressHelper
|
||||
|
||||
class MessageListExtractor(
|
||||
private val preferences: Preferences,
|
||||
|
@ -30,11 +31,8 @@ class MessageListExtractor(
|
|||
val fromAddresses = Address.unpack(fromList)
|
||||
val toAddresses = Address.unpack(toList)
|
||||
val ccAddresses = Address.unpack(ccList)
|
||||
val fromMe = messageHelper.toMe(account, fromAddresses)
|
||||
val toMe = messageHelper.toMe(account, toAddresses)
|
||||
val ccMe = messageHelper.toMe(account, ccAddresses)
|
||||
val counterPartyAddress = getCounterPartyAddress(fromMe, toAddresses, ccAddresses, fromAddresses)
|
||||
val displayName = messageHelper.getDisplayName(account, fromAddresses, toAddresses)
|
||||
val messageDate = cursor.getLong(MLFProjectionInfo.DATE_COLUMN)
|
||||
val threadCount = if (threadCountIncluded) cursor.getInt(MLFProjectionInfo.THREAD_COUNT_COLUMN) else 0
|
||||
val subject = cursor.getString(MLFProjectionInfo.SUBJECT_COLUMN)
|
||||
|
@ -51,8 +49,14 @@ class MessageListExtractor(
|
|||
val folderId = cursor.getLong(MLFProjectionInfo.FOLDER_ID_COLUMN)
|
||||
val messageUid = cursor.getString(MLFProjectionInfo.UID_COLUMN)
|
||||
val databaseId = cursor.getLong(MLFProjectionInfo.ID_COLUMN)
|
||||
val senderAddress = fromAddresses.getOrNull(0)?.address
|
||||
val threadRoot = cursor.getLong(MLFProjectionInfo.THREAD_ROOT_COLUMN)
|
||||
val showRecipients = DisplayAddressHelper.shouldShowRecipients(account, folderId)
|
||||
val displayAddress = if (showRecipients) toAddresses.firstOrNull() else fromAddresses.firstOrNull()
|
||||
val displayName = if (showRecipients) {
|
||||
messageHelper.getRecipientDisplayNames(toAddresses)
|
||||
} else {
|
||||
messageHelper.getSenderDisplayName(displayAddress)
|
||||
}
|
||||
|
||||
return MessageListItem(
|
||||
position,
|
||||
|
@ -61,8 +65,7 @@ class MessageListExtractor(
|
|||
threadCount,
|
||||
messageDate,
|
||||
displayName,
|
||||
counterPartyAddress,
|
||||
fromMe,
|
||||
displayAddress,
|
||||
toMe,
|
||||
ccMe,
|
||||
previewText,
|
||||
|
@ -76,25 +79,10 @@ class MessageListExtractor(
|
|||
folderId,
|
||||
messageUid,
|
||||
databaseId,
|
||||
senderAddress,
|
||||
threadRoot
|
||||
)
|
||||
}
|
||||
|
||||
private fun getCounterPartyAddress(
|
||||
fromMe: Boolean,
|
||||
toAddresses: Array<Address>,
|
||||
ccAddresses: Array<Address>,
|
||||
fromAddresses: Array<Address>
|
||||
): Address? {
|
||||
return when {
|
||||
fromMe && toAddresses.isNotEmpty() -> toAddresses[0]
|
||||
fromMe && ccAddresses.isNotEmpty() -> ccAddresses[0]
|
||||
fromAddresses.isNotEmpty() -> fromAddresses[0]
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPreviewText(previewType: DatabasePreviewType?, cursor: Cursor): String {
|
||||
return if (previewType == DatabasePreviewType.TEXT) {
|
||||
cursor.getString(MLFProjectionInfo.PREVIEW_COLUMN) ?: ""
|
||||
|
|
|
@ -10,8 +10,7 @@ data class MessageListItem(
|
|||
val threadCount: Int,
|
||||
val messageDate: Long,
|
||||
val displayName: CharSequence,
|
||||
val counterPartyAddress: Address?,
|
||||
val fromMe: Boolean,
|
||||
val displayAddress: Address?,
|
||||
val toMe: Boolean,
|
||||
val ccMe: Boolean,
|
||||
val previewText: String,
|
||||
|
@ -25,6 +24,5 @@ data class MessageListItem(
|
|||
val folderId: Long,
|
||||
val messageUid: String,
|
||||
val databaseId: Long,
|
||||
val senderAddress: String?,
|
||||
val threadRoot: Long
|
||||
)
|
||||
|
|
|
@ -268,28 +268,18 @@ public class MessageHeader extends LinearLayout implements OnClickListener, OnLo
|
|||
}
|
||||
|
||||
public void populate(final Message message, final Account account) {
|
||||
Address fromAddress = null;
|
||||
Address[] fromAddresses = message.getFrom();
|
||||
if (fromAddresses.length > 0) {
|
||||
fromAddress = fromAddresses[0];
|
||||
}
|
||||
|
||||
final Contacts contacts = K9.isShowContactName() ? mContacts : null;
|
||||
final CharSequence from = MessageHelper.toFriendly(message.getFrom(), contacts);
|
||||
final CharSequence from = mMessageHelper.getSenderDisplayName(fromAddress);
|
||||
final CharSequence to = MessageHelper.toFriendly(message.getRecipients(Message.RecipientType.TO), contacts);
|
||||
final CharSequence cc = MessageHelper.toFriendly(message.getRecipients(Message.RecipientType.CC), contacts);
|
||||
final CharSequence bcc = MessageHelper.toFriendly(message.getRecipients(Message.RecipientType.BCC), contacts);
|
||||
|
||||
Address[] fromAddrs = message.getFrom();
|
||||
Address[] toAddrs = message.getRecipients(Message.RecipientType.TO);
|
||||
Address[] ccAddrs = message.getRecipients(Message.RecipientType.CC);
|
||||
boolean fromMe = mMessageHelper.toMe(account, fromAddrs);
|
||||
|
||||
Address counterpartyAddress = null;
|
||||
if (fromMe) {
|
||||
if (toAddrs.length > 0) {
|
||||
counterpartyAddress = toAddrs[0];
|
||||
} else if (ccAddrs.length > 0) {
|
||||
counterpartyAddress = ccAddrs[0];
|
||||
}
|
||||
} else if (fromAddrs.length > 0) {
|
||||
counterpartyAddress = fromAddrs[0];
|
||||
}
|
||||
|
||||
mMessage = message;
|
||||
mAccount = account;
|
||||
|
||||
|
@ -318,9 +308,9 @@ public class MessageHeader extends LinearLayout implements OnClickListener, OnLo
|
|||
mDateView.setText(dateTime);
|
||||
|
||||
if (K9.isShowContactPicture()) {
|
||||
if (counterpartyAddress != null) {
|
||||
mContactBadge.setContact(counterpartyAddress);
|
||||
mContactsPictureLoader.setContactPicture(mContactBadge, counterpartyAddress);
|
||||
if (fromAddress != null) {
|
||||
mContactBadge.setContact(fromAddress);
|
||||
mContactsPictureLoader.setContactPicture(mContactBadge, fromAddress);
|
||||
} else {
|
||||
mContactBadge.setImageResource(R.drawable.ic_contact_picture);
|
||||
}
|
||||
|
|
|
@ -1083,6 +1083,7 @@ Please submit bug reports, contribute new features and ask questions at
|
|||
<string name="recipient_to">To</string>
|
||||
<string name="recipient_from">From</string>
|
||||
<string name="unknown_recipient"><![CDATA[<Unknown Recipient>]]></string>
|
||||
<string name="unknown_sender"><![CDATA[<Unknown Sender>]]></string>
|
||||
<string name="address_type_home">Home</string>
|
||||
<string name="address_type_work">Work</string>
|
||||
<string name="address_type_other">Other</string>
|
||||
|
|
|
@ -10,6 +10,8 @@ class TestCoreResourceProvider : CoreResourceProvider {
|
|||
override fun externalStorageProviderName() = throw UnsupportedOperationException("not implemented")
|
||||
|
||||
override fun contactDisplayNamePrefix() = throw UnsupportedOperationException("not implemented")
|
||||
override fun contactUnknownSender() = throw UnsupportedOperationException("not implemented")
|
||||
override fun contactUnknownRecipient() = throw UnsupportedOperationException("not implemented")
|
||||
|
||||
override fun messageHeaderFrom() = throw UnsupportedOperationException("not implemented")
|
||||
override fun messageHeaderTo() = throw UnsupportedOperationException("not implemented")
|
||||
|
|
|
@ -475,8 +475,7 @@ class MessageListAdapterTest : RobolectricTest() {
|
|||
threadCount: Int = 0,
|
||||
messageDate: Long = 0L,
|
||||
displayName: CharSequence = "irrelevant",
|
||||
counterPartyAddress: Address? = Address.parse("irrelevant@domain.example").first(),
|
||||
fromMe: Boolean = false,
|
||||
displayAddress: Address? = Address.parse("irrelevant@domain.example").first(),
|
||||
toMe: Boolean = false,
|
||||
ccMe: Boolean = false,
|
||||
previewText: String = "irrelevant",
|
||||
|
@ -490,7 +489,6 @@ class MessageListAdapterTest : RobolectricTest() {
|
|||
folderId: Long = 0L,
|
||||
messageUid: String = "irrelevant",
|
||||
databaseId: Long = 0L,
|
||||
senderAddress: String? = null,
|
||||
threadRoot: Long = 0L
|
||||
): MessageListItem {
|
||||
return MessageListItem(
|
||||
|
@ -500,8 +498,7 @@ class MessageListAdapterTest : RobolectricTest() {
|
|||
threadCount,
|
||||
messageDate,
|
||||
displayName,
|
||||
counterPartyAddress,
|
||||
fromMe,
|
||||
displayAddress,
|
||||
toMe,
|
||||
ccMe,
|
||||
previewText,
|
||||
|
@ -515,7 +512,6 @@ class MessageListAdapterTest : RobolectricTest() {
|
|||
folderId,
|
||||
messageUid,
|
||||
databaseId,
|
||||
senderAddress,
|
||||
threadRoot
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue