aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2016-03-22 00:58:52 +0100
committerlookshe <github@lookshe.org>2016-03-22 00:58:52 +0100
commit4085f2a80e00e24a73206389cb1e8f30385e9952 (patch)
tree2cb25205f26167d69b02b6efa6d500dbd4c34564 /src/main/java/eu/siacs/conversations/ui
parentde3894f77c58579608fbe116c2dc5f36dcecbc8f (diff)
parent02f958ce7687eeff0eaae7da372bad4b65f78596 (diff)
Merge branch 'trz/rename' into trz/rebase
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java62
1 files changed, 37 insertions, 25 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java b/src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java
index 5ef2eea7..0cbde814 100644
--- a/src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java
+++ b/src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java
@@ -10,6 +10,7 @@ import java.util.List;
import de.thedevstack.android.logcat.Logging;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
+import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.MessageArchiveService;
@@ -24,10 +25,12 @@ public class ConversationSwipeRefreshListener implements SwipyRefreshLayout.OnRe
private List<Message> messageList;
private ConversationFragment fragment;
private ConversationMoreMessagesLoadedListener listener;
+ private SwipyRefreshLayout swipeLayout;
public ConversationSwipeRefreshListener(List<Message> messageList, SwipyRefreshLayout swipeLayout, ConversationFragment fragment, ListView messagesView, MessageAdapter messageListAdapter) {
this.messageList = messageList;
this.fragment = fragment;
+ this.swipeLayout = swipeLayout;
this.listener = new ConversationMoreMessagesLoadedListener(swipeLayout, messageList, fragment, messagesView, messageListAdapter);
}
@@ -35,33 +38,42 @@ public class ConversationSwipeRefreshListener implements SwipyRefreshLayout.OnRe
public void onRefresh(SwipyRefreshLayoutDirection direction) {
Logging.d(Config.LOGTAG, "Refresh swipe container");
Logging.d(Config.LOGTAG, "Refresh direction " + direction);
- synchronized (this.messageList) {
- long timestamp;
- if (SwipyRefreshLayoutDirection.TOP == direction) { // Load history -> messages sent/received before first message in database
- if (messageList.isEmpty()) {
- timestamp = System.currentTimeMillis();
- } else {
- timestamp = this.messageList.get(0).getTimeSent(); // works only because of the ordering (last msg = first msg in list)
+ final ConversationActivity activity = (ConversationActivity) fragment.getActivity();
+ if (activity.getSelectedConversation().getAccount().getStatus() != Account.State.DISABLED) {
+ synchronized (this.messageList) {
+ long timestamp;
+ if (SwipyRefreshLayoutDirection.TOP == direction) { // Load history -> messages sent/received before first message in database
+ if (messageList.isEmpty()) {
+ timestamp = System.currentTimeMillis();
+ } else {
+ timestamp = this.messageList.get(0).getTimeSent(); // works only because of the ordering (last msg = first msg in list)
+ }
+ this.listener.setLoadHistory(true);
+ activity.xmppConnectionService.loadMoreMessages(activity.getSelectedConversation(), timestamp, this.listener);
+ } else if (SwipyRefreshLayoutDirection.BOTTOM == direction) { // load messages sent/received between last received or last session establishment and now
+ if (activity.getSelectedConversation().getAccount().isOnlineAndConnected()) {
+ Logging.d("mam", "loading missing messages from mam (last session establishing or last received message)");
+ long lastSessionEstablished = this.getTimestampOfLastSessionEstablished(activity.getSelectedConversation());
+ long lastReceivedMessage = this.getTimestampOfLastReceivedOrTransmittedMessage();
+ long startTimestamp = Math.min(lastSessionEstablished, lastReceivedMessage);
+ MessageArchiveService.Query query = activity.xmppConnectionService.getMessageArchiveService().query(activity.getSelectedConversation(), startTimestamp, System.currentTimeMillis(), this.listener);
+ if (query != null) {
+ this.listener.setLoadHistory(false);
+ } else {
+ Logging.d("mam", "no query built - no messages loaded");
+ this.listener.onMoreMessagesLoaded(0, activity.getSelectedConversation());
+ this.listener.informUser(R.string.no_more_history_on_server);
+ }
+ this.listener.informUser(R.string.fetching_history_from_server);
+ } else {
+ this.listener.informUser(R.string.not_connected_try_again);
+ swipeLayout.setRefreshing(false);
+ }
}
- ConversationActivity activity = (ConversationActivity) fragment.getActivity();
- this.listener.setLoadHistory(true);
- activity.xmppConnectionService.loadMoreMessages(activity.getSelectedConversation(), timestamp, this.listener);
- } else if (SwipyRefreshLayoutDirection.BOTTOM == direction) { // load messages sent/received between last received or last session establishment and now
- Logging.d("mam", "loading missing messages from mam (last session establishing or last received message)");
- final ConversationActivity activity = (ConversationActivity) fragment.getActivity();
- long lastSessionEstablished = this.getTimestampOfLastSessionEstablished(activity.getSelectedConversation());
- long lastReceivedMessage = this.getTimestampOfLastReceivedOrTransmittedMessage();
- long startTimestamp = Math.min(lastSessionEstablished, lastReceivedMessage);
- MessageArchiveService.Query query = activity.xmppConnectionService.getMessageArchiveService().query(activity.getSelectedConversation(), startTimestamp, System.currentTimeMillis(), this.listener);
- if (query != null) {
- this.listener.setLoadHistory(false);
- } else {
- Logging.d("mam", "no query built - no messages loaded");
- this.listener.onMoreMessagesLoaded(0, activity.getSelectedConversation());
- this.listener.informUser(R.string.no_more_history_on_server);
- }
- this.listener.informUser(R.string.fetching_history_from_server);
}
+ } else {
+ this.listener.informUser(R.string.this_account_is_disabled);
+ swipeLayout.setRefreshing(false);
}
Logging.d(Config.LOGTAG, "End Refresh swipe container");
}