make fetching some fields optional, used only at exporting

This commit is contained in:
tibbi 2018-02-22 16:23:04 +01:00
parent f81700c120
commit 7f11945af4
2 changed files with 15 additions and 15 deletions

View File

@ -358,7 +358,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
FilePickerDialog(this, pickFile = false, showFAB = true) { FilePickerDialog(this, pickFile = false, showFAB = true) {
ExportContactsDialog(this, it) { file, contactSources -> ExportContactsDialog(this, it) { file, contactSources ->
Thread { Thread {
ContactsHelper(this).getContacts { ContactsHelper(this).getContacts(true) {
val contacts = it.filter { contactSources.contains(it.source) } val contacts = it.filter { contactSources.contains(it.source) }
if (contacts.isEmpty()) { if (contacts.isEmpty()) {
toast(R.string.no_entries_for_exporting) toast(R.string.no_entries_for_exporting)

View File

@ -29,7 +29,7 @@ import com.simplemobiletools.contacts.extensions.getPhotoThumbnailSize
import com.simplemobiletools.contacts.models.* import com.simplemobiletools.contacts.models.*
class ContactsHelper(val activity: BaseSimpleActivity) { class ContactsHelper(val activity: BaseSimpleActivity) {
fun getContacts(callback: (ArrayList<Contact>) -> Unit) { fun getContacts(addOptionalFields: Boolean = false, callback: (ArrayList<Contact>) -> Unit) {
val contacts = SparseArray<Contact>() val contacts = SparseArray<Contact>()
Thread { Thread {
val uri = ContactsContract.Data.CONTENT_URI val uri = ContactsContract.Data.CONTENT_URI
@ -75,22 +75,22 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
contacts[key]?.phoneNumbers = phoneNumbers.valueAt(i) contacts[key]?.phoneNumbers = phoneNumbers.valueAt(i)
} }
val emails = getEmails() if (addOptionalFields) {
size = emails.size() val emails = getEmails()
for (i in 0 until size) { size = emails.size()
val key = emails.keyAt(i) for (i in 0 until size) {
contacts[key]?.emails = emails.valueAt(i) val key = emails.keyAt(i)
} contacts[key]?.emails = emails.valueAt(i)
}
val addresses = getAddresses() val addresses = getAddresses()
size = addresses.size() size = addresses.size()
for (i in 0 until size) { for (i in 0 until size) {
val key = addresses.keyAt(i) val key = addresses.keyAt(i)
contacts[key]?.addresses = addresses.valueAt(i) contacts[key]?.addresses = addresses.valueAt(i)
}
} }
//getNotes()
activity.dbHelper.getContacts().forEach { activity.dbHelper.getContacts().forEach {
contacts.put(it.id, it) contacts.put(it.id, it)
} }