mirror of
				https://github.com/SimpleMobileTools/Simple-Contacts.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	try being smarter at showing distinct contacts, dont check just contact id
This commit is contained in:
		| @@ -99,9 +99,7 @@ class SelectContactActivity : SimpleActivity() { | ||||
|             } as ArrayList<Contact> | ||||
|  | ||||
|             val contactSources = config.displayContactSources | ||||
|             if (!config.showAllContacts()) { | ||||
|             contacts = contacts.filter { contactSources.contains(it.source) } as ArrayList<Contact> | ||||
|             } | ||||
|  | ||||
|             Contact.sorting = config.sorting | ||||
|             Contact.startWithSurname = config.startNameWithSurname | ||||
|   | ||||
| @@ -21,7 +21,7 @@ class FilterContactSourcesAdapter(val activity: SimpleActivity, private val cont | ||||
|  | ||||
|     init { | ||||
|         contactSources.forEachIndexed { index, contactSource -> | ||||
|             if (activity.config.showAllContacts() || displayContactSources.contains(contactSource.name)) { | ||||
|             if (displayContactSources.contains(contactSource.name)) { | ||||
|                 selectedPositions.add(index) | ||||
|             } | ||||
|  | ||||
|   | ||||
| @@ -19,9 +19,7 @@ class SelectContactsDialog(val activity: SimpleActivity, initialContacts: ArrayL | ||||
|         var allContacts = initialContacts | ||||
|         if (selectContacts == null) { | ||||
|             val contactSources = activity.config.displayContactSources | ||||
|             if (!activity.config.showAllContacts()) { | ||||
|             allContacts = allContacts.filter { contactSources.contains(it.source) } as ArrayList<Contact> | ||||
|             } | ||||
|  | ||||
|             initiallySelectedContacts = allContacts.filter { it.starred == 1 } as ArrayList<Contact> | ||||
|         } else { | ||||
|   | ||||
| @@ -99,15 +99,11 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) | ||||
|         contacts.sort() | ||||
|         allContacts = contacts | ||||
|  | ||||
|         val filtered = if (this is GroupsFragment) { | ||||
|             contacts | ||||
|         } else if (this is FavoritesFragment) { | ||||
|             contacts.filter { it.starred == 1 } as ArrayList<Contact> | ||||
|         } else { | ||||
|         val filtered = when { | ||||
|             this is GroupsFragment -> contacts | ||||
|             this is FavoritesFragment -> contacts.filter { it.starred == 1 } as ArrayList<Contact> | ||||
|             else -> { | ||||
|                 val contactSources = config.displayContactSources | ||||
|             if (config.showAllContacts()) { | ||||
|                 contacts | ||||
|             } else { | ||||
|                 contacts.filter { contactSources.contains(it.source) } as ArrayList<Contact> | ||||
|             } | ||||
|         } | ||||
|   | ||||
| @@ -12,8 +12,6 @@ class Config(context: Context) : BaseConfig(context) { | ||||
|         get() = prefs.getStringSet(DISPLAY_CONTACT_SOURCES, hashSetOf("-1")) | ||||
|         set(displayContactSources) = prefs.edit().remove(DISPLAY_CONTACT_SOURCES).putStringSet(DISPLAY_CONTACT_SOURCES, displayContactSources).apply() | ||||
|  | ||||
|     fun showAllContacts() = displayContactSources.size == 1 && displayContactSources.first() == "-1" | ||||
|  | ||||
|     var showContactThumbnails: Boolean | ||||
|         get() = prefs.getBoolean(SHOW_CONTACT_THUMBNAILS, true) | ||||
|         set(showContactThumbnails) = prefs.edit().putBoolean(SHOW_CONTACT_THUMBNAILS, showContactThumbnails).apply() | ||||
|   | ||||
| @@ -35,7 +35,9 @@ class ContactsHelper(val activity: BaseSimpleActivity) { | ||||
|             val contactsSize = contacts.size() | ||||
|             var resultContacts = ArrayList<Contact>(contactsSize) | ||||
|             (0 until contactsSize).mapTo(resultContacts) { contacts.valueAt(it) } | ||||
|             resultContacts = resultContacts.distinctBy { it.contactId } as ArrayList<Contact> | ||||
|             resultContacts = resultContacts.distinctBy { | ||||
|                 it.getHashToCompare() | ||||
|             } as ArrayList<Contact> | ||||
|  | ||||
|             // groups are obtained with contactID, not rawID, so assign them to proper contacts like this | ||||
|             val groups = getContactGroups(getStoredGroups()) | ||||
| @@ -88,6 +90,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) { | ||||
|                     val websites = ArrayList<String>() | ||||
|                     val contact = Contact(id, prefix, firstName, middleName, surname, suffix, photoUri, number, emails, addresses, events, | ||||
|                             accountName, starred, contactId, thumbnailUri, null, notes, groups, organization, websites) | ||||
|  | ||||
|                     contacts.put(id, contact) | ||||
|                 } while (cursor.moveToNext()) | ||||
|             } | ||||
| @@ -1214,16 +1217,14 @@ class ContactsHelper(val activity: BaseSimpleActivity) { | ||||
|             activity.dbHelper.deleteContacts(localContacts) | ||||
|  | ||||
|             try { | ||||
|                 val contactIDs = HashSet<String>() | ||||
|                 val operations = ArrayList<ContentProviderOperation>() | ||||
|                 val selection = "${ContactsContract.Data.CONTACT_ID} = ?" | ||||
|                 contacts.filter { it.source != SMT_PRIVATE }.forEach { | ||||
|                     ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).apply { | ||||
|                         val selectionArgs = arrayOf(it.contactId.toString()) | ||||
|                         withSelection(selection, selectionArgs) | ||||
|                         operations.add(this.build()) | ||||
|                         operations.add(build()) | ||||
|                     } | ||||
|                     contactIDs.add(it.id.toString()) | ||||
|                 } | ||||
|  | ||||
|                 activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations) | ||||
|   | ||||
| @@ -119,6 +119,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont | ||||
|     fun deleteContact(id: Int) = deleteContacts(arrayOf(id.toString())) | ||||
|  | ||||
|     fun deleteContacts(ids: Array<String>) { | ||||
|         if (ids.isEmpty()) { | ||||
|             return | ||||
|         } | ||||
|  | ||||
|         val args = TextUtils.join(", ", ids) | ||||
|         val selection = "$CONTACTS_TABLE_NAME.$COL_ID IN ($args)" | ||||
|         mDb.delete(CONTACTS_TABLE_NAME, selection, null) | ||||
|   | ||||
| @@ -12,6 +12,7 @@ data class Contact(val id: Int, var prefix: String, var firstName: String, var m | ||||
|     companion object { | ||||
|         var sorting = 0 | ||||
|         var startWithSurname = false | ||||
|         val pattern = "\\D+".toRegex() | ||||
|     } | ||||
|  | ||||
|     override fun compareTo(other: Contact): Int { | ||||
| @@ -81,4 +82,10 @@ data class Contact(val id: Int, var prefix: String, var firstName: String, var m | ||||
|             fullName | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     fun getHashToCompare(): Int { | ||||
|         val newPhoneNumbers = ArrayList<PhoneNumber>() | ||||
|         phoneNumbers.mapTo(newPhoneNumbers, { PhoneNumber(it.value.replace(pattern, ""), 0) }) | ||||
|         return copy(id = 0, phoneNumbers = newPhoneNumbers).hashCode() | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user