mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-27 19:22:15 -05:00
made conversation list thread safe
This commit is contained in:
parent
c512d98b74
commit
fd5760d27a
@ -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
|
||||
|
@ -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,
|
||||
|
@ -805,8 +805,7 @@ public class ConversationActivity extends XmppActivity {
|
||||
}
|
||||
|
||||
public void updateConversationList() {
|
||||
conversationList.clear();
|
||||
conversationList.addAll(xmppConnectionService.getConversations());
|
||||
xmppConnectionService.populateWithOrderedConversations(conversationList);
|
||||
listView.invalidateViews();
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user