Finally optimize the loading of the chatlist view
This commit is contained in:
parent
990b6e602d
commit
1036b40a40
1 changed files with 25 additions and 12 deletions
|
@ -834,26 +834,39 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
return statusFragment;
|
return statusFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class ChatRoomContainer{
|
||||||
|
private LinphoneChatRoom mCr;
|
||||||
|
long mTime;
|
||||||
|
public ChatRoomContainer(LinphoneChatRoom chatroom){
|
||||||
|
mCr = chatroom;
|
||||||
|
LinphoneChatMessage[] lastMsg = chatroom.getHistory(1);
|
||||||
|
if (lastMsg != null && lastMsg[0] != null) {
|
||||||
|
mTime = lastMsg[0].getTime();
|
||||||
|
}else mTime = 0;
|
||||||
|
}
|
||||||
|
LinphoneChatRoom getChatRoom(){
|
||||||
|
return mCr;
|
||||||
|
}
|
||||||
|
long getTime(){
|
||||||
|
return mTime;
|
||||||
|
}
|
||||||
|
};
|
||||||
public List<String> getChatList() {
|
public List<String> getChatList() {
|
||||||
ArrayList<String> chatList = new ArrayList<String>();
|
ArrayList<String> chatList = new ArrayList<String>();
|
||||||
|
|
||||||
LinphoneChatRoom[] chats = LinphoneManager.getLc().getChatRooms();
|
LinphoneChatRoom[] chats = LinphoneManager.getLc().getChatRooms();
|
||||||
List<LinphoneChatRoom> rooms = new ArrayList<LinphoneChatRoom>();
|
List<ChatRoomContainer> rooms = new ArrayList<ChatRoomContainer>();
|
||||||
|
|
||||||
for (LinphoneChatRoom chatroom : chats) {
|
for (LinphoneChatRoom chatroom : chats) {
|
||||||
if (chatroom.getHistorySize() > 0) {
|
rooms.add(new ChatRoomContainer(chatroom));
|
||||||
rooms.add(chatroom);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rooms.size() > 1) {
|
if (rooms.size() > 1) {
|
||||||
Collections.sort(rooms, new Comparator<LinphoneChatRoom>() {
|
Collections.sort(rooms, new Comparator<ChatRoomContainer>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(LinphoneChatRoom a, LinphoneChatRoom b) {
|
public int compare(ChatRoomContainer a, ChatRoomContainer b) {
|
||||||
LinphoneChatMessage[] messagesA = a.getHistory(1);
|
long atime = a.getTime();
|
||||||
LinphoneChatMessage[] messagesB = b.getHistory(1);
|
long btime = b.getTime();
|
||||||
long atime = messagesA[0].getTime();
|
|
||||||
long btime = messagesB[0].getTime();
|
|
||||||
|
|
||||||
if (atime > btime)
|
if (atime > btime)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -865,8 +878,8 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (LinphoneChatRoom chatroom : rooms) {
|
for (ChatRoomContainer chatroomContainer : rooms) {
|
||||||
chatList.add(chatroom.getPeerAddress().asStringUriOnly());
|
chatList.add(chatroomContainer.getChatRoom().getPeerAddress().asStringUriOnly());
|
||||||
}
|
}
|
||||||
|
|
||||||
return chatList;
|
return chatList;
|
||||||
|
|
Loading…
Reference in a new issue