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 { dependencies {
implementation 'com.simplemobiletools:commons:5.16.14' implementation 'com.simplemobiletools:commons:5.16.16'
implementation 'joda-time:joda-time:2.10.1' implementation 'joda-time:joda-time:2.10.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5' implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'

View File

@ -167,14 +167,16 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
ensureBackgroundThread { ensureBackgroundThread {
ContactsHelper(activity).deleteContacts(contactsToRemove) ContactsHelper(activity).deleteContacts(contactsToRemove)
}
if (contactItems.isEmpty()) { activity.runOnUiThread {
refreshListener?.refreshContacts(ALL_TABS_MASK) if (contactItems.isEmpty()) {
finishActMode() refreshListener?.refreshContacts(ALL_TABS_MASK)
} else { finishActMode()
removeSelectedItems(positions) } else {
refreshListener?.refreshContacts(CONTACTS_TAB_MASK or FAVORITES_TAB_MASK) removeSelectedItems(positions)
refreshListener?.refreshContacts(CONTACTS_TAB_MASK or FAVORITES_TAB_MASK)
}
}
} }
} }

View File

@ -1530,7 +1530,7 @@ class ContactsHelper(val context: Context) {
} }
fun deleteContacts(contacts: ArrayList<Contact>) { 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) LocalContactsHelper(context).deleteContactIds(localContacts)
try { try {

View File

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

View File

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