From caefd38f96a3a9d8cf51ea2a672daf76c7e237b6 Mon Sep 17 00:00:00 2001 From: lookshe Date: Sun, 16 Aug 2015 18:59:59 +0200 Subject: moved merged files to correct location --- .../conversationsplus/ui/ConversationFragment.java | 1 + .../ConversationMoreMessagesLoadedListener.java | 118 +++++++++++++++++++++ .../ConversationSwipeRefreshListener.java | 48 +++++++++ .../ConversationMoreMessagesLoadedListener.java | 118 --------------------- .../ConversationSwipeRefreshListener.java | 48 --------- 5 files changed, 167 insertions(+), 166 deletions(-) create mode 100644 src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java create mode 100644 src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java delete mode 100644 src/main/java/eu/siacs/conversations/ui/listeners/ConversationMoreMessagesLoadedListener.java delete mode 100644 src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java (limited to 'src') diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java index 26e2b3c1..8bd7e81e 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java @@ -42,6 +42,7 @@ import java.util.List; import java.util.NoSuchElementException; import java.util.concurrent.ConcurrentLinkedQueue; +import de.thedevstack.conversationsplus.ui.listeners.ConversationSwipeRefreshListener; import de.tzur.conversations.Settings; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.R; diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java new file mode 100644 index 00000000..6e7d5d6a --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java @@ -0,0 +1,118 @@ +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 java.util.List; + +import de.thedevstack.conversationsplus.entities.Conversation; +import de.thedevstack.conversationsplus.entities.Message; +import de.thedevstack.conversationsplus.services.XmppConnectionService; +import de.thedevstack.conversationsplus.ui.ConversationActivity; +import de.thedevstack.conversationsplus.ui.ConversationFragment; +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 List messageList; + private ConversationFragment fragment; + private ListView messagesView; + private MessageAdapter messageListAdapter; + private Toast messageLoaderToast; + + public ConversationMoreMessagesLoadedListener(SwipeRefreshLayout swipeLayout, List messageList, ConversationFragment fragment, ListView messagesView, MessageAdapter messageListAdapter) { + this.swipeLayout = swipeLayout; + this.messageList = messageList; + this.fragment = fragment; + this.messagesView = messagesView; + this.messageListAdapter = messageListAdapter; + } + + @Override + public void onMoreMessagesLoaded(final int c, final Conversation conversation) { + ConversationActivity activity = (ConversationActivity) fragment.getActivity(); + if (activity.getSelectedConversation() != conversation) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + swipeLayout.setRefreshing(false); + } + }); + return; + } + if (0 == c) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + swipeLayout.setRefreshing(false); + } + }); + } + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + final int oldPosition = messagesView.getFirstVisiblePosition(); + int pos = 0; + View v = messagesView.getChildAt(0); + final int pxOffset = (v == null) ? 0 : v.getTop(); + if (-1 < oldPosition && messageList.size() > oldPosition) { + Message message = messageList.get(oldPosition); + String uuid = message != null ? message.getUuid() : null; + pos = getIndexOf(uuid, messageList); + } + conversation.populateWithMessages(messageList); + fragment.updateStatusMessages(); + messageListAdapter.notifyDataSetChanged(); + messagesView.setSelectionFromTop(pos, pxOffset); + + if (messageLoaderToast != null) { + messageLoaderToast.cancel(); + } + swipeLayout.setRefreshing(false); + } + }); + } + + @Override + public void informUser(final int resId) { + final ConversationActivity activity = (ConversationActivity) fragment.getActivity(); + + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + if (messageLoaderToast != null) { + messageLoaderToast.cancel(); + } + messageLoaderToast = Toast.makeText(activity, resId, Toast.LENGTH_LONG); + messageLoaderToast.show(); + } + }); + + } + + private int getIndexOf(String uuid, List messages) { + if (uuid == null) { + return 0; + } + for(int i = 0; i < messages.size(); ++i) { + if (uuid.equals(messages.get(i).getUuid())) { + return i; + } else { + Message next = messages.get(i); + while(next != null && next.wasMergedIntoPrevious()) { + if (uuid.equals(next.getUuid())) { + return i; + } + next = next.next(); + } + + } + } + return 0; + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java new file mode 100644 index 00000000..5329d626 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java @@ -0,0 +1,48 @@ +package de.thedevstack.conversationsplus.ui.listeners; + +import android.support.v4.widget.SwipeRefreshLayout; +import android.util.Log; +import android.view.View; +import android.widget.ListView; +import android.widget.Toast; + +import java.util.List; + +import de.thedevstack.conversationsplus.Config; +import de.thedevstack.conversationsplus.entities.Conversation; +import de.thedevstack.conversationsplus.entities.Message; +import de.thedevstack.conversationsplus.services.XmppConnectionService; +import de.thedevstack.conversationsplus.ui.ConversationActivity; +import de.thedevstack.conversationsplus.ui.ConversationFragment; +import de.thedevstack.conversationsplus.ui.adapter.MessageAdapter; + +/** + * This listener starts loading messages from the server. + */ +public class ConversationSwipeRefreshListener implements SwipeRefreshLayout.OnRefreshListener { + private List messageList; + private ConversationFragment fragment; + private ConversationMoreMessagesLoadedListener listener; + + public ConversationSwipeRefreshListener(List messageList, SwipeRefreshLayout 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() { + Log.d(Config.LOGTAG, "Refresh swipe container"); + synchronized (this.messageList) { + long timestamp; + if (messageList.isEmpty()) { + timestamp = System.currentTimeMillis(); + } else { + timestamp = this.messageList.get(0).getTimeSent(); + } + ConversationActivity activity = (ConversationActivity) fragment.getActivity(); + activity.xmppConnectionService.loadMoreMessages(activity.getSelectedConversation(), timestamp, this.listener); + } + Log.d(Config.LOGTAG, "End Refresh swipe container"); + } +} diff --git a/src/main/java/eu/siacs/conversations/ui/listeners/ConversationMoreMessagesLoadedListener.java b/src/main/java/eu/siacs/conversations/ui/listeners/ConversationMoreMessagesLoadedListener.java deleted file mode 100644 index 2154f8d8..00000000 --- a/src/main/java/eu/siacs/conversations/ui/listeners/ConversationMoreMessagesLoadedListener.java +++ /dev/null @@ -1,118 +0,0 @@ -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 java.util.List; - -import eu.siacs.conversations.entities.Conversation; -import eu.siacs.conversations.entities.Message; -import eu.siacs.conversations.services.XmppConnectionService; -import eu.siacs.conversations.ui.ConversationActivity; -import eu.siacs.conversations.ui.ConversationFragment; -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 List messageList; - private ConversationFragment fragment; - private ListView messagesView; - private MessageAdapter messageListAdapter; - private Toast messageLoaderToast; - - public ConversationMoreMessagesLoadedListener(SwipeRefreshLayout swipeLayout, List messageList, ConversationFragment fragment, ListView messagesView, MessageAdapter messageListAdapter) { - this.swipeLayout = swipeLayout; - this.messageList = messageList; - this.fragment = fragment; - this.messagesView = messagesView; - this.messageListAdapter = messageListAdapter; - } - - @Override - public void onMoreMessagesLoaded(final int c, final Conversation conversation) { - ConversationActivity activity = (ConversationActivity) fragment.getActivity(); - if (activity.getSelectedConversation() != conversation) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - swipeLayout.setRefreshing(false); - } - }); - return; - } - if (0 == c) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - swipeLayout.setRefreshing(false); - } - }); - } - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - final int oldPosition = messagesView.getFirstVisiblePosition(); - int pos = 0; - View v = messagesView.getChildAt(0); - final int pxOffset = (v == null) ? 0 : v.getTop(); - if (-1 < oldPosition && messageList.size() > oldPosition) { - Message message = messageList.get(oldPosition); - String uuid = message != null ? message.getUuid() : null; - pos = getIndexOf(uuid, messageList); - } - conversation.populateWithMessages(messageList); - fragment.updateStatusMessages(); - messageListAdapter.notifyDataSetChanged(); - messagesView.setSelectionFromTop(pos, pxOffset); - - if (messageLoaderToast != null) { - messageLoaderToast.cancel(); - } - swipeLayout.setRefreshing(false); - } - }); - } - - @Override - public void informUser(final int resId) { - final ConversationActivity activity = (ConversationActivity) fragment.getActivity(); - - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - if (messageLoaderToast != null) { - messageLoaderToast.cancel(); - } - messageLoaderToast = Toast.makeText(activity, resId, Toast.LENGTH_LONG); - messageLoaderToast.show(); - } - }); - - } - - private int getIndexOf(String uuid, List messages) { - if (uuid == null) { - return 0; - } - for(int i = 0; i < messages.size(); ++i) { - if (uuid.equals(messages.get(i).getUuid())) { - return i; - } else { - Message next = messages.get(i); - while(next != null && next.wasMergedIntoPrevious()) { - if (uuid.equals(next.getUuid())) { - return i; - } - next = next.next(); - } - - } - } - return 0; - } -} diff --git a/src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java b/src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java deleted file mode 100644 index 09a8d730..00000000 --- a/src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java +++ /dev/null @@ -1,48 +0,0 @@ -package eu.siacs.conversations.ui.listeners; - -import android.support.v4.widget.SwipeRefreshLayout; -import android.util.Log; -import android.view.View; -import android.widget.ListView; -import android.widget.Toast; - -import java.util.List; - -import eu.siacs.conversations.Config; -import eu.siacs.conversations.entities.Conversation; -import eu.siacs.conversations.entities.Message; -import eu.siacs.conversations.services.XmppConnectionService; -import eu.siacs.conversations.ui.ConversationActivity; -import eu.siacs.conversations.ui.ConversationFragment; -import eu.siacs.conversations.ui.adapter.MessageAdapter; - -/** - * This listener starts loading messages from the server. - */ -public class ConversationSwipeRefreshListener implements SwipeRefreshLayout.OnRefreshListener { - private List messageList; - private ConversationFragment fragment; - private ConversationMoreMessagesLoadedListener listener; - - public ConversationSwipeRefreshListener(List messageList, SwipeRefreshLayout 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() { - Log.d(Config.LOGTAG, "Refresh swipe container"); - synchronized (this.messageList) { - long timestamp; - if (messageList.isEmpty()) { - timestamp = System.currentTimeMillis(); - } else { - timestamp = this.messageList.get(0).getTimeSent(); - } - ConversationActivity activity = (ConversationActivity) fragment.getActivity(); - activity.xmppConnectionService.loadMoreMessages(activity.getSelectedConversation(), timestamp, this.listener); - } - Log.d(Config.LOGTAG, "End Refresh swipe container"); - } -} -- cgit v1.2.3