Last active
September 19, 2021 09:50
-
-
Save a914-gowtham/5df0f46de74e26cf1a073e1191b5fa71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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