handle prefix/suffix/organization exporting/importing
This commit is contained in:
parent
fea917e41c
commit
d6f8bd43bf
|
@ -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"
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -31,7 +31,8 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||
private var curEvents = ArrayList<Event>()
|
||||
private var curAddresses = ArrayList<Address>()
|
||||
private var curGroups = ArrayList<Group>()
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue