0

I have a simple chat activity built using FirebaseRecyclerAdapter where each view is a message. I'd like to support a typing indicator that visually looks like an additional message.

My first thought was to add a footer view to the recycler adapter by following instructions similar to Android 5.0 - Add header/footer to a RecyclerView. However, I can't figure out how to insert and remove the special type of view when using a FirebaseIndexRecyclerAdapter.

My code:

    // setting up the recycler view adapter
    mAdapter = new FirebaseIndexRecyclerAdapter<ChatMessage, MessageHolder>(
            ChatMessage.class,
            R.layout.chat_message_item,
            MessageHolder.class,
            keyRef,
            dataRef) {
        @Override
        public void populateViewHolder(final MessageHolder chatViewHolder, final ChatMessage chatMessage, final int position) {
            Log.d(TAG, chatMessage.toString());
            chatViewHolder.setMessage(chatMessage.getText());
        }
    };
    recyclerView.setAdapter(mAdapter);
Community
  • 1
  • 1
Andrew Stromme
  • 2,120
  • 23
  • 30
  • Does this header or footer item also come from the database, within the Query in the correct position relative to the other items in the Query? – Doug Stevenson Jan 05 '17 at 02:07
  • Currently my database has a /chats/$chat_id/messages/$message_id and a separate /chats/$chat_id/typing_indicators/$user_id. I *could* create a special type of message that was a typing indicator. If I did this, then how would I filter out this special message for the user who is doing the typing? And how would I ensure that it was pinned to the bottom? My message IDs are just keys, the timestamp of the message is in /messages/$message_id/timestamp – Andrew Stromme Jan 06 '17 at 00:26
  • You'd have to be able to generate a single query with all the items, including the footer in the correct location, and have a way to manipulate the views in that last item to appear the way you want. It won't be terribly easy. FirebaseRecyclerAdapter simply doesn't directly support what you're trying to do. It might be easier to modify it so that it does. – Doug Stevenson Jan 06 '17 at 01:43

0 Answers0