mirror of
https://github.com/FossifyOrg/Contacts.git
synced 2025-12-23 23:59:46 -05:00
feat: add dialog for choosing contact source when editing merged contact (#201)
* Ensure editing non-messenger contact while editing merged contact (#201) * Added dialog for choosing a contact source * Update CHANGELOG.md * Fixed bugs * fix: add title to chooser dialog For visual context. --------- Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com> Co-authored-by: Naveen Singh <snaveen935@gmail.com>
This commit is contained in:
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- Dialog for choosing contact source while editing a merged contact ([#201])
|
||||
|
||||
## [1.1.0] - 2024-10-28
|
||||
|
||||
### Added
|
||||
@@ -42,3 +45,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
[1.1.0]: https://github.com/FossifyOrg/Contacts/compare/1.0.1...1.1.0
|
||||
[1.0.1]: https://github.com/FossifyOrg/Contacts/compare/1.0.0...1.0.1
|
||||
[1.0.0]: https://github.com/FossifyOrg/Contacts/releases/tag/1.0.0
|
||||
|
||||
[#201]: https://github.com/FossifyOrg/Contacts/issues/201
|
||||
|
||||
@@ -2,14 +2,12 @@ package org.fossify.contacts.activities
|
||||
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.ContentUris
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.media.AudioManager
|
||||
import android.media.RingtoneManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.ContactsContract
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.widget.RelativeLayout
|
||||
@@ -103,7 +101,7 @@ class ViewContactActivity : ContactActivity() {
|
||||
|
||||
findItem(R.id.edit).setOnMenuItemClickListener {
|
||||
if (contact != null) {
|
||||
launchEditContact(contact!!)
|
||||
launchEditContact(contact!!, false)
|
||||
}
|
||||
true
|
||||
}
|
||||
@@ -258,7 +256,7 @@ class ViewContactActivity : ContactActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
getDuplicateContacts {
|
||||
initializeDuplicateContacts {
|
||||
duplicateInitialized = true
|
||||
setupContactDetails()
|
||||
}
|
||||
@@ -283,10 +281,14 @@ class ViewContactActivity : ContactActivity() {
|
||||
updateTextColors(binding.contactScrollview)
|
||||
}
|
||||
|
||||
private fun launchEditContact(contact: Contact) {
|
||||
private fun launchEditContact(contact: Contact, editExactContact: Boolean) {
|
||||
wasEditLaunched = true
|
||||
duplicateInitialized = false
|
||||
editContact(contact)
|
||||
if (editExactContact) {
|
||||
editContact(contact)
|
||||
} else {
|
||||
editContact(contact, config.mergeDuplicateContacts)
|
||||
}
|
||||
}
|
||||
|
||||
private fun openWith() {
|
||||
@@ -626,7 +628,7 @@ class ViewContactActivity : ContactActivity() {
|
||||
binding.contactSourcesHolder.addView(root)
|
||||
|
||||
contactSource.setOnClickListener {
|
||||
launchEditContact(key)
|
||||
launchEditContact(key, true)
|
||||
}
|
||||
|
||||
if (value.lowercase(Locale.getDefault()) == WHATSAPP) {
|
||||
@@ -819,21 +821,11 @@ class ViewContactActivity : ContactActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDuplicateContacts(callback: () -> Unit) {
|
||||
ContactsHelper(this).getDuplicatesOfContact(contact!!, false) { contacts ->
|
||||
ensureBackgroundThread {
|
||||
duplicateContacts.clear()
|
||||
val displayContactSources = getVisibleContactSources()
|
||||
contacts.filter { displayContactSources.contains(it.source) }.forEach {
|
||||
val duplicate = ContactsHelper(this).getContactWithId(it.id, it.isPrivate())
|
||||
if (duplicate != null) {
|
||||
duplicateContacts.add(duplicate)
|
||||
}
|
||||
}
|
||||
|
||||
runOnUiThread {
|
||||
callback()
|
||||
}
|
||||
private fun initializeDuplicateContacts(callback: () -> Unit) {
|
||||
getDuplicateContacts(contact!!, false) {
|
||||
duplicateContacts = it
|
||||
runOnUiThread {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ class ContactsAdapter(
|
||||
|
||||
private fun editContact() {
|
||||
val contact = getItemWithKey(selectedKeys.first()) ?: return
|
||||
activity.editContact(contact)
|
||||
activity.editContact(contact, config.mergeDuplicateContacts)
|
||||
}
|
||||
|
||||
private fun askConfirmDelete() {
|
||||
|
||||
@@ -82,7 +82,7 @@ fun SimpleActivity.handleGenericContactClick(contact: Contact) {
|
||||
when (config.onContactClick) {
|
||||
ON_CLICK_CALL_CONTACT -> callContact(contact)
|
||||
ON_CLICK_VIEW_CONTACT -> viewContact(contact)
|
||||
ON_CLICK_EDIT_CONTACT -> editContact(contact)
|
||||
ON_CLICK_EDIT_CONTACT -> editContact(contact, config.mergeDuplicateContacts)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +104,59 @@ fun Activity.viewContact(contact: Contact) {
|
||||
}
|
||||
}
|
||||
|
||||
fun Activity.editContact(contact: Contact, isMergedDuplicate: Boolean) {
|
||||
if (!isMergedDuplicate) {
|
||||
editContact(contact)
|
||||
} else {
|
||||
ContactsHelper(this).getContactSources { contactSources ->
|
||||
getDuplicateContacts(contact, true) { contacts ->
|
||||
if (contacts.size == 1) {
|
||||
runOnUiThread {
|
||||
editContact(contacts.first())
|
||||
}
|
||||
} else {
|
||||
val items = ArrayList(contacts.mapIndexed { index, contact ->
|
||||
var source = getPublicContactSourceSync(contact.source, contactSources)
|
||||
if (source == "") {
|
||||
source = getString(R.string.phone_storage)
|
||||
}
|
||||
RadioItem(index, source, contact)
|
||||
}.sortedBy { it.title })
|
||||
|
||||
runOnUiThread {
|
||||
RadioGroupDialog(
|
||||
activity = this,
|
||||
items = items,
|
||||
titleId = R.string.select_account,
|
||||
) {
|
||||
editContact(it as Contact)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Activity.getDuplicateContacts(contact: Contact, includeCurrent: Boolean, callback: (duplicateContacts: ArrayList<Contact>) -> Unit) {
|
||||
val duplicateContacts = ArrayList<Contact>()
|
||||
if (includeCurrent) {
|
||||
duplicateContacts.add(contact)
|
||||
}
|
||||
ContactsHelper(this).getDuplicatesOfContact(contact, false) { contacts ->
|
||||
ensureBackgroundThread {
|
||||
val displayContactSources = getVisibleContactSources()
|
||||
contacts.filter { displayContactSources.contains(it.source) }.forEach {
|
||||
val duplicate = ContactsHelper(this).getContactWithId(it.id, it.isPrivate())
|
||||
if (duplicate != null) {
|
||||
duplicateContacts.add(duplicate)
|
||||
}
|
||||
}
|
||||
callback(duplicateContacts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Activity.editContact(contact: Contact) {
|
||||
hideKeyboard()
|
||||
Intent(applicationContext, EditContactActivity::class.java).apply {
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
<string name="edit_contact">Edit contact</string>
|
||||
<string name="select_contact">Select contact</string>
|
||||
<string name="nickname">Nickname</string>
|
||||
<string name="select_account">Select account</string>
|
||||
|
||||
<!-- Groups -->
|
||||
<string name="no_groups">No groups</string>
|
||||
|
||||
Reference in New Issue
Block a user