diff options
author | steckbrief <steckbrief@chefmail.de> | 2015-10-15 22:40:05 +0200 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2015-10-15 22:40:05 +0200 |
commit | e891f076f2b479146fc7ecce3763bf500919df43 (patch) | |
tree | 8b6fbb891b06ac8a5a9ba59f56229d4b61183e70 /src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | |
parent | 0265bd05bf7ef6ee14c85ae87831bcc42a4b02cd (diff) | |
parent | 7206541a7b951c03297b7cc7bec02a0f18ac7bd4 (diff) |
Merge remote-tracking branch 'remotes/origin/trz/rename' into trz/rebase
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services/XmppConnectionService.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index f50b9fa6..1093c674 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1050,32 +1050,38 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa Log.d("mam", "Query in progress"); return; } + //TODO Create a separate class for this runnable to store if messages are getting loaded or not. Not really a good idea to do this in the callback. Runnable runnable = new Runnable() { @Override public void run() { - final Account account = conversation.getAccount(); - List<Message> messages = databaseBackend.getMessages(conversation, 50,timestamp); - Log.d("mam", "runnable load more messages"); - if (messages.size() > 0) { - Log.d("mam", "At least one message"); - conversation.addAll(0, messages); - checkDeletedFiles(conversation); - callback.onMoreMessagesLoaded(messages.size(), conversation); - } else if (conversation.hasMessagesLeftOnServer() - && account.isOnlineAndConnected() - && account.getXmppConnection().getFeatures().mam()) { - Log.d("mam", "mam activate, account online and connected and messages left on server"); - MessageArchiveService.Query query = getMessageArchiveService().query(conversation,0,timestamp - 1); - if (query != null) { - query.setCallback(callback); - } - callback.informUser(R.string.fetching_history_from_server); - } else { - Log.d("mam", ((!conversation.hasMessagesLeftOnServer()) ? "no" : "") + " more messages left on server, mam " + ((account.getXmppConnection().getFeatures().mam()) ? "" : "not") + " activated, account is " + ((account.isOnlineAndConnected()) ? "" : "not") + " online or connected)"); - callback.onMoreMessagesLoaded(0, conversation); - callback.informUser(R.string.no_more_history_on_server); + if (null == callback || !callback.isLoadingInProgress()) { // if a callback is set, ensure that there is no loading in progress + if (null != callback) { + callback.setLoadingInProgress(); // Tell the callback that the loading is in progress + } + final Account account = conversation.getAccount(); + List<Message> messages = databaseBackend.getMessages(conversation, 50, timestamp); + Log.d("mam", "runnable load more messages"); + if (messages.size() > 0) { + Log.d("mam", "At least one message"); + conversation.addAll(0, messages); + checkDeletedFiles(conversation); + callback.onMoreMessagesLoaded(messages.size(), conversation); + } else if (conversation.hasMessagesLeftOnServer() + && account.isOnlineAndConnected() + && account.getXmppConnection().getFeatures().mam()) { + Log.d("mam", "mam activate, account online and connected and messages left on server"); + MessageArchiveService.Query query = getMessageArchiveService().query(conversation, 0, timestamp - 1); + if (query != null) { + query.setCallback(callback); + } + callback.informUser(R.string.fetching_history_from_server); + } else { + Log.d("mam", ((!conversation.hasMessagesLeftOnServer()) ? "no" : "") + " more messages left on server, mam " + ((account.getXmppConnection().getFeatures().mam()) ? "" : "not") + " activated, account is " + ((account.isOnlineAndConnected()) ? "" : "not") + " online or connected)"); + callback.onMoreMessagesLoaded(0, conversation); + callback.informUser(R.string.no_more_history_on_server); + } } - } + } }; mDatabaseExecutor.execute(runnable); } @@ -2553,6 +2559,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa public void onMoreMessagesLoaded(int count, Conversation conversation); public void informUser(int r); + + void setLoadingInProgress(); + + boolean isLoadingInProgress(); } public interface OnAccountPasswordChanged { |