Fix crash when sorting chat list

This commit is contained in:
Sylvain Berfini 2015-02-17 09:23:25 +01:00
parent 33d4978f5f
commit 39d595d2da

View file

@ -389,20 +389,25 @@ public class ChatStorage {
} }
} }
Collections.sort(rooms, new Comparator<LinphoneChatRoom>() { if (rooms.size() > 1) {
@Override Collections.sort(rooms, new Comparator<LinphoneChatRoom>() {
public int compare(LinphoneChatRoom a, LinphoneChatRoom b) { @Override
// /!\ Warning: Have to take the second element because it returns two even when asking for only one... public int compare(LinphoneChatRoom a, LinphoneChatRoom b) {
long atime = a.getHistory(1)[1].getTime(); LinphoneChatMessage[] messagesA = a.getHistory(1);
long btime = b.getHistory(1)[1].getTime(); LinphoneChatMessage[] messagesB = b.getHistory(1);
if (atime > btime) long atime, btime;
return -1; // /!\ Warning: Have to take the second element because it returns two even when asking for only one...
else if (btime > atime) atime = messagesA.length > 1 ? messagesA[1].getTime() : messagesA[0].getTime();
return 1; btime = messagesA.length > 1 ? messagesB[1].getTime() : messagesB[0].getTime();
else if (atime > btime)
return 0; return -1;
} else if (btime > atime)
}); return 1;
else
return 0;
}
});
}
for (LinphoneChatRoom chatroom : rooms) { for (LinphoneChatRoom chatroom : rooms) {
chatList.add(chatroom.getPeerAddress().asStringUriOnly()); chatList.add(chatroom.getPeerAddress().asStringUriOnly());