mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-18 20:40:46 +01:00
fix some glitches at importing contacts from vcf, if Charset is mentioned
This commit is contained in:
parent
d40d6a083f
commit
19119b51c9
@ -45,7 +45,7 @@ ext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:4.3.29'
|
implementation 'com.simplemobiletools:commons:4.4.24'
|
||||||
implementation 'joda-time:joda-time:2.9.9'
|
implementation 'joda-time:joda-time:2.9.9'
|
||||||
implementation 'com.facebook.stetho:stetho:1.5.0'
|
implementation 'com.facebook.stetho:stetho:1.5.0'
|
||||||
|
|
||||||
|
@ -46,10 +46,10 @@ const val ANNIVERSARY = "ANNIVERSARY:"
|
|||||||
const val PHOTO = "PHOTO"
|
const val PHOTO = "PHOTO"
|
||||||
const val EMAIL = "EMAIL"
|
const val EMAIL = "EMAIL"
|
||||||
const val ADR = "ADR"
|
const val ADR = "ADR"
|
||||||
const val NOTE = "NOTE:"
|
const val NOTE = "NOTE"
|
||||||
const val ORG = "ORG:"
|
const val ORG = "ORG"
|
||||||
const val TITLE = "TITLE:"
|
const val TITLE = "TITLE"
|
||||||
const val URL = "URL:"
|
const val URL = "URL"
|
||||||
const val ENCODING = "ENCODING"
|
const val ENCODING = "ENCODING"
|
||||||
const val BASE64 = "BASE64"
|
const val BASE64 = "BASE64"
|
||||||
const val JPEG = "JPEG"
|
const val JPEG = "JPEG"
|
||||||
|
@ -65,16 +65,16 @@ class VcfExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (contact.notes.isNotEmpty()) {
|
if (contact.notes.isNotEmpty()) {
|
||||||
out.writeLn("$NOTE${contact.notes.replace("\n", "\\n")}")
|
out.writeLn("$NOTE:${contact.notes.replace("\n", "\\n")}")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!contact.organization.isEmpty()) {
|
if (!contact.organization.isEmpty()) {
|
||||||
out.writeLn("$ORG${contact.organization.company.replace("\n", "\\n")}")
|
out.writeLn("$ORG:${contact.organization.company.replace("\n", "\\n")}")
|
||||||
out.writeLn("$TITLE${contact.organization.jobPosition.replace("\n", "\\n")}")
|
out.writeLn("$TITLE:${contact.organization.jobPosition.replace("\n", "\\n")}")
|
||||||
}
|
}
|
||||||
|
|
||||||
contact.websites.forEach {
|
contact.websites.forEach {
|
||||||
out.writeLn("$URL$it")
|
out.writeLn("$URL:$it")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contact.thumbnailUri.isNotEmpty()) {
|
if (contact.thumbnailUri.isNotEmpty()) {
|
||||||
|
@ -59,7 +59,8 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||||||
|
|
||||||
inputStream.bufferedReader().use {
|
inputStream.bufferedReader().use {
|
||||||
while (true) {
|
while (true) {
|
||||||
val line = it.readLine() ?: break
|
var line = it.readLine() ?: break
|
||||||
|
line = line.trim()
|
||||||
if (line.trim().isEmpty()) {
|
if (line.trim().isEmpty()) {
|
||||||
if (isGettingPhoto) {
|
if (isGettingPhoto) {
|
||||||
savePhoto()
|
savePhoto()
|
||||||
@ -128,6 +129,7 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||||||
val nameParts = currentNameString.split(";")
|
val nameParts = currentNameString.split(";")
|
||||||
curSurname = if (currentNameIsANSI) QuotedPrintable.decode(nameParts[0]) else nameParts[0]
|
curSurname = if (currentNameIsANSI) QuotedPrintable.decode(nameParts[0]) else nameParts[0]
|
||||||
curFirstName = if (currentNameIsANSI) QuotedPrintable.decode(nameParts[1]) else nameParts[1]
|
curFirstName = if (currentNameIsANSI) QuotedPrintable.decode(nameParts[1]) else nameParts[1]
|
||||||
|
|
||||||
if (nameParts.size > 2) {
|
if (nameParts.size > 2) {
|
||||||
curMiddleName = if (currentNameIsANSI) QuotedPrintable.decode(nameParts[2]) else nameParts[2]
|
curMiddleName = if (currentNameIsANSI) QuotedPrintable.decode(nameParts[2]) else nameParts[2]
|
||||||
curPrefix = if (currentNameIsANSI) QuotedPrintable.decode(nameParts[3]) else nameParts[3]
|
curPrefix = if (currentNameIsANSI) QuotedPrintable.decode(nameParts[3]) else nameParts[3]
|
||||||
@ -244,26 +246,43 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun addNotes(notes: String) {
|
private fun addNotes(notes: String) {
|
||||||
currentNotesSB.append(notes)
|
if (notes.startsWith(";CHARSET", true)) {
|
||||||
|
currentNotesSB.append(notes.substringAfter(":"))
|
||||||
|
} else {
|
||||||
|
currentNotesSB.append(notes.substring(1))
|
||||||
|
}
|
||||||
isGettingNotes = true
|
isGettingNotes = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addCompany(company: String) {
|
private fun addCompany(company: String) {
|
||||||
curCompany = company
|
curCompany = if (company.startsWith(";")) {
|
||||||
|
company.substringAfter(":").trim(';')
|
||||||
|
} else {
|
||||||
|
company
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addJobPosition(jobPosition: String) {
|
private fun addJobPosition(jobPosition: String) {
|
||||||
curJobPosition = jobPosition
|
curJobPosition = if (jobPosition.startsWith(";")) {
|
||||||
|
jobPosition.substringAfter(":")
|
||||||
|
} else {
|
||||||
|
jobPosition
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addWebsite(website: String) {
|
private fun addWebsite(website: String) {
|
||||||
curWebsites.add(website)
|
if (website.startsWith(";")) {
|
||||||
|
curWebsites.add(website.substringAfter(":"))
|
||||||
|
} else {
|
||||||
|
curWebsites.add(website)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveContact(source: String) {
|
private fun saveContact(source: String) {
|
||||||
val organization = Organization(curCompany, curJobPosition)
|
val organization = Organization(curCompany, curJobPosition)
|
||||||
val contact = Contact(0, curPrefix, curFirstName, curMiddleName, curSurname, curSuffix, curPhotoUri, curPhoneNumbers, curEmails, curAddresses, curEvents,
|
val contact = Contact(0, curPrefix, curFirstName, curMiddleName, curSurname, curSuffix, curPhotoUri, curPhoneNumbers, curEmails, curAddresses, curEvents,
|
||||||
source, 0, 0, "", null, curNotes, curGroups, organization, curWebsites)
|
source, 0, 0, "", null, curNotes, curGroups, organization, curWebsites)
|
||||||
|
|
||||||
if (ContactsHelper(activity).insertContact(contact)) {
|
if (ContactsHelper(activity).insertContact(contact)) {
|
||||||
contactsImported++
|
contactsImported++
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user