Always use extension function to create EmailAddress
instance
This commit is contained in:
parent
391bcc7f0f
commit
fa487b2016
8 changed files with 16 additions and 15 deletions
|
@ -1,7 +1,7 @@
|
|||
package com.fsck.k9.helper
|
||||
|
||||
import app.k9mail.core.android.common.contact.ContactRepository
|
||||
import app.k9mail.core.common.mail.EmailAddress
|
||||
import app.k9mail.core.common.mail.toEmailAddress
|
||||
|
||||
interface ContactNameProvider {
|
||||
fun getNameForAddress(address: String): String?
|
||||
|
@ -11,6 +11,6 @@ class RealContactNameProvider(
|
|||
private val contactRepository: ContactRepository,
|
||||
) : ContactNameProvider {
|
||||
override fun getNameForAddress(address: String): String? {
|
||||
return contactRepository.getContactFor(EmailAddress(address))?.name
|
||||
return contactRepository.getContactFor(address.toEmailAddress())?.name
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import android.text.SpannableStringBuilder
|
|||
import android.text.TextUtils
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import app.k9mail.core.android.common.contact.ContactRepository
|
||||
import app.k9mail.core.common.mail.EmailAddress
|
||||
import app.k9mail.core.common.mail.toEmailAddress
|
||||
import com.fsck.k9.CoreResourceProvider
|
||||
import com.fsck.k9.K9.contactNameColor
|
||||
import com.fsck.k9.K9.isChangeContactNameColor
|
||||
|
@ -101,7 +101,7 @@ class MessageHelper(
|
|||
if (!showCorrespondentNames) {
|
||||
return address.address
|
||||
} else if (contactRepository != null) {
|
||||
val name = contactRepository.getContactFor(EmailAddress(address.address))?.name
|
||||
val name = contactRepository.getContactFor(address.address.toEmailAddress())?.name
|
||||
if (name != null) {
|
||||
return if (changeContactNameColor) {
|
||||
val coloredName = SpannableString(name)
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.text.SpannableString
|
|||
import app.k9mail.core.android.common.contact.Contact
|
||||
import app.k9mail.core.android.common.contact.ContactRepository
|
||||
import app.k9mail.core.common.mail.EmailAddress
|
||||
import app.k9mail.core.common.mail.toEmailAddress
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isInstanceOf
|
||||
|
@ -142,6 +143,6 @@ class MessageHelperTest : RobolectricTest() {
|
|||
}
|
||||
|
||||
private companion object {
|
||||
val EMAIL_ADDRESS = EmailAddress("test@testor.com")
|
||||
val EMAIL_ADDRESS = "test@testor.com".toEmailAddress()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.fsck.k9.notification
|
||||
|
||||
import app.k9mail.core.android.common.contact.ContactRepository
|
||||
import app.k9mail.core.common.mail.EmailAddress
|
||||
import app.k9mail.core.common.mail.toEmailAddress
|
||||
import com.fsck.k9.Account
|
||||
import com.fsck.k9.K9
|
||||
import com.fsck.k9.mail.Flag
|
||||
|
@ -88,7 +88,7 @@ class K9NotificationStrategy(
|
|||
}
|
||||
|
||||
if (account.isNotifyContactsMailOnly &&
|
||||
!contactRepository.hasAnyContactFor(message.from.asList().mapNotNull { EmailAddress(it.address) })
|
||||
!contactRepository.hasAnyContactFor(message.from.asList().mapNotNull { it.address.toEmailAddress() })
|
||||
) {
|
||||
Timber.v("No notification: Message is not from a known contact")
|
||||
return false
|
||||
|
|
|
@ -4,7 +4,7 @@ import android.content.ContentResolver
|
|||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import app.k9mail.core.android.common.contact.ContactRepository
|
||||
import app.k9mail.core.common.mail.EmailAddress
|
||||
import app.k9mail.core.common.mail.toEmailAddress
|
||||
import timber.log.Timber
|
||||
|
||||
internal class ContactPhotoLoader(
|
||||
|
@ -12,7 +12,7 @@ internal class ContactPhotoLoader(
|
|||
private val contactRepository: ContactRepository,
|
||||
) {
|
||||
fun loadContactPhoto(emailAddress: String): Bitmap? {
|
||||
val photoUri = contactRepository.getContactFor(EmailAddress(emailAddress))?.photoUri ?: return null
|
||||
val photoUri = contactRepository.getContactFor(emailAddress.toEmailAddress())?.photoUri ?: return null
|
||||
return try {
|
||||
contentResolver.openInputStream(photoUri).use { inputStream ->
|
||||
BitmapFactory.decodeStream(inputStream)
|
||||
|
|
|
@ -7,7 +7,7 @@ import androidx.lifecycle.viewModelScope
|
|||
import app.k9mail.core.android.common.contact.CachingRepository
|
||||
import app.k9mail.core.android.common.contact.ContactPermissionResolver
|
||||
import app.k9mail.core.android.common.contact.ContactRepository
|
||||
import app.k9mail.core.common.mail.EmailAddress
|
||||
import app.k9mail.core.common.mail.toEmailAddress
|
||||
import com.fsck.k9.Account
|
||||
import com.fsck.k9.controller.MessageReference
|
||||
import com.fsck.k9.helper.ClipboardManager
|
||||
|
@ -130,7 +130,7 @@ internal class MessageDetailsViewModel(
|
|||
Participant(
|
||||
displayName = displayName,
|
||||
emailAddress = emailAddress,
|
||||
contactLookupUri = contactRepository.getContactFor(EmailAddress(emailAddress))?.uri,
|
||||
contactLookupUri = contactRepository.getContactFor(emailAddress.toEmailAddress())?.uri,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import android.widget.LinearLayout
|
|||
import android.widget.ProgressBar
|
||||
import android.widget.TextView
|
||||
import app.k9mail.core.android.common.contact.ContactRepository
|
||||
import app.k9mail.core.common.mail.EmailAddress
|
||||
import app.k9mail.core.common.mail.toEmailAddress
|
||||
import com.fsck.k9.Account
|
||||
import com.fsck.k9.Account.ShowPictures
|
||||
import com.fsck.k9.mail.Message
|
||||
|
@ -262,7 +262,7 @@ class MessageTopView(
|
|||
return false
|
||||
}
|
||||
val senderEmailAddress = getSenderEmailAddress(message) ?: return false
|
||||
return contactRepository.hasContactFor(EmailAddress(senderEmailAddress))
|
||||
return contactRepository.hasContactFor(senderEmailAddress.toEmailAddress())
|
||||
}
|
||||
|
||||
private fun getSenderEmailAddress(message: Message): String? {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package app.k9mail.core.android.common.contact
|
||||
|
||||
import android.net.Uri
|
||||
import app.k9mail.core.common.mail.EmailAddress
|
||||
import app.k9mail.core.common.mail.toEmailAddress
|
||||
|
||||
const val CONTACT_ID = 123L
|
||||
const val CONTACT_NAME = "user name"
|
||||
const val CONTACT_LOOKUP_KEY = "0r1-4F314D4F2F294F29"
|
||||
val CONTACT_EMAIL_ADDRESS = EmailAddress("user@example.com")
|
||||
val CONTACT_EMAIL_ADDRESS = "user@example.com".toEmailAddress()
|
||||
val CONTACT_URI: Uri = Uri.parse("content://com.android.contacts/contacts/lookup/$CONTACT_LOOKUP_KEY/$CONTACT_ID")
|
||||
val CONTACT_PHOTO_URI: Uri = Uri.parse("content://com.android.contacts/display_photo/$CONTACT_ID")
|
||||
|
||||
|
|
Loading…
Reference in a new issue