always fetch all contact info to make sure Search works well

This commit is contained in:
tibbi 2018-03-04 10:06:40 +01:00
parent 004cf57385
commit 9ebb72b1b2
4 changed files with 27 additions and 29 deletions

View File

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

View File

@ -75,7 +75,7 @@ class SelectContactActivity : SimpleActivity() {
}
private fun initContacts() {
ContactsHelper(this).getContacts(true) {
ContactsHelper(this).getContacts {
if (isActivityDestroyed()) {
return@getContacts
}

View File

@ -168,7 +168,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
contactsIDs.add(contactItems[it].id)
}
ContactsHelper(activity).getContacts(true) {
ContactsHelper(activity).getContacts {
val filtered = it.filter { contactsIDs.contains(it.id) } as ArrayList<Contact>
activity.shareContacts(filtered)
}

View File

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