Construct name from structured name

This commit is contained in:
Naveen 2022-08-29 04:16:45 +05:30
parent 00d69ad40e
commit 4f809426bb
2 changed files with 16 additions and 1 deletions

View File

@ -55,7 +55,7 @@ class VCardViewerAdapter(
} }
private fun setupVCardView(view: View, item: VCardWrapper) { private fun setupVCardView(view: View, item: VCardWrapper) {
val name = item.vCard.formattedName?.value val name = item.getFullName()
view.apply { view.apply {
item_contact_name.apply { item_contact_name.apply {
text = name text = name

View File

@ -14,6 +14,21 @@ private val displayedPropertyClasses = arrayOf(
data class VCardWrapper(val vCard: VCard, var expanded: Boolean = false) { data class VCardWrapper(val vCard: VCard, var expanded: Boolean = false) {
fun getFullName(): String? {
var formattedName = vCard.formattedName?.value
if (formattedName.isNullOrEmpty()) {
val structured = vCard.structuredName
val given = structured?.given
val family = structured.family
formattedName = if (family != null) {
given?.plus(" ")?.plus(family)
} else {
given
}
}
return formattedName
}
fun getVCardProperties(context: Context): List<VCardPropertyWrapper> { fun getVCardProperties(context: Context): List<VCardPropertyWrapper> {
return vCard.properties return vCard.properties
.filter { displayedPropertyClasses.contains(it::class.java) } .filter { displayedPropertyClasses.contains(it::class.java) }