From bb217a3a6e520a28f1bea7b1f1af3267ce87bd2f Mon Sep 17 00:00:00 2001 From: Margaux Clerc Date: Thu, 26 Nov 2015 10:43:15 +0100 Subject: [PATCH] Fix crash in chat --- res/layout/search_contact_cell.xml | 2 +- src/org/linphone/ChatFragment.java | 29 ++++++++++++++--------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/res/layout/search_contact_cell.xml b/res/layout/search_contact_cell.xml index f15448df7..32c1279b0 100644 --- a/res/layout/search_contact_cell.xml +++ b/res/layout/search_contact_cell.xml @@ -3,7 +3,7 @@ android:id="@+id/layout" android:background="@drawable/list_selector" android:layout_width="match_parent" - android:layout_height="50dp" + android:layout_height="60dp" android:padding="5dp" android:gravity="center_vertical" android:orientation="vertical" > diff --git a/src/org/linphone/ChatFragment.java b/src/org/linphone/ChatFragment.java index aad10d6e6..2a226d25f 100644 --- a/src/org/linphone/ChatFragment.java +++ b/src/org/linphone/ChatFragment.java @@ -146,7 +146,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC if(getArguments() == null || getArguments().getString("SipUri") == null) { newChatConversation = true; - Log.w("lala"); } else { //Retrieve parameter from intent sipUri = getArguments().getString("SipUri"); @@ -468,7 +467,10 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC chatRoom = lc.getChatRoom(lAddress); chatRoom.markAsRead(); contact = ContactsManager.getInstance().findContactWithAddress(getActivity().getContentResolver(), lAddress); - displayChatHeader(lAddress); + if(chatRoom != null) { + displayChatHeader(lAddress); + dispayMessageList(); + } } } @@ -493,12 +495,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC this.pictureUri = pictureUri; initChatRoom(sipUri); - - if(chatRoom != null) { - LinphoneAddress lAddress = chatRoom.getPeerAddress(); - displayChatHeader(lAddress); - dispayMessageList(); - } } @Override @@ -608,12 +604,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC LinphoneManager.addListener(this); // Force hide keyboard - boolean isOrientationLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; - if(isOrientationLandscape) { - getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); - } else { - getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); - } + getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); String draft = getArguments().getString("messageDraft"); message.setText(draft); @@ -621,7 +612,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC if(!newChatConversation) { initChatRoom(sipUri); remoteComposing.setVisibility(chatRoom.isRemoteComposing() ? View.VISIBLE : View.GONE); - dispayMessageList(); } super.onResume(); } @@ -709,6 +699,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC editList.setVisibility(View.VISIBLE); isEditMode = true; dispayMessageList(); + //TODO refaire la liste } if(id == R.id.start_call){ LinphoneActivity.instance().setAddresGoToDialerAndCall(sipUri, LinphoneUtils.getUsernameFromAddress(sipUri), null); @@ -740,6 +731,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC if (chatRoom != null && messageToSend != null && messageToSend.length() > 0 && isNetworkReachable) { LinphoneChatMessage message = chatRoom.createLinphoneChatMessage(messageToSend); chatRoom.sendChatMessage(message); + lAddress = chatRoom.getPeerAddress(); if (LinphoneActivity.isInstanciated()) { LinphoneActivity.instance().onMessageSent(sipUri, messageToSend); @@ -761,6 +753,13 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC private void sendImageMessage(String path, int imageSize) { LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); boolean isNetworkReachable = lc == null ? false : lc.isNetworkReachable(); + + if(newChatConversation && chatRoom == null) { + String address = searchContactField.getText().toString(); + if (address != null && !address.equals("")) { + initChatRoom(address); + } + } invalidate(); if (chatRoom != null && path != null && path.length() > 0 && isNetworkReachable) {