diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-02-08 21:35:47 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-02-08 21:35:47 +0100 |
commit | 88c839371be97c8ce6acd570c55ae3e748e2e0f7 (patch) | |
tree | ee6ec74187f777dc181a3e25c235eef1f9b8739d /src/main/java/de/pixart/messenger | |
parent | a13be0c48dd6a0ed94ff23295824f8635a0e5e2a (diff) |
fixed scrolling and async loading of message of new conversation start
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 38 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ConversationFragment.java | 6 |
2 files changed, 29 insertions, 15 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 55b87074a..5fe77667b 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -1717,6 +1717,7 @@ public class XmppConnectionService extends Service { return conversation; } conversation = databaseBackend.findConversation(account, jid); + final boolean loadMessagesFromDb; if (conversation != null) { conversation.setStatus(Conversation.STATUS_AVAILABLE); conversation.setAccount(account); @@ -1727,8 +1728,8 @@ public class XmppConnectionService extends Service { conversation.setMode(Conversation.MODE_SINGLE); conversation.setContactJid(jid.toBareJid()); } - conversation.addAll(0, databaseBackend.getMessages(conversation, Config.PAGE_SIZE)); - this.databaseBackend.updateConversation(conversation); + databaseBackend.updateConversation(conversation); + loadMessagesFromDb = conversation.messagesLoaded.compareAndSet(true,false); } else { String conversationName; Contact contact = account.getRoster().getContact(jid); @@ -1744,20 +1745,31 @@ public class XmppConnectionService extends Service { conversation = new Conversation(conversationName, account, jid.toBareJid(), Conversation.MODE_SINGLE); } - this.databaseBackend.createConversation(conversation); + loadMessagesFromDb = false; } - if (account.getXmppConnection() != null - && account.getXmppConnection().getFeatures().mam() - && !muc) { - if (query == null) { - this.mMessageArchiveService.query(conversation); - } else { - if (query.getConversation() == null) { - this.mMessageArchiveService.query(conversation, query.getStart()); + final Conversation c = conversation; + mDatabaseExecutor.execute(new Runnable() { + @Override + public void run() { + if (loadMessagesFromDb) { + c.addAll(0, databaseBackend.getMessages(c, Config.PAGE_SIZE)); + updateConversationUi(); + c.messagesLoaded.set(true); + } + if (account.getXmppConnection() != null + && account.getXmppConnection().getFeatures().mam() + && !muc) { + if (query == null) { + mMessageArchiveService.query(c); + } else { + if (query.getConversation() == null) { + mMessageArchiveService.query(c, query.getStart()); + } + } } + checkDeletedFiles(c); } - } - checkDeletedFiles(conversation); + }); this.conversations.add(conversation); updateConversationUi(); return conversation; diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 7bc1a3208..db9e3981d 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -141,8 +141,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } activity.xmppConnectionService.loadMoreMessages(conversation, timestamp, new XmppConnectionService.OnMoreMessagesLoaded() { @Override - public void onMoreMessagesLoaded(final int c, Conversation conversation) { + public void onMoreMessagesLoaded(final int c, final Conversation conversation) { if (ConversationFragment.this.conversation != conversation) { + conversation.messagesLoaded.set(true); return; } activity.runOnUiThread(new Runnable() { @@ -170,6 +171,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa if (messageLoaderToast != null) { messageLoaderToast.cancel(); } + conversation.messagesLoaded.set(true); } }); } @@ -1283,7 +1285,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa private boolean showLoadMoreMessages(final Conversation c) { final boolean mam = hasMamSupport(c); final MessageArchiveService service = activity.xmppConnectionService.getMessageArchiveService(); - return mam && (c.getLastClearHistory() != 0 || (c.countMessages() == 0 && c.hasMessagesLeftOnServer() && !service.queryInProgress(c))); + return mam && (c.getLastClearHistory() != 0 || (c.countMessages() == 0 && c.messagesLoaded.get() && c.hasMessagesLeftOnServer() && !service.queryInProgress(c))); } private boolean hasMamSupport(final Conversation c) { |