handle exporting and importing contact nicknames

This commit is contained in:
tibbi 2018-08-13 12:26:52 +02:00
parent e0a38be028
commit 441a2ac3b1
2 changed files with 13 additions and 1 deletions

View File

@ -42,6 +42,10 @@ class VcfExporter {
out.writeLn(VERSION_2_1)
out.writeLn("$N${getNames(contact)}")
if (contact.nickname.isNotEmpty()) {
out.writeLn("$NICKNAME:${contact.nickname}")
}
contact.phoneNumbers.forEach {
out.writeLn("$TEL;${getPhoneNumberLabel(it.type)}:${it.value}")
}

View File

@ -93,7 +93,7 @@ class VcfImporter(val activity: SimpleActivity) {
when {
line.toUpperCase() == BEGIN_VCARD -> resetValues()
line.toUpperCase().startsWith(NOTE) -> addNotes(line.substring(NOTE.length))
line.toUpperCase().startsWith(NICKNAME) -> { }
line.toUpperCase().startsWith(NICKNAME) -> addNickname(line.substring(NICKNAME.length))
line.toUpperCase().startsWith(N) -> addNames(line.substring(N.length))
line.toUpperCase().startsWith(TEL) -> addPhoneNumber(line.substring(TEL.length))
line.toUpperCase().startsWith(EMAIL) -> addEmail(line.substring(EMAIL.length))
@ -148,6 +148,14 @@ class VcfImporter(val activity: SimpleActivity) {
}
}
private fun addNickname(nickname: String) {
curNickname = if (nickname.startsWith(";CHARSET", true)) {
nickname.substringAfter(":")
} else {
nickname.substring(1)
}
}
private fun addPhoneNumber(phoneNumber: String) {
val phoneParts = phoneNumber.trimStart(';').split(":")
var rawType = phoneParts[0]