fix #235, rely on both account name and type at filtering

This commit is contained in:
tibbi
2018-12-28 17:44:14 +01:00
parent cfa9bdaf7a
commit aeed7e2456
4 changed files with 22 additions and 9 deletions

View File

@ -41,12 +41,12 @@ class FilterContactSourcesDialog(val activity: SimpleActivity, private val callb
private fun confirmEventTypes() { private fun confirmEventTypes() {
val selectedContactSources = (view.filter_contact_sources_list.adapter as FilterContactSourcesAdapter).getSelectedContactSources() val selectedContactSources = (view.filter_contact_sources_list.adapter as FilterContactSourcesAdapter).getSelectedContactSources()
val ignoredContactSourceNames = contactSources.filter { !selectedContactSources.contains(it) }.map { val ignoredContactSources = contactSources.filter { !selectedContactSources.contains(it) }.map {
if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.name if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.getFullIdentifier()
}.toHashSet() }.toHashSet()
if (activity.getVisibleContactSources() != ignoredContactSourceNames) { if (activity.getVisibleContactSources() != ignoredContactSources) {
activity.config.ignoredContactSources = ignoredContactSourceNames activity.config.ignoredContactSources = ignoredContactSources
callback() callback()
} }
dialog?.dismiss() dialog?.dismiss()

View File

@ -308,8 +308,9 @@ fun Context.getVisibleContactSources(): ArrayList<String> {
val sources = ContactsHelper(this).getDeviceContactSources() val sources = ContactsHelper(this).getDeviceContactSources()
val phoneSecret = getString(R.string.phone_storage_hidden) val phoneSecret = getString(R.string.phone_storage_hidden)
sources.add(ContactSource(phoneSecret, SMT_PRIVATE, phoneSecret)) sources.add(ContactSource(phoneSecret, SMT_PRIVATE, phoneSecret))
val sourceNames = ArrayList(sources).map { if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.name }.toMutableList() as ArrayList<String> val ignoredContactSources = config.ignoredContactSources
sourceNames.removeAll(config.ignoredContactSources) val sourceNames = ArrayList(sources).filter { !ignoredContactSources.contains(it.getFullIdentifier()) }
.map { if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.name }.toMutableList() as ArrayList<String>
return sourceNames return sourceNames
} }

View File

@ -144,7 +144,8 @@ class ContactsHelper(val context: Context) {
if (cursor?.moveToFirst() == true) { if (cursor?.moveToFirst() == true) {
do { do {
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) ?: "" val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) ?: ""
if (ignoredSources.contains(accountName)) { val accountType = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_TYPE) ?: ""
if (ignoredSources.contains("$accountName:$accountType")) {
continue continue
} }
@ -884,7 +885,8 @@ class ContactsHelper(val context: Context) {
CommonDataKinds.StructuredName.PHOTO_URI, CommonDataKinds.StructuredName.PHOTO_URI,
CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI, CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI,
CommonDataKinds.StructuredName.STARRED, CommonDataKinds.StructuredName.STARRED,
ContactsContract.RawContacts.ACCOUNT_NAME ContactsContract.RawContacts.ACCOUNT_NAME,
ContactsContract.RawContacts.ACCOUNT_TYPE
) )
private fun getSortString(): String { private fun getSortString(): String {

View File

@ -1,3 +1,13 @@
package com.simplemobiletools.contacts.pro.models package com.simplemobiletools.contacts.pro.models
data class ContactSource(var name: String, var type: String, var publicName: String) import com.simplemobiletools.contacts.pro.helpers.SMT_PRIVATE
data class ContactSource(var name: String, var type: String, var publicName: String) {
fun getFullIdentifier(): String {
return if (type == SMT_PRIVATE) {
type
} else {
"$name:$type"
}
}
}