From dcc2490f865bbb68ae14bc755cf79b7b8b68a6cd Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 28 Dec 2018 15:30:22 +0100 Subject: [PATCH] change the way contacts are fetched, use type blacklist instead of whitelist --- .../contacts/pro/helpers/ContactsHelper.kt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt index 8a14f930..b861565c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt @@ -125,10 +125,12 @@ class ContactsHelper(val context: Context) { return } + val ignoredSources = context.config.ignoredContactSources val uri = ContactsContract.Data.CONTENT_URI val projection = getContactProjection() - val selection = getSourcesSelection(true) - val selectionArgs = getSourcesSelectionArgs(CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE) + + val selection = "${ContactsContract.Data.MIMETYPE} = ?" + val selectionArgs = arrayOf(CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE) val sortOrder = getSortString() var cursor: Cursor? = null @@ -136,6 +138,11 @@ class ContactsHelper(val context: Context) { cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, sortOrder) if (cursor?.moveToFirst() == true) { do { + val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) ?: "" + if (ignoredSources.contains(accountName)) { + continue + } + val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID) val prefix = cursor.getStringValue(CommonDataKinds.StructuredName.PREFIX) ?: "" val firstName = cursor.getStringValue(CommonDataKinds.StructuredName.GIVEN_NAME) ?: "" @@ -148,7 +155,6 @@ class ContactsHelper(val context: Context) { val emails = ArrayList() val addresses = ArrayList
() val events = ArrayList() - val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) ?: "" val starred = cursor.getIntValue(CommonDataKinds.StructuredName.STARRED) val contactId = cursor.getIntValue(ContactsContract.Data.CONTACT_ID) val thumbnailUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: "" @@ -839,9 +845,6 @@ class ContactsHelper(val context: Context) { accounts.forEach { if (ContentResolver.getIsSyncable(it, ContactsContract.AUTHORITY) == 1) { val contactSource = ContactSource(it.name, it.type) - if (it.type == TELEGRAM_PACKAGE) { - contactSource.name += " (${context.getString(R.string.telegram)})" - } sources.add(contactSource) } }