I have no issue sorting my database in descending order by using orderbychild(-timestamp) in firebaseRecycleradapter.
final FirebaseRecyclerAdapter<UserChat, BlogViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<UserChat, BlogViewHolder>(
UserChat.class,
R.layout.userchatrow,
BlogViewHolder.class,
mUserChatList.child(mAuth.getCurrentUser().getUid()).child("UserList").orderByChild("negatedtime")
//descending order
) {
However, when user is logged out using Auth.getinstance.signOut and LoginManager.getinstance.logOut, then log in again (either facebook, google or email), firebase database can no longer fetching latest result via orderbychild(-timestamp). When I deleted orderbychild(-timestamp), it can retrieve the latest result, but in ascending order which is not I want.
final FirebaseRecyclerAdapter<UserChat, BlogViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<UserChat, BlogViewHolder>(
UserChat.class,
R.layout.userchatrow,
BlogViewHolder.class,
mUserChatList.child(mAuth.getCurrentUser().getUid()).child("UserList")
//ascending order
) {
I can't reverse the LayoutManager nor RecyclerView, or the other approaches such as reversing the ArrayList order as suggested here as the key is not a push ID, the only way to sort to the latest is by orderbychild(-timestamp).
I did not use setPersistenceEnable and keepSynced, so as not to cache any memory on user phone, but to no avail.
Any helps?