I am learning about Firebase Firestore through official documentation. I was trying following code. Notifications are added using add() method of firestore.
FirebaseFirestore.getInstance().colRefNotifications()
.orderBy("timestamp", Query.Direction.DESCENDING)
.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot documentSnapshots) {
if (!documentSnapshots.isEmpty()){
listNotifications.clear();
recyclerViewNotification.removeAllViews();
for (DocumentSnapshot data : documentSnapshots){
Notification notification = data.toObject(Notification.class);
listNotifications.add(notification);
}
notificationGeneralAdapter.notifyDataSetChanged();
}
}
});
Notification.java
private String text;
private String key;
private Date timestamp;
public Notification() {
}
public Notification(String text, String key, Date timestamp) {
this.text = text;
this.key = key;
this.timestamp = timestamp;
}
public String getText() {
return text;
}
public String getKey() {
return key;
}
public Date getTimestamp() {
return timestamp;
}
Firestore
I am ordering notifications by timestamp in descending direction. But, as you can see in the following snapshot, it is not showing desired output.
What am I doing wrong? Thank you for your help.