mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-04-25 23:08:41 +02:00
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() {
|
fun deleteContact() {
|
||||||
ConfirmationDialog(this) {
|
ConfirmationDialog(this) {
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
ContactsHelper(this).deleteContact(contact!!)
|
ContactsHelper(this).deleteContact(contact!!, false) {
|
||||||
finish()
|
finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -992,10 +992,14 @@ class EditContactActivity : ContactActivity() {
|
|||||||
if (ContactsHelper(this@EditContactActivity).insertContact(contact!!)) {
|
if (ContactsHelper(this@EditContactActivity).insertContact(contact!!)) {
|
||||||
if (deleteCurrentContact) {
|
if (deleteCurrentContact) {
|
||||||
contact!!.source = originalContactSource
|
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 {
|
} else {
|
||||||
toast(R.string.unknown_error_occurred)
|
toast(R.string.unknown_error_occurred)
|
||||||
}
|
}
|
||||||
|
@ -519,8 +519,9 @@ class ViewContactActivity : ContactActivity() {
|
|||||||
val message = "${getString(R.string.proceed_with_deletion)}$addition"
|
val message = "${getString(R.string.proceed_with_deletion)}$addition"
|
||||||
ConfirmationDialog(this, message) {
|
ConfirmationDialog(this, message) {
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
ContactsHelper(this).deleteContact(contact!!)
|
ContactsHelper(this).deleteContact(contact!!, true) {
|
||||||
finish()
|
finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1524,17 +1524,27 @@ class ContactsHelper(val context: Context) {
|
|||||||
LocalContactsHelper(context).toggleFavorites(localContacts, addToFavorites)
|
LocalContactsHelper(context).toggleFavorites(localContacts, addToFavorites)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteContact(originalContact: Contact) {
|
fun deleteContact(originalContact: Contact, deleteClones: Boolean = false, callback: (success: Boolean) -> Unit) {
|
||||||
getDuplicatesOfContact(originalContact, true) { contacts ->
|
ensureBackgroundThread {
|
||||||
deleteContacts(contacts)
|
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()
|
val localContacts = contacts.filter { it.isPrivate() }.map { it.id.toLong() }.toMutableList()
|
||||||
LocalContactsHelper(context).deleteContactIds(localContacts)
|
LocalContactsHelper(context).deleteContactIds(localContacts)
|
||||||
|
|
||||||
try {
|
return try {
|
||||||
val operations = ArrayList<ContentProviderOperation>()
|
val operations = ArrayList<ContentProviderOperation>()
|
||||||
val selection = "${ContactsContract.RawContacts._ID} = ?"
|
val selection = "${ContactsContract.RawContacts._ID} = ?"
|
||||||
contacts.filter { !it.isPrivate() }.forEach {
|
contacts.filter { !it.isPrivate() }.forEach {
|
||||||
@ -1553,8 +1563,10 @@ class ContactsHelper(val context: Context) {
|
|||||||
if (context.hasPermission(PERMISSION_WRITE_CONTACTS)) {
|
if (context.hasPermission(PERMISSION_WRITE_CONTACTS)) {
|
||||||
context.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
|
context.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
|
||||||
}
|
}
|
||||||
|
true
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
context.showErrorToast(e)
|
context.showErrorToast(e)
|
||||||
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user