Updated liblinphone + use existing chatroom if possible, else create it (destroy no more needed)

This commit is contained in:
Sylvain Berfini 2013-08-12 11:21:46 +02:00
parent bc8c5a5b74
commit e1153f938f
3 changed files with 10 additions and 16 deletions

View file

@ -178,7 +178,12 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
progressBar.setProgress(0); progressBar.setProgress(0);
} }
}); });
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc != null) {
chatRoom = lc.getOrCreateChatRoom(sipUri);
}
if (savedInstanceState != null) { if (savedInstanceState != null) {
messagesFilterLimit = savedInstanceState.getInt("messagesFilterLimit"); messagesFilterLimit = savedInstanceState.getInt("messagesFilterLimit");
} }
@ -487,9 +492,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
@Override @Override
public void onPause() { public void onPause() {
if (chatRoom != null) {
chatRoom.destroy();
}
latestImageMessages = null; latestImageMessages = null;
message.removeTextChangedListener(textWatcher); message.removeTextChangedListener(textWatcher);
removeVirtualKeyboardVisiblityListener(); removeVirtualKeyboardVisiblityListener();
@ -513,11 +515,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
@SuppressLint("UseSparseArrays") @SuppressLint("UseSparseArrays")
@Override @Override
public void onResume() { public void onResume() {
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc != null) {
chatRoom = lc.createChatRoom(sipUri);
}
latestImageMessages = new HashMap<Integer, String>(); latestImageMessages = new HashMap<Integer, String>();
message.addTextChangedListener(textWatcher); message.addTextChangedListener(textWatcher);
addVirtualKeyboardVisiblityListener(); addVirtualKeyboardVisiblityListener();

View file

@ -280,7 +280,7 @@ public class ChatStorage {
} }
c.close(); c.close();
} else { } else {
LinphoneChatRoom room = LinphoneManager.getLc().createChatRoom(correspondent); LinphoneChatRoom room = LinphoneManager.getLc().getOrCreateChatRoom(correspondent);
LinphoneChatMessage[] history = room.getHistory(); LinphoneChatMessage[] history = room.getHistory();
for (int i = 0; i < history.length; i++) { for (int i = 0; i < history.length; i++) {
LinphoneChatMessage message = history[i]; LinphoneChatMessage message = history[i];
@ -290,7 +290,6 @@ public class ChatStorage {
chatMessage.setUrl(message.getExternalBodyUrl()); chatMessage.setUrl(message.getExternalBodyUrl());
chatMessages.add(chatMessage); chatMessages.add(chatMessage);
} }
room.destroy();
} }
return chatMessages; return chatMessages;
@ -319,9 +318,8 @@ public class ChatStorage {
public void removeDiscussion(String correspondent) { public void removeDiscussion(String correspondent) {
if (useNativeAPI) { if (useNativeAPI) {
LinphoneChatRoom chatroom = LinphoneManager.getLc().createChatRoom(correspondent); LinphoneChatRoom chatroom = LinphoneManager.getLc().getOrCreateChatRoom(correspondent);
chatroom.deleteHistory(); chatroom.deleteHistory();
chatroom.destroy();
} else { } else {
db.delete(TABLE_NAME, "remoteContact LIKE \"" + correspondent + "\"", null); db.delete(TABLE_NAME, "remoteContact LIKE \"" + correspondent + "\"", null);
} }
@ -393,9 +391,8 @@ public class ChatStorage {
count = c.getCount(); count = c.getCount();
c.close(); c.close();
} else { } else {
LinphoneChatRoom chatroom = LinphoneManager.getLc().createChatRoom(contact); LinphoneChatRoom chatroom = LinphoneManager.getLc().getOrCreateChatRoom(contact);
count = chatroom.getUnreadMessagesCount(); count = chatroom.getUnreadMessagesCount();
chatroom.destroy();
} }
return count; return count;
} }

@ -1 +1 @@
Subproject commit 8fbe7ee1d47c7957f35ca9268c4072df7921cec1 Subproject commit 55b640b0d733ea88885d438c7888cf021269510e