limit batch group at adding/removing contacts from groups

This commit is contained in:
tibbi 2018-04-08 13:03:56 +02:00
parent 37bfe59226
commit 4fde91ae47
2 changed files with 18 additions and 6 deletions

View File

@ -109,9 +109,11 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener, Refresh
}
override fun removeFromGroup(contacts: ArrayList<Contact>) {
removeContactsFromGroup(contacts, group.id)
if (groupContacts.size == 0) {
refreshContacts()
}
Thread {
removeContactsFromGroup(contacts, group.id)
if (groupContacts.size == 0) {
refreshContacts()
}
}.start()
}
}

View File

@ -24,6 +24,7 @@ import com.simplemobiletools.contacts.extensions.*
import com.simplemobiletools.contacts.models.*
class ContactsHelper(val activity: BaseSimpleActivity) {
private val BATCH_SIZE = 100
fun getContacts(callback: (ArrayList<Contact>) -> Unit) {
Thread {
val contacts = SparseArray<Contact>()
@ -886,6 +887,11 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
withValue(CommonDataKinds.GroupMembership.GROUP_ROW_ID, groupId)
operations.add(build())
}
if (operations.size % BATCH_SIZE == 0) {
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
operations.clear()
}
}
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
}
@ -899,6 +905,11 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
withSelection(selection, selectionArgs)
operations.add(build())
}
if (operations.size % BATCH_SIZE == 0) {
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
operations.clear()
}
}
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
}
@ -1117,7 +1128,6 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
}
private fun toggleFavorites(contacts: ArrayList<Contact>, addToFavorites: Boolean) {
val applyBatchSize = 100
try {
val operations = ArrayList<ContentProviderOperation>()
contacts.filter { it.source != SMT_PRIVATE }.map { it.contactId.toString() }.forEach {
@ -1127,7 +1137,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
operations.add(build())
}
if (operations.size % applyBatchSize == 0) {
if (operations.size % BATCH_SIZE == 0) {
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
operations.clear()
}