Skip to content

Commit dcc2490

Browse files
committed
change the way contacts are fetched, use type blacklist instead of whitelist
1 parent 14478e7 commit dcc2490

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,24 @@ class ContactsHelper(val context: Context) {
125125
return
126126
}
127127

128+
val ignoredSources = context.config.ignoredContactSources
128129
val uri = ContactsContract.Data.CONTENT_URI
129130
val projection = getContactProjection()
130-
val selection = getSourcesSelection(true)
131-
val selectionArgs = getSourcesSelectionArgs(CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
131+
132+
val selection = "${ContactsContract.Data.MIMETYPE} = ?"
133+
val selectionArgs = arrayOf(CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
132134
val sortOrder = getSortString()
133135

134136
var cursor: Cursor? = null
135137
try {
136138
cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, sortOrder)
137139
if (cursor?.moveToFirst() == true) {
138140
do {
141+
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) ?: ""
142+
if (ignoredSources.contains(accountName)) {
143+
continue
144+
}
145+
139146
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
140147
val prefix = cursor.getStringValue(CommonDataKinds.StructuredName.PREFIX) ?: ""
141148
val firstName = cursor.getStringValue(CommonDataKinds.StructuredName.GIVEN_NAME) ?: ""
@@ -148,7 +155,6 @@ class ContactsHelper(val context: Context) {
148155
val emails = ArrayList<Email>()
149156
val addresses = ArrayList<Address>()
150157
val events = ArrayList<Event>()
151-
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) ?: ""
152158
val starred = cursor.getIntValue(CommonDataKinds.StructuredName.STARRED)
153159
val contactId = cursor.getIntValue(ContactsContract.Data.CONTACT_ID)
154160
val thumbnailUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: ""
@@ -839,9 +845,6 @@ class ContactsHelper(val context: Context) {
839845
accounts.forEach {
840846
if (ContentResolver.getIsSyncable(it, ContactsContract.AUTHORITY) == 1) {
841847
val contactSource = ContactSource(it.name, it.type)
842-
if (it.type == TELEGRAM_PACKAGE) {
843-
contactSource.name += " (${context.getString(R.string.telegram)})"
844-
}
845848
sources.add(contactSource)
846849
}
847850
}

0 commit comments

Comments
 (0)