From cb7c47bc622e730a07cabae5e076217d99a5b0b2 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 9 Jun 2016 14:50:13 +0200 Subject: [PATCH] catch conversations sort exception. not vital at this point --- .../conversations/entities/Conversation.java | 15 ++++++++++++++- .../services/XmppConnectionService.java | 19 +++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 8dacf8089..37a57f7bf 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -28,7 +28,7 @@ import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; -public class Conversation extends AbstractEntity implements Blockable { +public class Conversation extends AbstractEntity implements Blockable, Comparable { public static final String TABLENAME = "conversations"; public static final int STATUS_AVAILABLE = 0; @@ -356,6 +356,19 @@ public class Conversation extends AbstractEntity implements Blockable { return getContact().isSelf(); } + @Override + public int compareTo(Conversation another) { + final Message left = getLatestMessage(); + final Message right = another.getLatestMessage(); + if (left.getTimeSent() > right.getTimeSent()) { + return -1; + } else if (left.getTimeSent() < right.getTimeSent()) { + return 1; + } else { + return 0; + } + } + public interface OnMessageFound { void onMessageFound(final Message message); } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 5b0c4591a..083c108ad 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1297,20 +1297,11 @@ public class XmppConnectionService extends Service { } } } - Collections.sort(list, new Comparator() { - @Override - public int compare(Conversation lhs, Conversation rhs) { - Message left = lhs.getLatestMessage(); - Message right = rhs.getLatestMessage(); - if (left.getTimeSent() > right.getTimeSent()) { - return -1; - } else if (left.getTimeSent() < right.getTimeSent()) { - return 1; - } else { - return 0; - } - } - }); + try { + Collections.sort(list); + } catch (IllegalArgumentException e) { + //ignore + } } public void loadMoreMessages(final Conversation conversation, final long timestamp, final OnMoreMessagesLoaded callback) {