From 09b41d2422bc06c54fe6d9267ac20776f4f2a4a7 Mon Sep 17 00:00:00 2001 From: "hanjoong.cho" Date: Sat, 6 Jan 2018 08:29:46 +0900 Subject: [PATCH] fix #28, lowering the number of bulk update lists --- .../com/simplemobiletools/contacts/helpers/ContactsHelper.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt index 1e335da9..99d2b29c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt @@ -564,6 +564,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) { } private fun toggleFavorites(ids: ArrayList, areFavorites: Boolean) { + val applyBatchSize = 100 try { val operations = ArrayList() 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) {