mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-04-12 09:31:04 +02:00
Use structured name when formatted name is empty
This commit is contained in:
parent
d95985841a
commit
8dc4687328
@ -367,7 +367,7 @@ class ThreadAdapter(
|
|||||||
thread_mesage_attachments_holder.addView(vCardView)
|
thread_mesage_attachments_holder.addView(vCardView)
|
||||||
|
|
||||||
parseVCardFromUri(context, uri) { vCards ->
|
parseVCardFromUri(context, uri) { vCards ->
|
||||||
val title = vCards.firstOrNull()?.formattedName?.value
|
val title = vCards.firstOrNull()?.parseNameFromVCard()
|
||||||
val imageIcon = if (title != null) {
|
val imageIcon = if (title != null) {
|
||||||
SimpleContactsHelper(context).getContactLetterIcon(title)
|
SimpleContactsHelper(context).getContactLetterIcon(title)
|
||||||
} else {
|
} else {
|
||||||
|
@ -13,3 +13,19 @@ fun parseVCardFromUri(context: Context, uri: Uri, callback: (vCards: List<VCard>
|
|||||||
callback(vCards)
|
callback(vCards)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun VCard?.parseNameFromVCard(): String? {
|
||||||
|
if (this == null) return null
|
||||||
|
var fullName = formattedName?.value
|
||||||
|
if (fullName.isNullOrEmpty()) {
|
||||||
|
val structured = structuredName
|
||||||
|
val given = structured?.given
|
||||||
|
val family = structured.family
|
||||||
|
fullName = if (family != null) {
|
||||||
|
given?.plus(" ")?.plus(family)
|
||||||
|
} else {
|
||||||
|
given
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fullName
|
||||||
|
}
|
||||||
|
@ -5,6 +5,7 @@ import com.simplemobiletools.commons.extensions.normalizePhoneNumber
|
|||||||
import com.simplemobiletools.smsmessenger.R
|
import com.simplemobiletools.smsmessenger.R
|
||||||
import com.simplemobiletools.smsmessenger.extensions.config
|
import com.simplemobiletools.smsmessenger.extensions.config
|
||||||
import com.simplemobiletools.smsmessenger.extensions.format
|
import com.simplemobiletools.smsmessenger.extensions.format
|
||||||
|
import com.simplemobiletools.smsmessenger.helpers.parseNameFromVCard
|
||||||
import ezvcard.VCard
|
import ezvcard.VCard
|
||||||
import ezvcard.property.*
|
import ezvcard.property.*
|
||||||
|
|
||||||
@ -15,27 +16,13 @@ private val displayedPropertyClasses = arrayOf(
|
|||||||
data class VCardWrapper(val vCard: VCard, val fullName: String?, val properties: List<VCardPropertyWrapper>, var expanded: Boolean = false) {
|
data class VCardWrapper(val vCard: VCard, val fullName: String?, val properties: List<VCardPropertyWrapper>, var expanded: Boolean = false) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private fun VCard.extractFullName(): String? {
|
|
||||||
var fullName = formattedName?.value
|
|
||||||
if (fullName.isNullOrEmpty()) {
|
|
||||||
val structured = structuredName
|
|
||||||
val given = structured?.given
|
|
||||||
val family = structured.family
|
|
||||||
fullName = if (family != null) {
|
|
||||||
given?.plus(" ")?.plus(family)
|
|
||||||
} else {
|
|
||||||
given
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return fullName
|
|
||||||
}
|
|
||||||
|
|
||||||
fun from(context: Context, vCard: VCard): VCardWrapper {
|
fun from(context: Context, vCard: VCard): VCardWrapper {
|
||||||
val properties = vCard.properties
|
val properties = vCard.properties
|
||||||
.filter { displayedPropertyClasses.contains(it::class.java) }
|
.filter { displayedPropertyClasses.contains(it::class.java) }
|
||||||
.map { VCardPropertyWrapper.from(context, it) }
|
.map { VCardPropertyWrapper.from(context, it) }
|
||||||
.distinctBy { it.value }
|
.distinctBy { it.value }
|
||||||
val fullName = vCard.extractFullName()
|
val fullName = vCard.parseNameFromVCard()
|
||||||
|
|
||||||
return VCardWrapper(vCard, fullName, properties)
|
return VCardWrapper(vCard, fullName, properties)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user