Skip to content

Instantly share code, notes, and snippets.

@a914-gowtham
Last active September 19, 2021 09:50
Show Gist options
  • Save a914-gowtham/5df0f46de74e26cf1a073e1191b5fa71 to your computer and use it in GitHub Desktop.
Save a914-gowtham/5df0f46de74e26cf1a073e1191b5fa71 to your computer and use it in GitHub Desktop.
interface QueryListener{
fun onCompleted(queriedList: ArrayList<UserProfile>)
fun onStart(position: Int,contactBatch: ArrayList<String>)
}
class ContactsQuery{
companion object{
var queriedList=ArrayList<UserProfile>()
var currentQueryCount=0
var totalQueryCount=0
}
private val usersCollection = FirebaseFirestore.getInstance().collection("Users")
fun makeQuery(position: Int,listOfMobile: ArrayList<String>,listener: QueryListener) {
try {
listener.onStart(position,listOfMobile)
usersCollection.whereIn("mobile.number", listOfMobile).get()
.addOnSuccessListener { documents ->
for (document in documents) {
val contact = document.toObject(UserProfile::class.java)
queriedList.add(contact)
}
currentQueryCount += 1
if(currentQueryCount == totalQueryCount)
listener.onCompleted(queriedList)
}
.addOnFailureListener { exception ->
Timber.wtf("Error: ${exception.message}")
currentQueryCount += 1
if(currentQueryCount == totalQueryCount)
listener.onCompleted(queriedList)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment