add IM exporting/importing

This commit is contained in:
tibbi 2018-09-04 17:07:01 +02:00
parent 36fbc9f0c6
commit 60bcbcb4a6
3 changed files with 42 additions and 0 deletions

View file

@ -65,6 +65,11 @@ const val HOME_FAX = "HOME;FAX"
const val PAGER = "PAGER"
const val MOBILE = "MOBILE"
// IMs not supported by Ez-vcard
const val HANGOUTS = "Hangouts"
const val QQ = "QQ"
const val JABBER = "Jabber"
const val ON_CLICK_CALL_CONTACT = 1
const val ON_CLICK_VIEW_CONTACT = 2
const val ON_CLICK_EDIT_CONTACT = 3

View file

@ -102,6 +102,22 @@ class VcfExporter {
card.addAddress(address)
}
contact.IMs.forEach {
val impp = when (it.type) {
CommonDataKinds.Im.PROTOCOL_AIM -> Impp.aim(it.value)
CommonDataKinds.Im.PROTOCOL_YAHOO -> Impp.yahoo(it.value)
CommonDataKinds.Im.PROTOCOL_MSN -> Impp.msn(it.value)
CommonDataKinds.Im.PROTOCOL_ICQ -> Impp.icq(it.value)
CommonDataKinds.Im.PROTOCOL_SKYPE -> Impp.skype(it.value)
CommonDataKinds.Im.PROTOCOL_GOOGLE_TALK -> Impp(HANGOUTS, it.value)
CommonDataKinds.Im.PROTOCOL_QQ -> Impp(QQ, it.value)
CommonDataKinds.Im.PROTOCOL_JABBER -> Impp(JABBER, it.value)
else -> Impp(it.label, it.value)
}
card.addImpp(impp)
}
if (contact.notes.isNotEmpty()) {
card.addNote(contact.notes)
}

View file

@ -15,6 +15,7 @@ import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
import java.io.File
import java.io.FileOutputStream
import java.net.URLDecoder
import java.util.*
class VcfImporter(val activity: SimpleActivity) {
@ -111,7 +112,27 @@ class VcfImporter(val activity: SimpleActivity) {
val photo = null
val thumbnailUri = savePhoto(photoData)
val cleanPhoneNumbers = ArrayList<PhoneNumber>()
val IMs = ArrayList<IM>()
ezContact.impps.forEach {
val typeString = it.uri.scheme
val value = URLDecoder.decode(it.uri.toString().substring(it.uri.scheme.length + 1), "UTF-8")
val type = when {
it.isAim -> CommonDataKinds.Im.PROTOCOL_AIM
it.isYahoo -> CommonDataKinds.Im.PROTOCOL_YAHOO
it.isMsn -> CommonDataKinds.Im.PROTOCOL_MSN
it.isIcq -> CommonDataKinds.Im.PROTOCOL_ICQ
it.isSkype -> CommonDataKinds.Im.PROTOCOL_SKYPE
typeString == HANGOUTS -> CommonDataKinds.Im.PROTOCOL_GOOGLE_TALK
typeString == QQ -> CommonDataKinds.Im.PROTOCOL_QQ
typeString == JABBER -> CommonDataKinds.Im.PROTOCOL_JABBER
else -> CommonDataKinds.Im.PROTOCOL_CUSTOM
}
val label = if (type == CommonDataKinds.Im.PROTOCOL_CUSTOM) URLDecoder.decode(typeString, "UTF-8") else ""
val IM = IM(value, type, label)
IMs.add(IM)
}
val contact = Contact(0, prefix, firstName, middleName, surname, suffix, nickname, photoUri, phoneNumbers, emails, addresses, events,
targetContactSource, starred, contactId, thumbnailUri, photo, notes, groups, organization, websites, cleanPhoneNumbers, IMs)