Skip to content

Commit af3a86a

Browse files
committed
fix: add middle name to first name field when importing (see #487)
1 parent 72e2d39 commit af3a86a

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

app/src/main/java/com/bnyro/contacts/util/VcardHelper.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ object VcardHelper {
103103
}
104104
ContactData(
105105
displayName = it.formattedName?.value,
106-
firstName = it.structuredName?.given,
106+
// we currently don't support prefixes, suffixes and middle names
107+
// so we merge all of them into the first name to not lose that information
108+
firstName = it.structuredName?.allExceptFamilyName(),
107109
surName = it.structuredName?.family,
108110
nickName = it.nickname?.values?.firstOrNull(),
109111
organization = it.organization?.values?.firstOrNull(),
@@ -165,4 +167,10 @@ object VcardHelper {
165167
)
166168
}
167169
}
170+
171+
fun StructuredName.allExceptFamilyName(): String {
172+
return (prefixes + listOf(given) + additionalNames + suffixes)
173+
.filterNotNull()
174+
.joinToString(" ")
175+
}
168176
}

0 commit comments

Comments
 (0)