Merge pull request #32 from hanjoongcho/master

fix #31, lowering the number of bulk update lists
This commit is contained in:
Tibor Kaputa 2018-01-06 10:17:37 +01:00 committed by GitHub
commit 38bd334855
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -564,6 +564,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
}
private fun toggleFavorites(ids: ArrayList<String>, areFavorites: Boolean) {
val applyBatchSize = 100
try {
val operations = ArrayList<ContentProviderOperation>()
ids.forEach {
@ -572,6 +573,10 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
withValue(ContactsContract.Contacts.STARRED, if (areFavorites) 1 else 0)
operations.add(build())
}
if (operations.size % applyBatchSize == 0) {
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
operations.clear()
}
}
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
} catch (e: Exception) {