diff options
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/ui/listeners')
3 files changed, 2 insertions, 168 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java deleted file mode 100644 index 6e7d5d6a..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java +++ /dev/null @@ -1,118 +0,0 @@ -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<Message> messageList; - private ConversationFragment fragment; - private ListView messagesView; - private MessageAdapter messageListAdapter; - private Toast messageLoaderToast; - - public ConversationMoreMessagesLoadedListener(SwipeRefreshLayout swipeLayout, List<Message> 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<Message> 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 deleted file mode 100644 index 5329d626..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java +++ /dev/null @@ -1,48 +0,0 @@ -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<Message> messageList; - private ConversationFragment fragment; - private ConversationMoreMessagesLoadedListener listener; - - public ConversationSwipeRefreshListener(List<Message> 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/de/thedevstack/conversationsplus/ui/listeners/ShowResourcesListDialogListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShowResourcesListDialogListener.java index 070ea58c..b082c5c4 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShowResourcesListDialogListener.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShowResourcesListDialogListener.java @@ -3,8 +3,8 @@ package de.thedevstack.conversationsplus.ui.listeners; import android.content.Context; import android.view.View; -import de.thedevstack.conversationsplus.R; -import de.thedevstack.conversationsplus.entities.Contact; +import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.Contact; import de.thedevstack.conversationsplus.ui.adapter.PresencesArrayAdapter; import de.thedevstack.conversationsplus.ui.dialogs.AbstractAlertDialog; |