alexstyl / contactstore

A modern, strongly-typed contacts API for Android.
https://alexstyl.github.io/contactstore
Apache License 2.0
440 stars 15 forks source link

Get Contact with Filter (LIKE Query) #4

Closed nauhalf closed 3 years ago

nauhalf commented 3 years ago

I didn't find any document about filtering contact with LIKE keyword, like the content resolver has. Is it filterable ?

alexstyl commented 3 years ago

Hi @nauhalf. This is not something that is currently supported.

I am asuming that you are refering to the Contacts#CONTENT_FILTER_URI, is that correct?

nauhalf commented 3 years ago

Like this image

NLLAPPS commented 3 years ago

I am just chipping in as I recently started following this repo and have high hopes of it :)

Some content resolvers have limits on params. For example LIMIT is not allowed but not sure about LIKE. Also, there might be performance issues if user has too many contacts. Some people have thousands of contacts. I would prefer CONTENT_FILTER_URI being used as it seems to be the official way.

alexstyl commented 3 years ago

+1 for the CONTENT_FILTER_URI approach. If someone really wants/needs to manipulate SQL queries they still have the ContentProviders API to their disposal.

AFAIK such URIs tend to be highly optimised according to the docs, so doing multiple queries shouldn't be expensive.

I think that something like:

            combine(
                contactStore.fetchContacts(PhoneLookup(PhoneNumber(keyword))),
                contactStore.fetchContacts(NameLookup(keyword)) // <- not supported right now
            ) { fromPhones, fromNames ->
                // do any processing to the results you like
                fromPhones + fromNames
            }.collect { results ->
                println("Contacts matching $keyword were = $results")
            }

would work well for @nauhalf 's case.

alexstyl commented 3 years ago

Quick update on this. I am planning of having this shipped this weekend with v0.2.0

alexstyl commented 3 years ago

Name lookup is now available in 0.2.0

https://github.com/alexstyl/contactstore/releases/tag/0.2.0