aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java62
1 files changed, 37 insertions, 25 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java
index dede54ca..6dc9f4a4 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java
@@ -10,6 +10,7 @@ import java.util.List;
import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.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");
}