mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-04-15 18:37:23 +02:00
Merge pull request #32 from hanjoongcho/master
fix #31, lowering the number of bulk update lists
This commit is contained in:
commit
38bd334855
@ -564,6 +564,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleFavorites(ids: ArrayList<String>, areFavorites: Boolean) {
|
private fun toggleFavorites(ids: ArrayList<String>, areFavorites: Boolean) {
|
||||||
|
val applyBatchSize = 100
|
||||||
try {
|
try {
|
||||||
val operations = ArrayList<ContentProviderOperation>()
|
val operations = ArrayList<ContentProviderOperation>()
|
||||||
ids.forEach {
|
ids.forEach {
|
||||||
@ -572,6 +573,10 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
withValue(ContactsContract.Contacts.STARRED, if (areFavorites) 1 else 0)
|
withValue(ContactsContract.Contacts.STARRED, if (areFavorites) 1 else 0)
|
||||||
operations.add(build())
|
operations.add(build())
|
||||||
}
|
}
|
||||||
|
if (operations.size % applyBatchSize == 0) {
|
||||||
|
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
|
||||||
|
operations.clear()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
|
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user