fix #582, allow disabling duplicate contact merging

This commit is contained in:
tibbi 2022-03-24 10:40:13 +01:00
parent faf6a8597a
commit ef10ce088f
6 changed files with 40 additions and 6 deletions

View File

@ -34,6 +34,7 @@ class SettingsActivity : SimpleActivity() {
setupShowPhoneNumbers()
setupShowContactsWithNumbers()
setupStartNameWithSurname()
setupMergeDuplicateContacts()
setupShowCallConfirmation()
setupShowDialpadButton()
setupShowPrivateContacts()
@ -216,4 +217,12 @@ class SettingsActivity : SimpleActivity() {
config.showCallConfirmation = settings_show_call_confirmation.isChecked
}
}
private fun setupMergeDuplicateContacts() {
settings_merge_duplicate_contacts.isChecked = config.mergeDuplicateContacts
settings_merge_duplicate_contacts_holder.setOnClickListener {
settings_merge_duplicate_contacts.toggle()
config.mergeDuplicateContacts = settings_merge_duplicate_contacts.isChecked
}
}
}

View File

@ -245,9 +245,11 @@ class ViewContactActivity : ContactActivity() {
contactSources = it
runOnUiThread {
setupContactDetails()
getDuplicateContacts {
if (duplicateContacts.isNotEmpty()) {
setupContactDetails()
if (config.mergeDuplicateContacts) {
getDuplicateContacts {
if (duplicateContacts.isNotEmpty()) {
setupContactDetails()
}
}
}
}

View File

@ -33,8 +33,10 @@ class Config(context: Context) : BaseConfig(context) {
set(onContactClick) = prefs.edit().putInt(ON_CONTACT_CLICK, onContactClick).apply()
var showContactFields: Int
get() = prefs.getInt(SHOW_CONTACT_FIELDS, SHOW_FIRST_NAME_FIELD or SHOW_SURNAME_FIELD or SHOW_PHONE_NUMBERS_FIELD or SHOW_EMAILS_FIELD or
SHOW_ADDRESSES_FIELD or SHOW_EVENTS_FIELD or SHOW_NOTES_FIELD or SHOW_GROUPS_FIELD or SHOW_CONTACT_SOURCE_FIELD)
get() = prefs.getInt(
SHOW_CONTACT_FIELDS, SHOW_FIRST_NAME_FIELD or SHOW_SURNAME_FIELD or SHOW_PHONE_NUMBERS_FIELD or SHOW_EMAILS_FIELD or
SHOW_ADDRESSES_FIELD or SHOW_EVENTS_FIELD or SHOW_NOTES_FIELD or SHOW_GROUPS_FIELD or SHOW_CONTACT_SOURCE_FIELD
)
set(showContactFields) = prefs.edit().putInt(SHOW_CONTACT_FIELDS, showContactFields).apply()
var showTabs: Int
@ -60,4 +62,8 @@ class Config(context: Context) : BaseConfig(context) {
var showPrivateContacts: Boolean
get() = prefs.getBoolean(SHOW_PRIVATE_CONTACTS, true)
set(showPrivateContacts) = prefs.edit().putBoolean(SHOW_PRIVATE_CONTACTS, showPrivateContacts).apply()
var mergeDuplicateContacts: Boolean
get() = prefs.getBoolean(MERGE_DUPLICATE_CONTACTS, true)
set(mergeDuplicateContacts) = prefs.edit().putBoolean(MERGE_DUPLICATE_CONTACTS, mergeDuplicateContacts).apply()
}

View File

@ -21,6 +21,7 @@ const val SPEED_DIAL = "speed_dial"
const val LAST_EXPORT_PATH = "last_export_path"
const val WAS_LOCAL_ACCOUNT_INITIALIZED = "was_local_account_initialized"
const val SHOW_PRIVATE_CONTACTS = "show_private_contacts"
const val MERGE_DUPLICATE_CONTACTS = "merge_duplicate_contacts"
const val SMT_PRIVATE = "smt_private" // used at the contact source of local contacts hidden from other apps
const val GROUP = "group"

View File

@ -72,7 +72,7 @@ class ContactsHelper(val context: Context) {
contacts.valueAt(it)
}
if (ignoredContactSources.isEmpty() && !getAll) {
if (context.config.mergeDuplicateContacts && ignoredContactSources.isEmpty() && !getAll) {
tempContacts.filter { displayContactSources.contains(it.source) }.groupBy { it.getNameToDisplay().toLowerCase() }.values.forEach { it ->
if (it.size == 1) {
resultContacts.add(it.first())

View File

@ -114,6 +114,22 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_merge_duplicate_contacts_holder"
style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_background">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_merge_duplicate_contacts"
style="@style/SettingsCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/merge_duplicate_contacts" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_show_call_confirmation_holder"
style="@style/SettingsHolderCheckboxStyle"