Display chat rooms event if they are empty
This commit is contained in:
parent
feaa564f80
commit
6a3e05b59c
6 changed files with 28 additions and 76 deletions
Binary file not shown.
|
@ -34,7 +34,7 @@ dtmf_player_amp=0.1
|
|||
ec_calibrator_cool_tones=1
|
||||
|
||||
[misc]
|
||||
conference_factory_uri=sips:conference-factory@sip.linphone.org
|
||||
conference_factory_uri=sip:conference-factory@conf.test.org
|
||||
max_calls=10
|
||||
history_max_size=100
|
||||
|
||||
|
|
|
@ -123,12 +123,9 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.linphone.activities.LinphoneActivity.ChatRoomContainer.createChatroomContainer;
|
||||
|
||||
public class LinphoneActivity extends LinphoneGenericActivity implements OnClickListener, ContactPicked, ActivityCompat.OnRequestPermissionsResultCallback {
|
||||
public static final String PREF_FIRST_LAUNCH = "pref_first_launch";
|
||||
|
@ -909,62 +906,6 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
|||
return statusFragment;
|
||||
}
|
||||
|
||||
static class ChatRoomContainer{
|
||||
private ChatRoom mCr;
|
||||
long mTime;
|
||||
static public ChatRoomContainer createChatroomContainer(ChatRoom chatRoom) {
|
||||
if (chatRoom.getHistorySize() <= 0) return null;
|
||||
return new ChatRoomContainer(chatRoom);
|
||||
}
|
||||
public ChatRoomContainer(ChatRoom chatroom){
|
||||
mCr = chatroom;
|
||||
ChatMessage[] lastMsg = chatroom.getHistory(1);
|
||||
if (lastMsg != null && lastMsg.length > 0 && lastMsg[0] != null) {
|
||||
mTime = lastMsg[0].getTime();
|
||||
}else mTime = 0;
|
||||
}
|
||||
ChatRoom getChatRoom(){
|
||||
return mCr;
|
||||
}
|
||||
long getTime(){
|
||||
return mTime;
|
||||
}
|
||||
};
|
||||
public List<String> getChatList() {
|
||||
ArrayList<String> chatList = new ArrayList<String>();
|
||||
|
||||
ChatRoom[] chats = LinphoneManager.getLc().getChatRooms();
|
||||
List<ChatRoomContainer> rooms = new ArrayList<ChatRoomContainer>();
|
||||
|
||||
for (ChatRoom chatroom : chats) {
|
||||
ChatRoomContainer crc = createChatroomContainer(chatroom);
|
||||
if (crc != null) rooms.add(crc);
|
||||
}
|
||||
|
||||
if (rooms.size() > 1) {
|
||||
Collections.sort(rooms, new Comparator<ChatRoomContainer>() {
|
||||
@Override
|
||||
public int compare(ChatRoomContainer a, ChatRoomContainer b) {
|
||||
long atime = a.getTime();
|
||||
long btime = b.getTime();
|
||||
|
||||
if (atime > btime)
|
||||
return -1;
|
||||
else if (btime > atime)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (ChatRoomContainer chatroomContainer : rooms) {
|
||||
chatList.add(chatroomContainer.getChatRoom().getPeerAddress().asStringUriOnly());
|
||||
}
|
||||
|
||||
return chatList;
|
||||
}
|
||||
|
||||
public void removeFromChatList(String sipUri) {
|
||||
ChatRoom chatroom = LinphoneManager.getLc().getChatRoomFromUri(sipUri);
|
||||
chatroom.deleteHistory();
|
||||
|
|
|
@ -58,6 +58,7 @@ import org.linphone.core.Core;
|
|||
import org.linphone.core.Factory;
|
||||
import org.linphone.core.CoreListenerStub;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.linphone.fragments.FragmentsAvailable.CHAT_LIST;
|
||||
|
@ -189,8 +190,16 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
|||
}
|
||||
}
|
||||
|
||||
private void refreshConversations() {
|
||||
mConversations = new ArrayList<>();
|
||||
ChatRoom[] chats = LinphoneManager.getLc().getChatRooms();
|
||||
for (ChatRoom room : chats) {
|
||||
mConversations.add(room.getPeerAddress().asStringUriOnly());
|
||||
}
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
mConversations = LinphoneActivity.instance().getChatList();
|
||||
refreshConversations();
|
||||
hideAndDisplayMessageIfNoChat();
|
||||
}
|
||||
|
||||
|
@ -262,7 +271,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
|||
String sipUri = chatList.getAdapter().getItem(info.position).toString();
|
||||
|
||||
LinphoneActivity.instance().removeFromChatList(sipUri);
|
||||
mConversations = LinphoneActivity.instance().getChatList();
|
||||
refreshConversations();
|
||||
if (getResources().getBoolean(R.bool.isTablet)) {
|
||||
quitEditMode();
|
||||
}
|
||||
|
@ -421,8 +430,9 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
|||
ChatRoom chatRoom = LinphoneManager.getLc().getChatRoom(address);
|
||||
int unreadMessagesCount = chatRoom.getUnreadMessagesCount();
|
||||
ChatMessage[] history = chatRoom.getHistory(1);
|
||||
ChatMessage msg = history[0];
|
||||
|
||||
if (history.length > 0) {
|
||||
ChatMessage msg = history[0];
|
||||
if (msg.getFileTransferInformation() != null || msg.getExternalBodyUrl() != null || msg.getAppdata() != null) {
|
||||
holder.lastMessageView.setBackgroundResource(R.drawable.chat_file_message);
|
||||
time = msg.getTime();
|
||||
|
@ -435,6 +445,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
|||
holder.date.setText(LinphoneUtils.timestampToHumanDate(getActivity(),time,getString(R.string.messages_list_date_format)));
|
||||
holder.lastMessageView.setText(message);
|
||||
}
|
||||
}
|
||||
|
||||
holder.displayName.setSelected(true); // For animation
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit c390646fe81934550781ec7470c0dcf440b03e58
|
||||
Subproject commit c09442f1808a0fa9e040b48485a1fa7c4c9fd5a3
|
|
@ -1 +1 @@
|
|||
Subproject commit 2f97587d53020be683a98a4b6404f76f9a8e24a5
|
||||
Subproject commit c30a7b48f5f212609546650efd24340943bd1542
|
Loading…
Reference in a new issue