From 1036b40a40a62902740d90a7e4955a11b2b206f4 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Sat, 9 Sep 2017 18:23:36 +0200 Subject: [PATCH] Finally optimize the loading of the chatlist view --- .../org/linphone/LinphoneActivity.java | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/android/org/linphone/LinphoneActivity.java b/src/android/org/linphone/LinphoneActivity.java index 2686fbbcd..c5d759e70 100644 --- a/src/android/org/linphone/LinphoneActivity.java +++ b/src/android/org/linphone/LinphoneActivity.java @@ -834,26 +834,39 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick 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 getChatList() { ArrayList chatList = new ArrayList(); LinphoneChatRoom[] chats = LinphoneManager.getLc().getChatRooms(); - List rooms = new ArrayList(); + List rooms = new ArrayList(); for (LinphoneChatRoom chatroom : chats) { - if (chatroom.getHistorySize() > 0) { - rooms.add(chatroom); - } + rooms.add(new ChatRoomContainer(chatroom)); } if (rooms.size() > 1) { - Collections.sort(rooms, new Comparator() { + Collections.sort(rooms, new Comparator() { @Override - public int compare(LinphoneChatRoom a, LinphoneChatRoom b) { - LinphoneChatMessage[] messagesA = a.getHistory(1); - LinphoneChatMessage[] messagesB = b.getHistory(1); - long atime = messagesA[0].getTime(); - long btime = messagesB[0].getTime(); + public int compare(ChatRoomContainer a, ChatRoomContainer b) { + long atime = a.getTime(); + long btime = b.getTime(); if (atime > btime) return -1; @@ -865,8 +878,8 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick }); } - for (LinphoneChatRoom chatroom : rooms) { - chatList.add(chatroom.getPeerAddress().asStringUriOnly()); + for (ChatRoomContainer chatroomContainer : rooms) { + chatList.add(chatroomContainer.getChatRoom().getPeerAddress().asStringUriOnly()); } return chatList;