timigod/android-chat-ui

New messages add to the bottom of the list (I provided the solution, can you please implement?)

Opened this issue · 6 comments

can you add the below method to be able to pass in an index so that the messages load to the back of the list?

addAll(int index, ArrayList chatMessages){
this.chatMessages.addAll(index, chatMessages);
notifyDataSetChanged();
}

(beautiful UI by the way, thanks so much)

Here is my ugly ugly solution but it is what it is until the implementation of the code above:

  1. create this object:
    private List<List> messagesGroupsByPage = = new ArrayList<List>();
  2. add the messages to the group
    messagesGroupsByPage.add(pageGroup-1, response.body().getMessages());
  3. clear the actual list before readding
    chatView.clearMessages();
  4. add
    for (int i1 = 0; i1<pageGroup ; i1++){
    chatView.addMessages(chatMessageArrayListConverter(messagesGroupsByPage.get(pageGroup-1-i1)));
    }
  5. scroll to position and:
    pageNumber++

timigod, again we are all thankful and will be more thankful for the improvement

Hi @ousanmazCT, can you please clarify what exactly you're trying to achieve. I'm having a hard time understanding the problem

Yeah sorry, I realize I didn't explain why I ask for this feature.

Right now, when I do a request to get past messages, I receive 10 messages from the server.

I do the first request, all is fine. Now I have 10 messages on the UI.

I do the second request for another set of 10 messages and they are added to the bottom of the list (at index 0). I would like to be able to add them to the top so that when user is scrolling, more messages display.

(how is this explanation?)

Thanks. This is much clearer.

I think what we should be doing in this case is creating a new list from the old and new lists and passing it to ChatView because I can see how mutating the internal list in this way can introduce bugs. I think adding a method to swap the lists would create the flexibility to achieve this.

What do you think?

I think that is fine but my only concern would be the UI. When we reset the list, and when I say reset I mean replacing the old list with a new one, the UI will want to reset itself as well.

If UI wants to reset, instead of the scroll bar staying where it is, it is going to reset and go all the way to the begining, therefore not a smooth experience.

This is the ugly code I implemented at the moment. I am replacing the old list with a new one and it is resetting the UI, making the scroll bar go all the way down to the beginning.

This is why I believe adding the new set of messages to the end of the messagesList (of ChatView) is a better option.

What do you think? I don't know if the current code will accommodate appending the new messages to the end of the list.

Let's try it out and evaluate the options.
We'll most likely have to switch to RecyclerView so we can achieve a smoother experience.
Can you please create a pull request with the proposed fix and the we'll go from there.