Reputation: 163
I`m using FirestoreRecyclerAdapter and faced with the problem.
Query query = db
.collection(SOME_COLLECTION)
.whereEqualTo("key", key)
.orderBy("dueDate");
If I put orderBy, data loaded just first time. Real time updates not working. I tried putting orderBy at the end, as well as changing ordering fields.
If I remove orderBy, all works well. But no ordering.
According to documentation it should work when not using range comparison. Any ideas?
Updated. Here is adapter options.
FirestoreRecyclerOptions<Payment> options =
new FirestoreRecyclerOptions.Builder<Payment>()
.setQuery(query, Payment.class)
.build();
Here is Payment.
public class Payment {
private String key;
private double amount;
private Date cDate;
private Date paidDate;
private Date dueDate;
private boolean isPaid;
public Payment() {
}
Payment(String key, double amount, Date cDate, Date paidDate, Date dueDate, boolean isPaid) {
this.key = key;
this.amount = amount;
this.cDate = cDate;
this.paidDate = paidDate;
this.dueDate = dueDate;
this.isPaid = isPaid;
}
}
Here is Payment Holder.
class PaymentHolder extends RecyclerView.ViewHolder {
private TextView pDate, pAmount;
private CheckBox pDone;
PaymentHolder(View itemView) {
super(itemView);
pDate = itemView.findViewById(R.id.pDate);
pAmount = itemView.findViewById(R.id.pAmount);
pDone = itemView.findViewById(R.id.checkBox);
}}
And here is adapter.
firestoreRecyclerAdapter = new FirestoreRecyclerAdapter<Payment, PaymentHolder>(options) {
@Override
protected void onBindViewHolder(final PaymentHolder paymentHolder, final int position, final Payment payment) {
final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
final String id = getSnapshots().getSnapshot(position).getId();
paymentHolder.getpDate().setText(dateFormat.format(payment.getDueDate()));
paymentHolder.getpAmount().setText(getAmount(payment.getAmount()));
paymentHolder.getpDone().setChecked(payment.isPaid());
}
@Override
public PaymentHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.payment_item, viewGroup, false);
final PaymentHolder paymentHolder = new PaymentHolder(view);
return paymentHolder;
}
};
recyclerView.setAdapter(firestoreRecyclerAdapter);
All set accorting to examples, nothing fancy.
Upvotes: 2
Views: 632
Reputation: 163
As Frank said, you should create index. If you look more precise at log, there is a warning and a link to create index. Just click on link and that is it. Big brother creates right index for you. Thank you Frank.
Upvotes: 4