limit batch group at adding/removing contacts from groups
This commit is contained in:
parent
37bfe59226
commit
4fde91ae47
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue