From 441a2ac3b159bb40f05d8ae0e4d4b50dd867d3d0 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 13 Aug 2018 12:26:52 +0200 Subject: [PATCH] handle exporting and importing contact nicknames --- .../simplemobiletools/contacts/helpers/VcfExporter.kt | 4 ++++ .../simplemobiletools/contacts/helpers/VcfImporter.kt | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfExporter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfExporter.kt index e53cecd4..5e6adf06 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfExporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfExporter.kt @@ -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}") } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt index 3831f26f..c50168cc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt @@ -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]