aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-12-15 23:06:29 +0100
committeriNPUTmice <daniel@gultsch.de>2014-12-15 23:06:29 +0100
commite2f50ab8558a32ff54b6c6c80da319b4a396e173 (patch)
treec8c334c6f6b1a74ecb9b27a561b8897e77963608 /src/main/java/eu/siacs/conversations/ui
parent03ca971e2e6a816d1a64123633b2e1ec7d087323 (diff)
go through mam history page by page. load mam dynamically on scroll
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationFragment.java36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
index 7f4b5c54b..c333bab79 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
@@ -9,6 +9,7 @@ import android.content.Intent;
import android.content.IntentSender;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
+import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Gravity;
@@ -38,6 +39,7 @@ import java.util.List;
import java.util.NoSuchElementException;
import java.util.concurrent.ConcurrentLinkedQueue;
+import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.entities.Account;
@@ -104,6 +106,7 @@ public class ConversationFragment extends Fragment {
private TextView snackbarMessage;
private TextView snackbarAction;
private boolean messagesLoaded = false;
+
private OnScrollListener mOnScrollListener = new OnScrollListener() {
@Override
@@ -119,14 +122,30 @@ public class ConversationFragment extends Fragment {
if (firstVisibleItem == 0 && messagesLoaded) {
long timestamp = ConversationFragment.this.messageList.get(0).getTimeSent();
messagesLoaded = false;
- int size = activity.xmppConnectionService.loadMoreMessages(conversation, timestamp);
- conversation.populateWithMessages(ConversationFragment.this.messageList);
- updateStatusMessages();
- messageListAdapter.notifyDataSetChanged();
- if (size != 0) {
- messagesLoaded = true;
- }
- messagesView.setSelectionFromTop(size + 1, 0);
+ Log.d(Config.LOGTAG,"load more messages");
+ activity.xmppConnectionService.loadMoreMessages(conversation, timestamp, new XmppConnectionService.OnMoreMessagesLoaded() {
+ @Override
+ public void onMoreMessagesLoaded(final int count, Conversation conversation) {
+ if (ConversationFragment.this.conversation != conversation) {
+ return;
+ }
+ activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ int firstItem = messagesView.getFirstVisiblePosition();
+ Log.d(Config.LOGTAG, "done loading more messages. first item: " + firstItem);
+ ConversationFragment.this.conversation.populateWithMessages(ConversationFragment.this.messageList);
+ updateStatusMessages();
+ messageListAdapter.notifyDataSetChanged();
+ if (count != 0) {
+ messagesLoaded = true;
+ }
+ messagesView.setSelectionFromTop(firstItem + count, 0);
+ }
+ });
+ }
+ });
+
}
}
}
@@ -580,6 +599,7 @@ public class ConversationFragment extends Fragment {
}
}
conversation.populateWithMessages(ConversationFragment.this.messageList);
+ this.messagesLoaded = this.messageList.size() > 0;
for (Message message : this.messageList) {
if (message.getEncryption() == Message.ENCRYPTION_PGP
&& (message.getStatus() == Message.STATUS_RECEIVED || message