Skip to content

Commit aeed7e2

Browse files
committed
fix #235, rely on both account name and type at filtering
1 parent cfa9bda commit aeed7e2

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/FilterContactSourcesDialog.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ class FilterContactSourcesDialog(val activity: SimpleActivity, private val callb
4141

4242
private fun confirmEventTypes() {
4343
val selectedContactSources = (view.filter_contact_sources_list.adapter as FilterContactSourcesAdapter).getSelectedContactSources()
44-
val ignoredContactSourceNames = contactSources.filter { !selectedContactSources.contains(it) }.map {
45-
if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.name
44+
val ignoredContactSources = contactSources.filter { !selectedContactSources.contains(it) }.map {
45+
if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.getFullIdentifier()
4646
}.toHashSet()
4747

48-
if (activity.getVisibleContactSources() != ignoredContactSourceNames) {
49-
activity.config.ignoredContactSources = ignoredContactSourceNames
48+
if (activity.getVisibleContactSources() != ignoredContactSources) {
49+
activity.config.ignoredContactSources = ignoredContactSources
5050
callback()
5151
}
5252
dialog?.dismiss()

app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,9 @@ fun Context.getVisibleContactSources(): ArrayList<String> {
308308
val sources = ContactsHelper(this).getDeviceContactSources()
309309
val phoneSecret = getString(R.string.phone_storage_hidden)
310310
sources.add(ContactSource(phoneSecret, SMT_PRIVATE, phoneSecret))
311-
val sourceNames = ArrayList(sources).map { if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.name }.toMutableList() as ArrayList<String>
312-
sourceNames.removeAll(config.ignoredContactSources)
311+
val ignoredContactSources = config.ignoredContactSources
312+
val sourceNames = ArrayList(sources).filter { !ignoredContactSources.contains(it.getFullIdentifier()) }
313+
.map { if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.name }.toMutableList() as ArrayList<String>
313314
return sourceNames
314315
}
315316

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ class ContactsHelper(val context: Context) {
144144
if (cursor?.moveToFirst() == true) {
145145
do {
146146
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) ?: ""
147-
if (ignoredSources.contains(accountName)) {
147+
val accountType = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_TYPE) ?: ""
148+
if (ignoredSources.contains("$accountName:$accountType")) {
148149
continue
149150
}
150151

@@ -884,7 +885,8 @@ class ContactsHelper(val context: Context) {
884885
CommonDataKinds.StructuredName.PHOTO_URI,
885886
CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI,
886887
CommonDataKinds.StructuredName.STARRED,
887-
ContactsContract.RawContacts.ACCOUNT_NAME
888+
ContactsContract.RawContacts.ACCOUNT_NAME,
889+
ContactsContract.RawContacts.ACCOUNT_TYPE
888890
)
889891

890892
private fun getSortString(): String {
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
package com.simplemobiletools.contacts.pro.models
22

3-
data class ContactSource(var name: String, var type: String, var publicName: String)
3+
import com.simplemobiletools.contacts.pro.helpers.SMT_PRIVATE
4+
5+
data class ContactSource(var name: String, var type: String, var publicName: String) {
6+
fun getFullIdentifier(): String {
7+
return if (type == SMT_PRIVATE) {
8+
type
9+
} else {
10+
"$name:$type"
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)