diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt index 4e4392d8..37edb2b6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt @@ -496,7 +496,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { private fun exportContacts() { FilePickerDialog(this, pickFile = false, showFAB = true) { ExportContactsDialog(this, it) { file, ignoredContactSources -> - ContactsHelper(this).getContacts(ignoredContactSources) { contacts -> + ContactsHelper(this).getContacts(true, ignoredContactSources) { contacts -> if (contacts.isEmpty()) { toast(R.string.no_entries_for_exporting) } else { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt index e505e4ed..59868db0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt @@ -307,10 +307,10 @@ fun Context.getVisibleContactSources(): ArrayList { .map { it.name }.toMutableList() as ArrayList } -fun Context.getAllContactSources(): List { +fun Context.getAllContactSources(): ArrayList { val sources = ContactsHelper(this).getDeviceContactSources() sources.add(getPrivateContactSource()) - return sources.toMutableList() + return sources.toMutableList() as ArrayList } @TargetApi(Build.VERSION_CODES.N) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt index ecc2ff98..30d247d9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt @@ -25,17 +25,22 @@ import java.util.* import kotlin.collections.ArrayList class ContactsHelper(val context: Context) { - private val BATCH_SIZE = 100 + private val BATCH_SIZE = 50 private var displayContactSources = ArrayList() - fun getContacts(ignoredContactSources: HashSet = HashSet(), callback: (ArrayList) -> Unit) { + fun getContacts(isExporting: Boolean = false, ignoredContactSources: HashSet = HashSet(), callback: (ArrayList) -> Unit) { ensureBackgroundThread { val contacts = SparseArray() displayContactSources = context.getVisibleContactSources() - if (ignoredContactSources.isNotEmpty()) { - displayContactSources = context.getAllContactSources().filter { - it.getFullIdentifier().isNotEmpty() && !ignoredContactSources.contains(it.getFullIdentifier()) - }.map { it.getFullIdentifier() }.toMutableList() as ArrayList + + if (isExporting) { + displayContactSources = if (ignoredContactSources.isEmpty()) { + context.getAllContactSources().map { it.getFullIdentifier() }.toMutableList() as ArrayList + } else { + context.getAllContactSources().filter { + it.getFullIdentifier().isNotEmpty() && !ignoredContactSources.contains(it.getFullIdentifier()) + }.map { it.getFullIdentifier() }.toMutableList() as ArrayList + } } getDeviceContacts(contacts, ignoredContactSources) @@ -61,7 +66,7 @@ class ContactsHelper(val context: Context) { contacts.valueAt(it) } - if (ignoredContactSources.isEmpty() && context.config.filterDuplicates) { + if (ignoredContactSources.isEmpty() && context.config.filterDuplicates && !isExporting) { tempContacts = tempContacts.distinctBy { it.getHashToCompare() } as ArrayList