improve some contact deleting scenarios, delete clones in some cases
This commit is contained in:
parent
33357e1413
commit
090c347e5f
|
@ -77,8 +77,9 @@ abstract class ContactActivity : SimpleActivity() {
|
|||
fun deleteContact() {
|
||||
ConfirmationDialog(this) {
|
||||
if (contact != null) {
|
||||
ContactsHelper(this).deleteContact(contact!!)
|
||||
finish()
|
||||
ContactsHelper(this).deleteContact(contact!!, false) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -992,10 +992,14 @@ class EditContactActivity : ContactActivity() {
|
|||
if (ContactsHelper(this@EditContactActivity).insertContact(contact!!)) {
|
||||
if (deleteCurrentContact) {
|
||||
contact!!.source = originalContactSource
|
||||
ContactsHelper(this).deleteContact(contact!!)
|
||||
ContactsHelper(this).deleteContact(contact!!, false) {
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
}
|
||||
} else {
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
}
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
|
|
|
@ -519,8 +519,9 @@ class ViewContactActivity : ContactActivity() {
|
|||
val message = "${getString(R.string.proceed_with_deletion)}$addition"
|
||||
ConfirmationDialog(this, message) {
|
||||
if (contact != null) {
|
||||
ContactsHelper(this).deleteContact(contact!!)
|
||||
finish()
|
||||
ContactsHelper(this).deleteContact(contact!!, true) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1524,17 +1524,27 @@ class ContactsHelper(val context: Context) {
|
|||
LocalContactsHelper(context).toggleFavorites(localContacts, addToFavorites)
|
||||
}
|
||||
|
||||
fun deleteContact(originalContact: Contact) {
|
||||
getDuplicatesOfContact(originalContact, true) { contacts ->
|
||||
deleteContacts(contacts)
|
||||
fun deleteContact(originalContact: Contact, deleteClones: Boolean = false, callback: (success: Boolean) -> Unit) {
|
||||
ensureBackgroundThread {
|
||||
if (deleteClones) {
|
||||
getDuplicatesOfContact(originalContact, true) { contacts ->
|
||||
if (deleteContacts(contacts)) {
|
||||
callback(true)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (deleteContacts(arrayListOf(originalContact))) {
|
||||
callback(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteContacts(contacts: ArrayList<Contact>) {
|
||||
fun deleteContacts(contacts: ArrayList<Contact>): Boolean {
|
||||
val localContacts = contacts.filter { it.isPrivate() }.map { it.id.toLong() }.toMutableList()
|
||||
LocalContactsHelper(context).deleteContactIds(localContacts)
|
||||
|
||||
try {
|
||||
return try {
|
||||
val operations = ArrayList<ContentProviderOperation>()
|
||||
val selection = "${ContactsContract.RawContacts._ID} = ?"
|
||||
contacts.filter { !it.isPrivate() }.forEach {
|
||||
|
@ -1553,8 +1563,10 @@ class ContactsHelper(val context: Context) {
|
|||
if (context.hasPermission(PERMISSION_WRITE_CONTACTS)) {
|
||||
context.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
context.showErrorToast(e)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue