aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/ui
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2015-10-15 22:30:47 +0200
committersteckbrief <steckbrief@chefmail.de>2015-10-15 22:30:47 +0200
commit8c450d17a4f94a2528b6b438e39cd128bfbe84ce (patch)
treec437aef07cbe5911c5b6975276f12697e41e20cd /src/main/java/de/thedevstack/conversationsplus/ui
parent1db6e6d5eadbad04768be823b8dbd32827b9b5c3 (diff)
Fixes FS#81 - avoid jumps after loading messages
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/ui')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java42
1 files changed, 32 insertions, 10 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java
index 6e7d5d6a..cdc60187 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java
@@ -24,18 +24,32 @@ public class ConversationMoreMessagesLoadedListener implements XmppConnectionSer
private ListView messagesView;
private MessageAdapter messageListAdapter;
private Toast messageLoaderToast;
+ /*
+ The current loading status
+ */
+ private boolean loadingMessages = false;
public ConversationMoreMessagesLoadedListener(SwipeRefreshLayout swipeLayout, List<Message> messageList, ConversationFragment fragment, ListView messagesView, MessageAdapter messageListAdapter) {
this.swipeLayout = swipeLayout;
this.messageList = messageList;
+
this.fragment = fragment;
this.messagesView = messagesView;
this.messageListAdapter = messageListAdapter;
}
+ public void setLoadingInProgress() {
+ this.loadingMessages = true;
+ }
+
+ public boolean isLoadingInProgress() {
+ return this.loadingMessages;
+ }
+
@Override
public void onMoreMessagesLoaded(final int c, final Conversation conversation) {
ConversationActivity activity = (ConversationActivity) fragment.getActivity();
+ // Current selected conversation is not the same the messages are loaded - skip updating message view and hide loading graphic
if (activity.getSelectedConversation() != conversation) {
activity.runOnUiThread(new Runnable() {
@Override
@@ -45,6 +59,7 @@ public class ConversationMoreMessagesLoadedListener implements XmppConnectionSer
});
return;
}
+ // No new messages are loaded
if (0 == c) {
activity.runOnUiThread(new Runnable() {
@Override
@@ -56,19 +71,26 @@ public class ConversationMoreMessagesLoadedListener implements XmppConnectionSer
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
- final int oldPosition = messagesView.getFirstVisiblePosition();
- int pos = 0;
- View v = messagesView.getChildAt(0);
- final int pxOffset = (v == null) ? 0 : v.getTop();
+ final int oldPosition = messagesView.getFirstVisiblePosition(); // Always 0 - because loading starts always when hitting the top
+ String uuid = null;
+ boolean oldMessageListWasEmpty = messageList.isEmpty();
if (-1 < oldPosition && messageList.size() > oldPosition) {
Message message = messageList.get(oldPosition);
- String uuid = message != null ? message.getUuid() : null;
- pos = getIndexOf(uuid, messageList);
+ uuid = message != null ? message.getUuid() : null;
}
- conversation.populateWithMessages(messageList);
- fragment.updateStatusMessages();
+ View v = messagesView.getChildAt(0);
+ final int pxOffset = (v == null) ? 0 : v.getTop();
+
+ conversation.populateWithMessages(messageList); // This overrides the old message list
+ fragment.updateStatusMessages(); // This adds "messages" to the list for the status
messageListAdapter.notifyDataSetChanged();
- messagesView.setSelectionFromTop(pos, pxOffset);
+ loadingMessages = false; // Loading of messages is finished - next query can be loaded
+
+ int pos = getIndexOf(uuid, messageList);
+
+ if (!oldMessageListWasEmpty) {
+ messagesView.setSelectionFromTop(pos, pxOffset);
+ }
if (messageLoaderToast != null) {
messageLoaderToast.cancel();
@@ -99,7 +121,7 @@ public class ConversationMoreMessagesLoadedListener implements XmppConnectionSer
if (uuid == null) {
return 0;
}
- for(int i = 0; i < messages.size(); ++i) {
+ for (int i = 0; i < messages.size(); ++i) {
if (uuid.equals(messages.get(i).getUuid())) {
return i;
} else {