properly export all contacts as appropriate

This commit is contained in:
tibbi
2019-08-26 15:46:09 +02:00
parent e6c031885c
commit d856649618
3 changed files with 15 additions and 10 deletions

View File

@ -496,7 +496,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
private fun exportContacts() { private fun exportContacts() {
FilePickerDialog(this, pickFile = false, showFAB = true) { FilePickerDialog(this, pickFile = false, showFAB = true) {
ExportContactsDialog(this, it) { file, ignoredContactSources -> ExportContactsDialog(this, it) { file, ignoredContactSources ->
ContactsHelper(this).getContacts(ignoredContactSources) { contacts -> ContactsHelper(this).getContacts(true, ignoredContactSources) { contacts ->
if (contacts.isEmpty()) { if (contacts.isEmpty()) {
toast(R.string.no_entries_for_exporting) toast(R.string.no_entries_for_exporting)
} else { } else {

View File

@ -307,10 +307,10 @@ fun Context.getVisibleContactSources(): ArrayList<String> {
.map { it.name }.toMutableList() as ArrayList<String> .map { it.name }.toMutableList() as ArrayList<String>
} }
fun Context.getAllContactSources(): List<ContactSource> { fun Context.getAllContactSources(): ArrayList<ContactSource> {
val sources = ContactsHelper(this).getDeviceContactSources() val sources = ContactsHelper(this).getDeviceContactSources()
sources.add(getPrivateContactSource()) sources.add(getPrivateContactSource())
return sources.toMutableList() return sources.toMutableList() as ArrayList<ContactSource>
} }
@TargetApi(Build.VERSION_CODES.N) @TargetApi(Build.VERSION_CODES.N)

View File

@ -25,17 +25,22 @@ import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
class ContactsHelper(val context: Context) { class ContactsHelper(val context: Context) {
private val BATCH_SIZE = 100 private val BATCH_SIZE = 50
private var displayContactSources = ArrayList<String>() private var displayContactSources = ArrayList<String>()
fun getContacts(ignoredContactSources: HashSet<String> = HashSet(), callback: (ArrayList<Contact>) -> Unit) { fun getContacts(isExporting: Boolean = false, ignoredContactSources: HashSet<String> = HashSet(), callback: (ArrayList<Contact>) -> Unit) {
ensureBackgroundThread { ensureBackgroundThread {
val contacts = SparseArray<Contact>() val contacts = SparseArray<Contact>()
displayContactSources = context.getVisibleContactSources() displayContactSources = context.getVisibleContactSources()
if (ignoredContactSources.isNotEmpty()) {
displayContactSources = context.getAllContactSources().filter { if (isExporting) {
it.getFullIdentifier().isNotEmpty() && !ignoredContactSources.contains(it.getFullIdentifier()) displayContactSources = if (ignoredContactSources.isEmpty()) {
}.map { it.getFullIdentifier() }.toMutableList() as ArrayList 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) getDeviceContacts(contacts, ignoredContactSources)
@ -61,7 +66,7 @@ class ContactsHelper(val context: Context) {
contacts.valueAt(it) contacts.valueAt(it)
} }
if (ignoredContactSources.isEmpty() && context.config.filterDuplicates) { if (ignoredContactSources.isEmpty() && context.config.filterDuplicates && !isExporting) {
tempContacts = tempContacts.distinctBy { tempContacts = tempContacts.distinctBy {
it.getHashToCompare() it.getHashToCompare()
} as ArrayList<Contact> } as ArrayList<Contact>