Switching Firestore query

I have 2 queries that fetch data from the firestore. The first one executes when the adapter item count is 0

 query = collectionReference.orderBy("Places", Query.Direction.DESCENDING);

and another one that is executed if it exists in my firestore database.

 query = collectionReference.whereEqualTo(Constants.SEARCH_QUERY, Constants.CURRENT_CITY);

and I also have onDataChange method in my Firestore adapter that will get the total item count based on the query that executed.

TOTAL_ITEM = getItemCount();

now on my options, it looks like this

        public FirestoreRecyclerOptions<PlacesModel> options(){
           if (Constants.TOTAL_ITEM == 0) {
           query = collectionReference.orderBy("Places", Query.Direction.DESCENDING);
           } else {
             query = collectionReference.whereEqualTo(Constants.SEARCH_QUERY, Constants.CURRENT_CITY);
            return new FirestoreRecyclerOptions.Builder<PlacesModel>()
            .setQuery(query, PlacesModel.class)

and this is my adapter

adapter = new PlacesAdapter(placesViewModel.options());

The adapter is working fine if the value exists in my firestore database. But the problem is when I tried to search for a place that does not exist in the firestore database, It should execute my first query but it doesn't. That's why I need to initialize the adapter again to update my recyclerview based on my first query. What I want to achieve is to be dynamic. Like, when I search and it returns nothing, it will automatically update my recyclerview based on my first query .

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum