diff options
Diffstat (limited to 'src/eu/siacs')
4 files changed, 15 insertions, 8 deletions
diff --git a/src/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/eu/siacs/conversations/persistance/DatabaseBackend.java index fbf45d25..7643076a 100644 --- a/src/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -116,8 +116,8 @@ public class DatabaseBackend extends SQLiteOpenHelper { return cursor.getInt(0); } - public List<Conversation> getConversations(int status) { - List<Conversation> list = new ArrayList<Conversation>(); + public CopyOnWriteArrayList<Conversation> getConversations(int status) { + CopyOnWriteArrayList<Conversation> list = new CopyOnWriteArrayList<Conversation>(); SQLiteDatabase db = this.getReadableDatabase(); String[] selectionArgs = { "" + status }; Cursor cursor = db.rawQuery("select * from " + Conversation.TABLENAME diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index fc19b3c1..f8a5d974 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -10,6 +10,7 @@ import java.util.Hashtable; import java.util.List; import java.util.Locale; import java.util.TimeZone; +import java.util.concurrent.CopyOnWriteArrayList; import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpServiceConnection; @@ -98,7 +99,7 @@ public class XmppConnectionService extends Service { private PresenceGenerator mPresenceGenerator = new PresenceGenerator(); private List<Account> accounts; - private List<Conversation> conversations = null; + private CopyOnWriteArrayList<Conversation> conversations = null; private JingleConnectionManager mJingleConnectionManager = new JingleConnectionManager( this); @@ -708,7 +709,14 @@ public class XmppConnectionService extends Service { conv.setMessages(databaseBackend.getMessages(conv, 50)); } } - Collections.sort(this.conversations, new Comparator<Conversation>() { + + return this.conversations; + } + + public void populateWithOrderedConversations(List<Conversation> list) { + list.clear(); + list.addAll(getConversations()); + Collections.sort(list, new Comparator<Conversation>() { @Override public int compare(Conversation lhs, Conversation rhs) { Message left = lhs.getLatestMessage(); @@ -722,7 +730,6 @@ public class XmppConnectionService extends Service { } } }); - return this.conversations; } public List<Message> getMoreMessages(Conversation conversation, diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index aea35d3c..209ff3b8 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -805,8 +805,7 @@ public class ConversationActivity extends XmppActivity { } public void updateConversationList() { - conversationList.clear(); - conversationList.addAll(xmppConnectionService.getConversations()); + xmppConnectionService.populateWithOrderedConversations(conversationList); listView.invalidateViews(); } diff --git a/src/eu/siacs/conversations/ui/ShareWithActivity.java b/src/eu/siacs/conversations/ui/ShareWithActivity.java index 601caa29..461aaec4 100644 --- a/src/eu/siacs/conversations/ui/ShareWithActivity.java +++ b/src/eu/siacs/conversations/ui/ShareWithActivity.java @@ -89,7 +89,8 @@ public class ShareWithActivity extends XmppActivity { Set<Contact> displayedContacts = new HashSet<Contact>(); conversations.removeAllViews(); - List<Conversation> convList = xmppConnectionService.getConversations(); + List<Conversation> convList = new ArrayList<Conversation>(); + xmppConnectionService.populateWithOrderedConversations(convList); Collections.sort(convList, new Comparator<Conversation>() { @Override public int compare(Conversation lhs, Conversation rhs) { |