fix #444, #376, properly show Organization type contacts

This commit is contained in:
tibbi 2019-10-28 17:03:17 +01:00
parent 4d63dc06c3
commit 653d5fcd8c

View File

@ -67,7 +67,7 @@ class ContactsHelper(val context: Context) {
} }
if (ignoredContactSources.isEmpty() && !getAll) { if (ignoredContactSources.isEmpty() && !getAll) {
tempContacts.filter { displayContactSources.contains(it.source) }.groupBy { it.getNameToDisplay().toLowerCase()}.values.forEach { it -> tempContacts.filter { displayContactSources.contains(it.source) }.groupBy { it.getNameToDisplay().toLowerCase() }.values.forEach { it ->
if (it.size == 1) { if (it.size == 1) {
resultContacts.add(it.first()) resultContacts.add(it.first())
} else { } else {
@ -143,8 +143,8 @@ class ContactsHelper(val context: Context) {
val uri = ContactsContract.Data.CONTENT_URI val uri = ContactsContract.Data.CONTENT_URI
val projection = getContactProjection() val projection = getContactProjection()
val selection = "${ContactsContract.Data.MIMETYPE} = ?" val selection = "${ContactsContract.Data.MIMETYPE} = ? OR ${ContactsContract.Data.MIMETYPE} = ?"
val selectionArgs = arrayOf(CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE) val selectionArgs = arrayOf(CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE, CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
val sortOrder = getSortString() val sortOrder = getSortString()
var cursor: Cursor? = null var cursor: Cursor? = null
@ -788,14 +788,14 @@ class ContactsHelper(val context: Context) {
return LocalContactsHelper(context).getContactWithId(id) return LocalContactsHelper(context).getContactWithId(id)
} }
val selection = "${ContactsContract.Data.MIMETYPE} = ? AND ${ContactsContract.Data.RAW_CONTACT_ID} = ?" val selection = "(${ContactsContract.Data.MIMETYPE} = ? OR ${ContactsContract.Data.MIMETYPE} = ?) AND ${ContactsContract.Data.RAW_CONTACT_ID} = ?"
val selectionArgs = arrayOf(CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE, id.toString()) val selectionArgs = arrayOf(CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE, CommonDataKinds.Organization.CONTENT_ITEM_TYPE, id.toString())
return parseContactCursor(selection, selectionArgs) return parseContactCursor(selection, selectionArgs)
} }
fun getContactWithLookupKey(key: String): Contact? { fun getContactWithLookupKey(key: String): Contact? {
val selection = "${ContactsContract.Data.MIMETYPE} = ? AND ${ContactsContract.Data.LOOKUP_KEY} = ?" val selection = "(${ContactsContract.Data.MIMETYPE} = ? OR ${ContactsContract.Data.MIMETYPE} = ?) AND ${ContactsContract.Data.LOOKUP_KEY} = ?"
val selectionArgs = arrayOf(CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE, key) val selectionArgs = arrayOf(CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE, CommonDataKinds.Organization.CONTENT_ITEM_TYPE, key)
return parseContactCursor(selection, selectionArgs) return parseContactCursor(selection, selectionArgs)
} }
@ -912,8 +912,8 @@ class ContactsHelper(val context: Context) {
private fun getRealContactId(id: Long): Int { private fun getRealContactId(id: Long): Int {
val uri = ContactsContract.Data.CONTENT_URI val uri = ContactsContract.Data.CONTENT_URI
val projection = getContactProjection() val projection = getContactProjection()
val selection = "${ContactsContract.Data.MIMETYPE} = ? AND ${ContactsContract.Data.RAW_CONTACT_ID} = ?" val selection = "(${ContactsContract.Data.MIMETYPE} = ? OR ${ContactsContract.Data.MIMETYPE} = ?) AND ${ContactsContract.Data.RAW_CONTACT_ID} = ?"
val selectionArgs = arrayOf(CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE, id.toString()) val selectionArgs = arrayOf(CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE, CommonDataKinds.Organization.CONTENT_ITEM_TYPE, id.toString())
var cursor: Cursor? = null var cursor: Cursor? = null
try { try {
cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null) cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null)