diff options
Diffstat (limited to 'src/main/java')
3 files changed, 44 insertions, 16 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 1b4e1813..670d2c38 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -10,7 +10,6 @@ import android.content.Intent; import android.content.IntentSender; import android.content.IntentSender.SendIntentException; import android.os.Bundle; -import android.support.v4.widget.SwipeRefreshLayout; import android.text.InputType; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -34,6 +33,8 @@ import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; import android.widget.Toast; +import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayout; + import net.java.otr4j.session.SessionStatus; import java.util.ArrayList; @@ -110,7 +111,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } }; protected ListView messagesView; - protected SwipeRefreshLayout swipeLayout; + protected SwipyRefreshLayout swipeLayout; final protected List<Message> messageList = new ArrayList<>(); protected MessageAdapter messageListAdapter; private EditMessage mEditMessage; @@ -441,7 +442,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa // Start of swipe refresh // New Swipe refresh - swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_container); + swipeLayout = (SwipyRefreshLayout) view.findViewById(R.id.swipe_refresh_container); swipeLayout.setOnRefreshListener(new ConversationSwipeRefreshListener(messageList, swipeLayout, this, messagesView, messageListAdapter)); // End of swipe refresh diff --git a/src/main/java/eu/siacs/conversations/ui/listeners/ConversationMoreMessagesLoadedListener.java b/src/main/java/eu/siacs/conversations/ui/listeners/ConversationMoreMessagesLoadedListener.java index 02a32114..a7354eec 100644 --- a/src/main/java/eu/siacs/conversations/ui/listeners/ConversationMoreMessagesLoadedListener.java +++ b/src/main/java/eu/siacs/conversations/ui/listeners/ConversationMoreMessagesLoadedListener.java @@ -1,10 +1,11 @@ package eu.siacs.conversations.ui.listeners; -import android.support.v4.widget.SwipeRefreshLayout; import android.view.View; import android.widget.ListView; import android.widget.Toast; +import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayout; + import java.util.List; import eu.siacs.conversations.entities.Conversation; @@ -18,7 +19,7 @@ import eu.siacs.conversations.ui.adapter.MessageAdapter; * This listener updates the UI when messages are loaded from the server. */ public class ConversationMoreMessagesLoadedListener implements XmppConnectionService.OnMoreMessagesLoaded { - private SwipeRefreshLayout swipeLayout; + private SwipyRefreshLayout swipeLayout; private List<Message> messageList; private ConversationFragment fragment; private ListView messagesView; @@ -29,7 +30,7 @@ public class ConversationMoreMessagesLoadedListener implements XmppConnectionSer */ private boolean loadingMessages = false; - public ConversationMoreMessagesLoadedListener(SwipeRefreshLayout swipeLayout, List<Message> messageList, ConversationFragment fragment, ListView messagesView, MessageAdapter messageListAdapter) { + public ConversationMoreMessagesLoadedListener(SwipyRefreshLayout swipeLayout, List<Message> messageList, ConversationFragment fragment, ListView messagesView, MessageAdapter messageListAdapter) { this.swipeLayout = swipeLayout; this.messageList = messageList; 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 b97a894e..7b3b97aa 100644 --- a/src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java +++ b/src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java @@ -1,9 +1,13 @@ package eu.siacs.conversations.ui.listeners; -import android.support.v4.widget.SwipeRefreshLayout; +import de.thedevstack.conversationsplus.R; +import de.thedevstack.conversationsplus.services.MessageArchiveService; import de.thedevstack.conversationsplus.utils.Logging; import android.widget.ListView; +import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayout; +import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayoutDirection; + import java.util.List; import eu.siacs.conversations.Config; @@ -15,29 +19,51 @@ import eu.siacs.conversations.ui.adapter.MessageAdapter; /** * This listener starts loading messages from the server. */ -public class ConversationSwipeRefreshListener implements SwipeRefreshLayout.OnRefreshListener { +public class ConversationSwipeRefreshListener implements SwipyRefreshLayout.OnRefreshListener { private List<Message> messageList; private ConversationFragment fragment; private ConversationMoreMessagesLoadedListener listener; - public ConversationSwipeRefreshListener(List<Message> messageList, SwipeRefreshLayout swipeLayout, ConversationFragment fragment, ListView messagesView, MessageAdapter messageListAdapter) { + public ConversationSwipeRefreshListener(List<Message> messageList, SwipyRefreshLayout swipeLayout, ConversationFragment fragment, ListView messagesView, MessageAdapter messageListAdapter) { this.messageList = messageList; this.fragment = fragment; this.listener = new ConversationMoreMessagesLoadedListener(swipeLayout, messageList, fragment, messagesView, messageListAdapter); } @Override - public void onRefresh() { + 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 (messageList.isEmpty()) { - timestamp = System.currentTimeMillis(); - } else { - timestamp = this.messageList.get(0).getTimeSent(); // works only because of the ordering (last msg = first msg in list) + if (SwipyRefreshLayoutDirection.TOP == direction) { + 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) + } + ConversationActivity activity = (ConversationActivity) fragment.getActivity(); + activity.xmppConnectionService.loadMoreMessages(activity.getSelectedConversation(), timestamp, this.listener); + } else if (SwipyRefreshLayoutDirection.BOTTOM == direction) { + Logging.d("mam", "loading missing messages from mam (last session establishing or last received message)"); + final ConversationActivity activity = (ConversationActivity) fragment.getActivity(); + long lastSessionEstablished = activity.getSelectedConversation().getAccount().getXmppConnection().getLastSessionEstablished(); + int lastMessageIndex = this.messageList.size() - 1; + long lastReceivedMessage = (0 <= lastMessageIndex) ? this.messageList.get(lastMessageIndex).getTimeSent() : Long.MAX_VALUE; + long startTimestamp = Math.min(lastSessionEstablished, lastReceivedMessage); + MessageArchiveService.Query query = activity.xmppConnectionService.getMessageArchiveService().query(activity.getSelectedConversation(), startTimestamp, System.currentTimeMillis()); + if (query != null) { + query.setCallback(this.listener); + } else { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + listener.onMoreMessagesLoaded(0, activity.getSelectedConversation()); + } + }); + } + this.listener.informUser(R.string.fetching_history_from_server); } - ConversationActivity activity = (ConversationActivity) fragment.getActivity(); - activity.xmppConnectionService.loadMoreMessages(activity.getSelectedConversation(), timestamp, this.listener); } Logging.d(Config.LOGTAG, "End Refresh swipe container"); } |