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() {
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 {

View File

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

View File

@ -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<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 {
val contacts = SparseArray<Contact>()
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<Contact>