Why recyclerview syncing with Firestore does not update correctly ordering by ServerTimeStamp?

时间:2019-04-16 22:29:59

标签: java android google-cloud-firestore

if I order the query by the date of the ServerTimeStamp, firestore recyclerview does not update if a document is deleted on Firestore even after restarting the app.

Following code does not work if it is orderBy("date", Query.Direction.DESCENDING)

Query query = FirebaseFirestore.getInstance()
            .collection("Ventas "+mes+"-"+ano)
            .whereEqualTo("dia", d)
            .orderBy("date", Query.Direction.DESCENDING);
    FirestoreRecyclerOptions<PojoVenta> opciones = new FirestoreRecyclerOptions
            .Builder<PojoVenta>().setQuery(query, PojoVenta.class).build();
    adaptador = new AdaptadorVentasRegistradas(opciones);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(adaptador);

THIS CODE WORKS AS EXPECTED. I delete a document manually on Firestore, the recyclerview updates correctly.

Query query = FirebaseFirestore.getInstance()
            .collection("Ventas "+mes+"-"+ano)
            .whereEqualTo("dia", d)
            .orderBy("dia", Query.Direction.ASCENDING)
            .orderBy("minuto", Query.Direction.ASCENDING);
    FirestoreRecyclerOptions<PojoVenta> opciones = new FirestoreRecyclerOptions
            .Builder<PojoVenta>().setQuery(query, PojoVenta.class).build();
    adaptador = new AdaptadorVentasRegistradas(opciones);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(adaptador);

0 个答案:

没有答案