diff options
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/listeners')
2 files changed, 0 insertions, 246 deletions
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 08916206..00000000 --- a/src/main/java/eu/siacs/conversations/ui/listeners/ConversationMoreMessagesLoadedListener.java +++ /dev/null @@ -1,143 +0,0 @@ -package eu.siacs.conversations.ui.listeners; - -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; -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 SwipyRefreshLayout swipeLayout; - private List<Message> messageList; - private ConversationFragment fragment; - private ListView messagesView; - private MessageAdapter messageListAdapter; - private Toast messageLoaderToast; - /* - The current loading status - */ - private boolean loadingMessages = false; - /** - * Whether the user is loading only history messages or not. - * History messages are messages which are older than the oldest in the database. - */ - private boolean loadHistory = true; - - public ConversationMoreMessagesLoadedListener(SwipyRefreshLayout 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; - } - - public void setLoadHistory(boolean value) { - this.loadHistory = value; - } - - public void setLoadingInProgress() { - this.loadingMessages = true; - } - - public boolean isLoadingInProgress() { - return this.loadingMessages; - } - - @Override - public void onMoreMessagesLoaded(final int c, final Conversation conversation) { - ConversationActivity activity = (ConversationActivity) fragment.getActivity(); - // Current selected conversation is not the same the messages are loaded - skip updating message view and hide loading graphic - if (activity.getSelectedConversation() != conversation) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - swipeLayout.setRefreshing(false); - } - }); - return; - } - // No new messages are loaded - if (0 == c) { - if (this.loadHistory) { - conversation.setHasMessagesLeftOnServer(false); - } - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - swipeLayout.setRefreshing(false); - } - }); - } - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - final int oldPosition = messagesView.getFirstVisiblePosition(); // Always 0 - because loading starts always when hitting the top - String uuid = null; - boolean oldMessageListWasEmpty = messageList.isEmpty(); - if (-1 < oldPosition && messageList.size() > oldPosition) { - Message message = messageList.get(oldPosition); - uuid = message != null ? message.getUuid() : null; - } - View v = messagesView.getChildAt(0); - final int pxOffset = (v == null) ? 0 : v.getTop(); - - conversation.populateWithMessages(messageList); // This overrides the old message list - fragment.updateStatusMessages(); // This adds "messages" to the list for the status - messageListAdapter.notifyDataSetChanged(); - loadingMessages = false; // Loading of messages is finished - next query can be loaded - - int pos = getIndexOf(uuid, messageList); - - if (!oldMessageListWasEmpty) { - 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; - } - } - 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 0cbde814..00000000 --- a/src/main/java/eu/siacs/conversations/ui/listeners/ConversationSwipeRefreshListener.java +++ /dev/null @@ -1,103 +0,0 @@ -package eu.siacs.conversations.ui.listeners; - -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.android.logcat.Logging; -import eu.siacs.conversations.Config; -import eu.siacs.conversations.R; -import eu.siacs.conversations.entities.Account; -import eu.siacs.conversations.entities.Conversation; -import eu.siacs.conversations.entities.Message; -import eu.siacs.conversations.services.MessageArchiveService; -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 SwipyRefreshLayout.OnRefreshListener { - 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); - } - - @Override - public void onRefresh(SwipyRefreshLayoutDirection direction) { - Logging.d(Config.LOGTAG, "Refresh swipe container"); - Logging.d(Config.LOGTAG, "Refresh direction " + direction); - 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); - } - } - } - } else { - this.listener.informUser(R.string.this_account_is_disabled); - swipeLayout.setRefreshing(false); - } - Logging.d(Config.LOGTAG, "End Refresh swipe container"); - } - - private long getTimestampOfLastReceivedOrTransmittedMessage() { - long lastReceivedOrTransmittedMessage = Long.MAX_VALUE; - if (null != this.messageList - && !this.messageList.isEmpty()) { - int lastMessageIndex = this.messageList.size() - 1; - if (0 <= lastMessageIndex && this.messageList.size() > lastMessageIndex) { - lastReceivedOrTransmittedMessage = this.messageList.get(lastMessageIndex).getTimeSent(); - } - } - - return lastReceivedOrTransmittedMessage; - } - - private long getTimestampOfLastSessionEstablished(Conversation conversation) { - long lastSessionEstablished = Long.MAX_VALUE; - if (null != conversation - && null != conversation.getAccount() - && null != conversation.getAccount().getXmppConnection()) { - lastSessionEstablished = conversation.getAccount().getXmppConnection().getLastSessionEstablished(); - } - return lastSessionEstablished; - } -} |