Skip to content

Commit 1991aed

Browse files
committed
fix #327, use VCard version 4 at exporting
1 parent a87fb2e commit 1991aed

File tree

1 file changed

+20
-13
lines changed
  • app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers

1 file changed

+20
-13
lines changed

app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/VcfExporter.kt

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package com.simplemobiletools.contacts.pro.helpers
22

33
import android.net.Uri
44
import android.provider.ContactsContract.CommonDataKinds
5-
import android.provider.ContactsContract.CommonDataKinds.*
5+
import android.provider.ContactsContract.CommonDataKinds.Event
6+
import android.provider.ContactsContract.CommonDataKinds.Im
7+
import android.provider.ContactsContract.CommonDataKinds.Phone
8+
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal
69
import android.provider.MediaStore
710
import com.simplemobiletools.commons.activities.BaseSimpleActivity
811
import com.simplemobiletools.commons.extensions.getDateTimeFromDateString
@@ -14,13 +17,9 @@ import com.simplemobiletools.contacts.pro.helpers.VcfExporter.ExportResult.EXPOR
1417
import com.simplemobiletools.contacts.pro.models.Contact
1518
import ezvcard.Ezvcard
1619
import ezvcard.VCard
20+
import ezvcard.VCardVersion
1721
import ezvcard.parameter.ImageType
1822
import ezvcard.property.*
19-
import ezvcard.property.Email
20-
import ezvcard.property.Organization
21-
import ezvcard.property.Photo
22-
import ezvcard.property.StructuredName
23-
import ezvcard.util.PartialDate
2423
import java.io.OutputStream
2524
import java.util.*
2625

@@ -32,7 +31,13 @@ class VcfExporter {
3231
private var contactsExported = 0
3332
private var contactsFailed = 0
3433

35-
fun exportContacts(activity: BaseSimpleActivity, outputStream: OutputStream?, contacts: ArrayList<Contact>, showExportingToast: Boolean, callback: (result: ExportResult) -> Unit) {
34+
fun exportContacts(
35+
activity: BaseSimpleActivity,
36+
outputStream: OutputStream?,
37+
contacts: ArrayList<Contact>,
38+
showExportingToast: Boolean,
39+
callback: (result: ExportResult) -> Unit
40+
) {
3641
try {
3742
if (outputStream == null) {
3843
callback(EXPORT_FAIL)
@@ -150,16 +155,18 @@ class VcfExporter {
150155
contactsExported++
151156
}
152157

153-
Ezvcard.write(cards).go(outputStream)
158+
Ezvcard.write(cards).version(VCardVersion.V4_0).go(outputStream)
154159
} catch (e: Exception) {
155160
activity.showErrorToast(e)
156161
}
157162

158-
callback(when {
159-
contactsExported == 0 -> EXPORT_FAIL
160-
contactsFailed > 0 -> ExportResult.EXPORT_PARTIAL
161-
else -> ExportResult.EXPORT_OK
162-
})
163+
callback(
164+
when {
165+
contactsExported == 0 -> EXPORT_FAIL
166+
contactsFailed > 0 -> ExportResult.EXPORT_PARTIAL
167+
else -> ExportResult.EXPORT_OK
168+
}
169+
)
163170
}
164171

165172
private fun getPhoneNumberTypeLabel(type: Int, label: String) = when (type) {

0 commit comments

Comments
 (0)