mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
properly export all contacts as appropriate
This commit is contained in:
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -25,18 +25,23 @@ 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 {
|
||||
|
||||
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>
|
||||
|
Reference in New Issue
Block a user