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