Filtering has to be done on the basis of Multiple attributes such as Location, Preferred Gender, etc. For this, I have used Firebase database as my backend. I am fetching data accordingly using a query string such as,
fun populateItems()
{
if (noUsersLayout == null) {
progressLayout.visibility = View.VISIBLE
}
noUsersLayout.visibility = View.GONE
progressLayout.visibility = View.VISIBLE
val cardsQuery = userDatabase.orderByChild(DATA_LOCATION).equalTo(location)
cardsQuery.addListenerForSingleValueEvent(object : ValueEventListener {
override fun onCancelled(p0: DatabaseError) {
}
override fun onDataChange(p0: DataSnapshot) {
p0.children.forEach { child ->
val user = child.getValue(User::class.java)
var showUser = true
if (child.child(DATA_SWIPES_LEFT).hasChild(userId) ||
child.child(DATA_SWIPES_RIGHT).hasChild(userId) ||
child.child(DATA_MATCHES).hasChild(userId)){
showUser = false
}
if (showUser) {
rowItems.add(user!!)
cardsAdapter?.notifyDataSetChanged()
}
progressLayout.visibility = View.GONE
if (rowItems.isEmpty()) {
noUsersLayout.visibility = View.VISIBLE
}
}
}
})
So how can I add multiple queries to this statement? i.e.
val cardsQuery = userDatabase.orderByChild(DATA_LOCATION).equalTo(location)
along with userDatabase.orderByChild(DATA_GENDER).equalTo(preferredGender)
I have tried using .also{}
and .with{}
but it didn't work.