handle deleting local private contacts
This commit is contained in:
parent
062ee8a6d4
commit
21cc46de54
|
@ -639,14 +639,23 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||
}
|
||||
}
|
||||
|
||||
fun deleteContact(contact: Contact) = deleteContacts(arrayListOf(contact))
|
||||
fun deleteContact(contact: Contact) {
|
||||
if (contact.source == SMT_PRIVATE) {
|
||||
activity.dbHelper.deleteContact(contact.id)
|
||||
} else {
|
||||
deleteContacts(arrayListOf(contact))
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteContacts(contacts: ArrayList<Contact>) {
|
||||
val localContacts = contacts.filter { it.source == SMT_PRIVATE }.map { it.id.toString() }.toTypedArray()
|
||||
activity.dbHelper.deleteContacts(localContacts)
|
||||
|
||||
try {
|
||||
val contactIDs = HashSet<String>()
|
||||
val operations = ArrayList<ContentProviderOperation>()
|
||||
val selection = "${ContactsContract.Data.RAW_CONTACT_ID} = ?"
|
||||
contacts.forEach {
|
||||
contacts.filter { it.source != SMT_PRIVATE }.forEach {
|
||||
ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).apply {
|
||||
val selectionArgs = arrayOf(it.id.toString())
|
||||
withSelection(selection, selectionArgs)
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.ContentValues
|
|||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.database.sqlite.SQLiteOpenHelper
|
||||
import android.text.TextUtils
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.commons.extensions.getIntValue
|
||||
|
@ -68,6 +69,14 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
return mDb.update(CONTACTS_TABLE_NAME, contactValues, selection, selectionArgs) == 1
|
||||
}
|
||||
|
||||
fun deleteContact(id: Int) = deleteContacts(arrayOf(id.toString()))
|
||||
|
||||
fun deleteContacts(ids: Array<String>) {
|
||||
val args = TextUtils.join(", ", ids)
|
||||
val selection = "$CONTACTS_TABLE_NAME.$COL_ID IN ($args)"
|
||||
mDb.delete(CONTACTS_TABLE_NAME, selection, null)
|
||||
}
|
||||
|
||||
private fun fillContactValues(contact: Contact): ContentValues {
|
||||
return ContentValues().apply {
|
||||
put(COL_FIRST_NAME, contact.firstName)
|
||||
|
|
Loading…
Reference in New Issue