正如我的标题所述,我正在尝试按顺序加载我的帖子。即:新帖子优先。但是,当我添加新帖子时,它将转到最后。其余的一切都井井有条。当我重新启动应用程序时,它会恢复原位。这是我的代码:
String userId=firebaseAuth.getCurrentUser().getUid();
if(firebaseAuth.getCurrentUser()!=null) {
firebaseFirestore = FirebaseFirestore.getInstance();
Query firstQuery=firebaseFirestore.collection("Timeline").document(userId).collection("Posts").orderBy("timestamp",Query.Direction.DESCENDING);
firstQuery.addSnapshotListener(getActivity(),new EventListener<QuerySnapshot>() {
@Override
public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {
for (DocumentChange doc : documentSnapshots.getDocumentChanges()) {
if (doc.getType() == DocumentChange.Type.ADDED) {
String blogPostId=doc.getDocument().getId();
BlogPost blogPost = doc.getDocument().toObject(BlogPost.class).withId(blogPostId);
blogList.add(blogPost);
blogRecyclerAdapter.notifyDataSetChanged();
}
}
}
});
}