0

I'm trying to reload or update Firestore Recyclerview Adapter (Firebase Ui) based upon field value changes.

In my case I'm querying .whereNotIn("id", list) where list is stored locally and updated frequently which should trigger firestore recyclerview options based upon arraylist value updated.

My code is below:

 postsRef
                .orderBy("id")
                .whereNotIn("id", list) // list is updated frequently so update firesttore recyclervew option
                .whereEqualTo("disabled", false)
                .whereEqualTo("expired", false)
                .whereEqualTo("locality", locality)
                .whereEqualTo("country", country)
                .orderBy("createdAt", Query.Direction.DESCENDING)
                .limit(20)

        val firestoreRecyclerOptions: FirestoreRecyclerOptions<Post> =
            FirestoreRecyclerOptions.Builder<Post>()
                .setQuery(query, Post::class.java)
                .build()

"list" value is changes locally frequently. I want to update firestore RecyclerView options maybe reload based upon list update.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Fortray
  • 133
  • 1
  • 1
  • 8
  • So what's wrong with this code? Have you created an [index](https://stackoverflow.com/questions/50305328/firestore-whereequalto-orderby-and-limit1-not-working)? – Alex Mamo Apr 18 '22 at 12:42
  • I'm storing ArrayList value as list locally which is used to query database. Firestore trigger based upon database changes. But I want to update Firestore Recyclerview options based upon local list is updated frequently without recreating Fragment. Yes I have created an index. – Fortray Apr 18 '22 at 12:48

1 Answers1

0

The list is updated as the data in the table is updated.

The code I wrote for myself, you can change it according to you.

docRef
                    .whereEqualTo(field, equel)
                    .whereEqualTo(cevapField, cevapdurum)
                    .orderBy("date",query)
                    .addSnapshotListener { querySnapshot, firebaseFirestoreException ->
                        firebaseFirestoreException?.let {
                            Toast.makeText(context, it.message, Toast.LENGTH_LONG)
                                .show()
                           //error
                            return@addSnapshotListener
                        }
                        val listData: MutableList<Any> = mutableListOf()
                        querySnapshot?.let {
                            for (document in it) {
                               //success
                                val data1=document.getString("data1")
                        }
                    }