mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-10 00:20:46 +01:00
minor code cleanup at importing/exporting
This commit is contained in:
parent
b90405ceea
commit
37016b53cb
@ -139,7 +139,7 @@ class VcfExporter {
|
|||||||
card.addPhoto(photo)
|
card.addPhoto(photo)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contact.groups.size > 0) {
|
if (contact.groups.isNotEmpty()) {
|
||||||
val groupList = Categories()
|
val groupList = Categories()
|
||||||
contact.groups.forEach {
|
contact.groups.forEach {
|
||||||
groupList.values.add(it.title)
|
groupList.values.add(it.title)
|
||||||
|
@ -5,7 +5,6 @@ import android.graphics.BitmapFactory
|
|||||||
import android.provider.ContactsContract.CommonDataKinds
|
import android.provider.ContactsContract.CommonDataKinds
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||||
import com.simplemobiletools.contacts.R
|
|
||||||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||||
import com.simplemobiletools.contacts.extensions.dbHelper
|
import com.simplemobiletools.contacts.extensions.dbHelper
|
||||||
import com.simplemobiletools.contacts.extensions.getCachePhoto
|
import com.simplemobiletools.contacts.extensions.getCachePhoto
|
||||||
@ -13,6 +12,7 @@ import com.simplemobiletools.contacts.extensions.getCachePhotoUri
|
|||||||
import com.simplemobiletools.contacts.helpers.VcfImporter.ImportResult.*
|
import com.simplemobiletools.contacts.helpers.VcfImporter.ImportResult.*
|
||||||
import com.simplemobiletools.contacts.models.*
|
import com.simplemobiletools.contacts.models.*
|
||||||
import ezvcard.Ezvcard
|
import ezvcard.Ezvcard
|
||||||
|
import ezvcard.VCard
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import org.joda.time.format.DateTimeFormat
|
import org.joda.time.format.DateTimeFormat
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -104,36 +104,11 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||||||
val starred = 0
|
val starred = 0
|
||||||
val contactId = 0
|
val contactId = 0
|
||||||
val notes = ezContact.notes.firstOrNull()?.value ?: ""
|
val notes = ezContact.notes.firstOrNull()?.value ?: ""
|
||||||
val groups = ArrayList<Group>()
|
val groups = getContactGroups(ezContact)
|
||||||
|
|
||||||
if (ezContact.categories != null) {
|
|
||||||
val groupNames = ezContact.categories.values
|
|
||||||
|
|
||||||
if (groupNames != null) {
|
|
||||||
val storedGroups = ContactsHelper(activity).getStoredGroups()
|
|
||||||
|
|
||||||
groupNames.forEach {
|
|
||||||
val groupName = it
|
|
||||||
val storedGroup = storedGroups.firstOrNull { it.title == groupName }
|
|
||||||
|
|
||||||
if (storedGroup != null) {
|
|
||||||
groups.add(storedGroup)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
val newcontactGroup = activity.dbHelper.insertGroup(Group(0, groupName))
|
|
||||||
|
|
||||||
if (newcontactGroup != null)
|
|
||||||
groups.add(newcontactGroup)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val company = ezContact.organization?.values?.firstOrNull() ?: ""
|
val company = ezContact.organization?.values?.firstOrNull() ?: ""
|
||||||
val jobPosition = ezContact.titles?.firstOrNull()?.value ?: ""
|
val jobPosition = ezContact.titles?.firstOrNull()?.value ?: ""
|
||||||
val organization = Organization(company, jobPosition)
|
val organization = Organization(company, jobPosition)
|
||||||
val websites = ezContact.urls.map { it.value } as ArrayList<String>
|
val websites = ezContact.urls.map { it.value } as ArrayList<String>
|
||||||
|
|
||||||
val photoData = ezContact.photos.firstOrNull()?.data
|
val photoData = ezContact.photos.firstOrNull()?.data
|
||||||
val photo = null
|
val photo = null
|
||||||
val thumbnailUri = savePhoto(photoData)
|
val thumbnailUri = savePhoto(photoData)
|
||||||
@ -184,6 +159,33 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||||||
return dateTime.toString("yyyy-MM-dd")
|
return dateTime.toString("yyyy-MM-dd")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getContactGroups(ezContact: VCard): ArrayList<Group> {
|
||||||
|
val groups = ArrayList<Group>()
|
||||||
|
if (ezContact.categories != null) {
|
||||||
|
val groupNames = ezContact.categories.values
|
||||||
|
|
||||||
|
if (groupNames != null) {
|
||||||
|
val storedGroups = ContactsHelper(activity).getStoredGroups()
|
||||||
|
|
||||||
|
groupNames.forEach {
|
||||||
|
val groupName = it
|
||||||
|
val storedGroup = storedGroups.firstOrNull { it.title == groupName }
|
||||||
|
|
||||||
|
if (storedGroup != null) {
|
||||||
|
groups.add(storedGroup)
|
||||||
|
} else {
|
||||||
|
val newContactGroup = activity.dbHelper.insertGroup(Group(0, groupName))
|
||||||
|
|
||||||
|
if (newContactGroup != null) {
|
||||||
|
groups.add(newContactGroup)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return groups
|
||||||
|
}
|
||||||
|
|
||||||
private fun getPhoneNumberTypeId(type: String, subtype: String?) = when (type.toUpperCase()) {
|
private fun getPhoneNumberTypeId(type: String, subtype: String?) = when (type.toUpperCase()) {
|
||||||
CELL -> CommonDataKinds.Phone.TYPE_MOBILE
|
CELL -> CommonDataKinds.Phone.TYPE_MOBILE
|
||||||
HOME -> {
|
HOME -> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user