scroll fixes

This commit is contained in:
iNPUTmice 2014-09-19 21:09:54 +02:00
parent 1d23c7e7fb
commit c282ef4645
2 changed files with 11 additions and 10 deletions

View File

@ -820,14 +820,14 @@ public class XmppConnectionService extends Service {
}); });
} }
public List<Message> getMoreMessages(Conversation conversation, public int loadMoreMessages(Conversation conversation, long timestamp) {
long timestamp) {
List<Message> messages = databaseBackend.getMessages(conversation, 50, List<Message> messages = databaseBackend.getMessages(conversation, 50,
timestamp); timestamp);
for (Message message : messages) { for (Message message : messages) {
message.setConversation(conversation); message.setConversation(conversation);
} }
return messages; conversation.getMessages().addAll(0, messages);
return messages.size();
} }
public List<Account> getAccounts() { public List<Account> getAccounts() {

View File

@ -165,14 +165,15 @@ public class ConversationFragment extends Fragment {
if (firstVisibleItem == 0 && messagesLoaded) { if (firstVisibleItem == 0 && messagesLoaded) {
long timestamp = messageList.get(0).getTimeSent(); long timestamp = messageList.get(0).getTimeSent();
messagesLoaded = false; messagesLoaded = false;
List<Message> messages = activity.xmppConnectionService int size = activity.xmppConnectionService.loadMoreMessages(
.getMoreMessages(conversation, timestamp); conversation, timestamp);
messageList.addAll(0, messages); messageList.clear();
messageList.addAll(conversation.getMessages());
messageListAdapter.notifyDataSetChanged(); messageListAdapter.notifyDataSetChanged();
if (messages.size() != 0) { if (size != 0) {
messagesLoaded = true; messagesLoaded = true;
} }
messagesView.setSelectionFromTop(messages.size() + 1, 0); messagesView.setSelectionFromTop(size + 1, 0);
} }
} }
}; };
@ -492,7 +493,7 @@ public class ConversationFragment extends Fragment {
private void messageSent() { private void messageSent() {
int size = this.messageList.size(); int size = this.messageList.size();
if (size >= 1) { if (size >= 1 && this.messagesView.getLastVisiblePosition() != size - 1) {
messagesView.setSelection(size - 1); messagesView.setSelection(size - 1);
} }
mEditMessage.setText(""); mEditMessage.setText("");