From 926ba81bcdfcb374f8ae72864c8e6d08b80cb526 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 22 Feb 2018 16:04:31 +0100 Subject: [PATCH] add importing note from vcf file --- .../contacts/helpers/Constants.kt | 1 + .../contacts/helpers/VcfImporter.kt | 19 +++++++++++++++++++ 2 files changed, 20 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 695fd967..b59e18ca 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt @@ -31,6 +31,7 @@ const val ANNIVERSARY = "ANNIVERSARY:" const val PHOTO = "PHOTO" const val EMAIL = "EMAIL" const val ADR = "ADR" +const val NOTE = "NOTE:" const val ENCODING = "ENCODING" const val BASE64 = "BASE64" const val JPEG = "JPEG" 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 3259600a..e644d5eb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt @@ -37,6 +37,9 @@ class VcfImporter(val activity: SimpleActivity) { private var currentNameIsANSI = false private var currentNameString = StringBuilder() + private var isGettingNotes = false + private var currentNotesSB = StringBuilder() + private var contactsImported = 0 private var contactsFailed = 0 @@ -61,10 +64,18 @@ class VcfImporter(val activity: SimpleActivity) { currentNameString.append(line.trimStart('\t')) isGettingName = false parseNames() + } else if (isGettingNotes) { + if (line.startsWith(' ')) { + currentNotesSB.append(line.substring(1)) + } else { + curNotes = currentNotesSB.toString().replace("\\n", "\n").replace("\\,", ",") + isGettingNotes = false + } } when { line.toUpperCase() == BEGIN_VCARD -> resetValues() + line.toUpperCase().startsWith(NOTE) -> addNotes(line.substring(NOTE.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)) @@ -217,6 +228,11 @@ class VcfImporter(val activity: SimpleActivity) { curPhotoUri = activity.getCachePhotoUri(file).toString() } + private fun addNotes(notes: String) { + currentNotesSB.append(notes) + isGettingNotes = true + } + private fun saveContact(source: String) { val contact = Contact(0, curFirstName, curMiddleName, curSurname, curPhotoUri, curPhoneNumbers, curEmails, curAddresses, curEvents, source, 0, 0, "", null, curNotes) if (ContactsHelper(activity).insertContact(contact)) { @@ -242,5 +258,8 @@ class VcfImporter(val activity: SimpleActivity) { isGettingName = false currentNameIsANSI = false currentNameString = StringBuilder() + + isGettingNotes = false + currentNotesSB = StringBuilder() } }