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 6a7555f6..38f51d63 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt @@ -43,6 +43,8 @@ const val PHOTO = "PHOTO" const val EMAIL = "EMAIL" const val ADR = "ADR" const val NOTE = "NOTE:" +const val ORG = "ORG:" +const val TITLE = "TITLE:" 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 ec7e443e..80e503eb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfExporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfExporter.kt @@ -66,6 +66,11 @@ class VcfExporter { out.writeLn("$NOTE${contact.notes.replace("\n", "\\n")}") } + if (!contact.organization.isEmpty()) { + out.writeLn("$ORG${contact.organization.company.replace("\n", "\\n")}") + out.writeLn("$TITLE${contact.organization.jobPosition.replace("\n", "\\n")}") + } + if (contact.thumbnailUri.isNotEmpty()) { val bitmap = MediaStore.Images.Media.getBitmap(activity.contentResolver, Uri.parse(contact.thumbnailUri)) addBitmap(bitmap, out) @@ -116,17 +121,23 @@ class VcfExporter { var firstName = contact.firstName var surName = contact.surname var middleName = contact.middleName + var prefix = contact.prefix + var suffix = contact.suffix if (QuotedPrintable.urlEncode(firstName) != firstName || QuotedPrintable.urlEncode(surName) != surName - || QuotedPrintable.urlEncode(middleName) != middleName) { + || QuotedPrintable.urlEncode(middleName) != middleName + || QuotedPrintable.urlEncode(prefix) != prefix + || QuotedPrintable.urlEncode(suffix) != suffix) { firstName = QuotedPrintable.encode(firstName) surName = QuotedPrintable.encode(surName) middleName = QuotedPrintable.encode(middleName) + prefix = QuotedPrintable.encode(prefix) + suffix = QuotedPrintable.encode(suffix) result += ";CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE" } - return "$result:$surName;$firstName;$middleName;;" + return "$result:$surName;$firstName;$middleName;$prefix;$suffix" } private fun getPhoneNumberLabel(type: Int) = when (type) { 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 da2f57a3..ed998f9c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt @@ -31,7 +31,8 @@ class VcfImporter(val activity: SimpleActivity) { private var curEvents = ArrayList() private var curAddresses = ArrayList
() private var curGroups = ArrayList() - private var curOrganization = Organization("", "") + private var curCompany = "" + private var curJobPosition = "" private var isGettingPhoto = false private var currentPhotoString = StringBuilder() @@ -87,6 +88,8 @@ class VcfImporter(val activity: SimpleActivity) { line.toUpperCase().startsWith(BDAY) -> addBirthday(line.substring(BDAY.length)) line.toUpperCase().startsWith(ANNIVERSARY) -> addAnniversary(line.substring(ANNIVERSARY.length)) 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() == END_VCARD -> saveContact(targetContactSource) isGettingPhoto -> currentPhotoString.append(line.trim()) } @@ -121,6 +124,8 @@ class VcfImporter(val activity: SimpleActivity) { curFirstName = if (currentNameIsANSI) QuotedPrintable.decode(nameParts[1]) else nameParts[1] if (nameParts.size > 2) { curMiddleName = if (currentNameIsANSI) QuotedPrintable.decode(nameParts[2]) else nameParts[2] + curPrefix = if (currentNameIsANSI) QuotedPrintable.decode(nameParts[3]) else nameParts[3] + curSuffix = if (currentNameIsANSI) QuotedPrintable.decode(nameParts[4]) else nameParts[4] } } @@ -237,9 +242,18 @@ class VcfImporter(val activity: SimpleActivity) { isGettingNotes = true } + private fun addCompany(company: String) { + curCompany = company + } + + private fun addJobPosition(jobPosition: String) { + curJobPosition = jobPosition + } + private fun saveContact(source: String) { + val organization = Organization(curCompany, curJobPosition) val contact = Contact(0, curPrefix, curFirstName, curMiddleName, curSurname, curSuffix, curPhotoUri, curPhoneNumbers, curEmails, curAddresses, curEvents, - source, 0, 0, "", null, curNotes, curGroups, curOrganization) + source, 0, 0, "", null, curNotes, curGroups, organization) if (ContactsHelper(activity).insertContact(contact)) { contactsImported++ } @@ -258,7 +272,8 @@ class VcfImporter(val activity: SimpleActivity) { curEvents = ArrayList() curAddresses = ArrayList() curGroups = ArrayList() - curOrganization = Organization("", "") + curCompany = "" + curJobPosition = "" isGettingPhoto = false currentPhotoString = StringBuilder()