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