Firestore chat app using Firebase-UI (Android)

后端 未结 1 1122
深忆病人
深忆病人 2021-01-13 06:58

I am trying to create a chat using the Firebase-UI library for Cloud Firestore. This github repository contains the relevant code which I am using. The problem comes with th

相关标签:
1条回答
  • 2021-01-13 07:31

    To solve this, you can use the following query:

    Query sChatQuery = sChatCollection
        .orderBy("timestamp", Query.Direction.ASCENDING)
        .whereGreaterThanOrEqualTo("timestamp', desiredTime)
        .limit(50);
    

    If you are using a RecyclerView to display data, the simplest way would be to use the following code:

    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    layoutManager.setReverseLayout(true);
    layoutManager.setStackFromEnd(true);
    recyclerView.setLayoutManager(layoutManager);
    

    This approch will reverse you the order as you want.

    Another approach would be to create your own adapter that extends FirebaseListAdapter and override getItem() method like this:

    @Override
    public HashMap getItem(int pos) {
        return super.getItem(getCount() - 1 - pos);
    }
    

    Another approach would be to get the data from the database, add it to a Collection, a List would be a good solution and then use Collections.reverse(yourList);.

    0 讨论(0)
提交回复
热议问题