mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-04-26 07:18:41 +02:00
improve some contact deleting scenarios, delete clones in some cases
This commit is contained in:
parent
33357e1413
commit
090c347e5f
@ -77,11 +77,12 @@ 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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun shareContact() {
|
fun shareContact() {
|
||||||
shareContacts(arrayListOf(contact!!))
|
shareContacts(arrayListOf(contact!!))
|
||||||
|
@ -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)
|
setResult(Activity.RESULT_OK)
|
||||||
finish()
|
finish()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setResult(Activity.RESULT_OK)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.unknown_error_occurred)
|
toast(R.string.unknown_error_occurred)
|
||||||
}
|
}
|
||||||
|
@ -519,11 +519,12 @@ 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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getStarDrawable(on: Boolean) = resources.getDrawable(if (on) R.drawable.ic_star_on_vector else R.drawable.ic_star_off_vector)
|
private fun getStarDrawable(on: Boolean) = resources.getDrawable(if (on) R.drawable.ic_star_on_vector else R.drawable.ic_star_off_vector)
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
ensureBackgroundThread {
|
||||||
|
if (deleteClones) {
|
||||||
getDuplicatesOfContact(originalContact, true) { contacts ->
|
getDuplicatesOfContact(originalContact, true) { contacts ->
|
||||||
deleteContacts(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