aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2015-12-04 23:18:36 +0100
committersteckbrief <steckbrief@chefmail.de>2015-12-04 23:18:36 +0100
commit0086d5dc80dd95b1e8e4dcfe2d3d3090d260bb88 (patch)
treeb1b600ca8aeed4136d0a536f5c5b7a540bf03f66 /src/main
parent909dac7ac2bd2e76b2514a7bc6044e918abdf13f (diff)
Implements FS#83: Reload from last received message
Diffstat (limited to '')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java46
-rw-r--r--src/main/res/layout/fragment_conversation.xml10
4 files changed, 50 insertions, 20 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
index 94cb896b..3ee79412 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
+++ b/src/main/java/de/thedevstack/conversationsplus/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;
@@ -108,7 +109,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;
@@ -439,7 +440,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/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java
index cdc60187..774e72ba 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java
@@ -1,10 +1,11 @@
package de.thedevstack.conversationsplus.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 de.thedevstack.conversationsplus.entities.Conversation;
@@ -18,7 +19,7 @@ import de.thedevstack.conversationsplus.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/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java
index 84203bf4..c6e00bed 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java
@@ -1,9 +1,13 @@
package de.thedevstack.conversationsplus.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 de.thedevstack.conversationsplus.Config;
@@ -15,29 +19,51 @@ import de.thedevstack.conversationsplus.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");
}
diff --git a/src/main/res/layout/fragment_conversation.xml b/src/main/res/layout/fragment_conversation.xml
index aab37295..e70e9a05 100644
--- a/src/main/res/layout/fragment_conversation.xml
+++ b/src/main/res/layout/fragment_conversation.xml
@@ -1,17 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:background="@color/grey200" >
+ android:background="@color/grey200">
- <android.support.v4.widget.SwipeRefreshLayout
+ <com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/snackbar"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
- android:id="@+id/swipe_refresh_container">
+ android:id="@+id/swipe_refresh_container"
+ app:direction="both">
<ListView
android:id="@+id/messages_view"
android:layout_width="fill_parent"
@@ -27,7 +29,7 @@
android:transcriptMode="normal"
tools:listitem="@layout/message_sent" >
</ListView>
- </android.support.v4.widget.SwipeRefreshLayout>
+ </com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayout>
<RelativeLayout
android:id="@+id/textsend"