improve deleting multiple contacts at once

This commit is contained in:
tibbi 2019-08-25 22:15:54 +02:00
parent 42ff471748
commit 899971aa2a
5 changed files with 18 additions and 12 deletions

View File

@ -51,7 +51,7 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:5.16.14'
implementation 'com.simplemobiletools:commons:5.16.16'
implementation 'joda-time:joda-time:2.10.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'

View File

@ -167,8 +167,8 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
ensureBackgroundThread {
ContactsHelper(activity).deleteContacts(contactsToRemove)
}
activity.runOnUiThread {
if (contactItems.isEmpty()) {
refreshListener?.refreshContacts(ALL_TABS_MASK)
finishActMode()
@ -177,6 +177,8 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
refreshListener?.refreshContacts(CONTACTS_TAB_MASK or FAVORITES_TAB_MASK)
}
}
}
}
// used for removing contacts from groups or favorites, not deleting actual contacts
private fun removeContacts() {

View File

@ -1530,7 +1530,7 @@ class ContactsHelper(val context: Context) {
}
fun deleteContacts(contacts: ArrayList<Contact>) {
val localContacts = contacts.filter { it.isPrivate() }.map { it.id }.toTypedArray()
val localContacts = contacts.filter { it.isPrivate() }.map { it.id.toLong() }.toMutableList()
LocalContactsHelper(context).deleteContactIds(localContacts)
try {

View File

@ -5,6 +5,7 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.net.Uri
import android.provider.MediaStore
import com.simplemobiletools.commons.extensions.getChoppedList
import com.simplemobiletools.contacts.pro.extensions.contactsDB
import com.simplemobiletools.contacts.pro.extensions.getByteArray
import com.simplemobiletools.contacts.pro.extensions.getEmptyContact
@ -45,9 +46,9 @@ class LocalContactsHelper(val context: Context) {
}
}
fun deleteContactIds(ids: Array<Int>) {
ids.forEach {
context.contactsDB.deleteContactId(it)
fun deleteContactIds(ids: MutableList<Long>) {
ids.getChoppedList().forEach {
context.contactsDB.deleteContactIds(it)
}
}

View File

@ -22,4 +22,7 @@ interface ContactsDao {
@Query("DELETE FROM contacts WHERE id = :id")
fun deleteContactId(id: Int)
@Query("DELETE FROM contacts WHERE id IN (:ids)")
fun deleteContactIds(ids: List<Long>)
}