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() {
|
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 {
|
||||||
|
@ -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)
|
||||||
|
@ -25,18 +25,23 @@ 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) {
|
||||||
|
displayContactSources = if (ignoredContactSources.isEmpty()) {
|
||||||
|
context.getAllContactSources().map { it.getFullIdentifier() }.toMutableList() as ArrayList
|
||||||
|
} else {
|
||||||
|
context.getAllContactSources().filter {
|
||||||
it.getFullIdentifier().isNotEmpty() && !ignoredContactSources.contains(it.getFullIdentifier())
|
it.getFullIdentifier().isNotEmpty() && !ignoredContactSources.contains(it.getFullIdentifier())
|
||||||
}.map { it.getFullIdentifier() }.toMutableList() as ArrayList
|
}.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>
|
||||||
|
Reference in New Issue
Block a user