From b7d7eb5e8a9baa13663d7bd934f064d44bbd3e8c Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 13 Apr 2018 14:53:19 +0200 Subject: [PATCH] handle contact website import/export --- .../com/simplemobiletools/contacts/helpers/Constants.kt | 1 + .../com/simplemobiletools/contacts/helpers/VcfExporter.kt | 4 ++++ .../com/simplemobiletools/contacts/helpers/VcfImporter.kt | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt index 03e65cbe..670aedad 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt @@ -46,6 +46,7 @@ const val ADR = "ADR" const val NOTE = "NOTE:" const val ORG = "ORG:" const val TITLE = "TITLE:" +const val URL = "URL:" const val ENCODING = "ENCODING" const val BASE64 = "BASE64" const val JPEG = "JPEG" 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 80e503eb..bd573b75 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfExporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfExporter.kt @@ -71,6 +71,10 @@ class VcfExporter { out.writeLn("$TITLE${contact.organization.jobPosition.replace("\n", "\\n")}") } + contact.websites.forEach { + out.writeLn("$URL$it") + } + if (contact.thumbnailUri.isNotEmpty()) { val bitmap = MediaStore.Images.Media.getBitmap(activity.contentResolver, Uri.parse(contact.thumbnailUri)) addBitmap(bitmap, out) 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 c1938d19..f1c45102 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt @@ -91,6 +91,7 @@ class VcfImporter(val activity: SimpleActivity) { line.toUpperCase().startsWith(PHOTO) -> addPhoto(line.substring(PHOTO.length)) line.toUpperCase().startsWith(ORG) -> addCompany(line.substring(ORG.length)) line.toUpperCase().startsWith(TITLE) -> addJobPosition(line.substring(TITLE.length)) + line.toUpperCase().startsWith(URL) -> addWebsite(line.substring(URL.length)) line.toUpperCase() == END_VCARD -> saveContact(targetContactSource) isGettingPhoto -> currentPhotoString.append(line.trim()) } @@ -251,6 +252,10 @@ class VcfImporter(val activity: SimpleActivity) { curJobPosition = jobPosition } + private fun addWebsite(website: String) { + curWebsites.add(website) + } + private fun saveContact(source: String) { val organization = Organization(curCompany, curJobPosition) val contact = Contact(0, curPrefix, curFirstName, curMiddleName, curSurname, curSuffix, curPhotoUri, curPhoneNumbers, curEmails, curAddresses, curEvents,