Fix crash when trying to create a chat one to one without network

This commit is contained in:
Erwan Croze 2018-08-09 15:30:08 +02:00
parent 3d3858e0f5
commit d674105dc1
5 changed files with 40 additions and 26 deletions

View file

@ -36,6 +36,7 @@ import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import org.linphone.LinphoneManager;
import org.linphone.LinphonePreferences;
@ -392,21 +393,26 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
mWaitLayout.setVisibility(View.VISIBLE);
Core lc = LinphoneManager.getLc();
Address participant = mContactsSelected.get(0).getAddress();
ChatRoom chatRoom = lc.findOneToOneChatRoom(lc.getDefaultProxyConfig().getContact(), participant);
if (chatRoom == null) {
ProxyConfig lpc = lc.getDefaultProxyConfig();
if (lpc != null && lpc.getConferenceFactoryUri() != null && !LinphonePreferences.instance().useBasicChatRoomFor1To1()) {
mChatRoom = lc.createClientGroupChatRoom(getString(R.string.dummy_group_chat_subject), false);
mChatRoom.addListener(mChatRoomCreationListener);
Address participants[] = new Address[1];
participants[0] = participant;
mChatRoom.addParticipants(participants);
if (lc.getDefaultProxyConfig().getContact() != null) {
ChatRoom chatRoom = lc.findOneToOneChatRoom(lc.getDefaultProxyConfig().getContact(), participant);
if (chatRoom == null) {
ProxyConfig lpc = lc.getDefaultProxyConfig();
if (lpc != null && lpc.getConferenceFactoryUri() != null && !LinphonePreferences.instance().useBasicChatRoomFor1To1()) {
mChatRoom = lc.createClientGroupChatRoom(getString(R.string.dummy_group_chat_subject), false);
mChatRoom.addListener(mChatRoomCreationListener);
Address participants[] = new Address[1];
participants[0] = participant;
mChatRoom.addParticipants(participants);
} else {
chatRoom = lc.getChatRoom(participant);
LinphoneActivity.instance().goToChat(chatRoom.getPeerAddress().asStringUriOnly(), mShareInfos);
}
} else {
chatRoom = lc.getChatRoom(participant);
LinphoneActivity.instance().goToChat(chatRoom.getPeerAddress().asStringUriOnly(), mShareInfos);
}
} else {
LinphoneActivity.instance().goToChat(chatRoom.getPeerAddress().asStringUriOnly(), mShareInfos);
mWaitLayout.setVisibility(View.GONE);
LinphoneActivity.instance().displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
}
} else {
mContactsSelectedLayout.removeAllViews();

View file

@ -439,7 +439,7 @@ public class ChatEventsAdapter extends ListSelectionAdapter {
break;
case ConferenceSecurityAlert:
String message;
if (event.getSecurityAlertFaultyDevice() != null) {
if (event.getSecurityAlertFaultyDevice() != null && event.getSecurityAlertFaultyDevice().getUsername() != null ) {
message = mContext.getString(R.string.security_alert_address).replace("%s", event.getSecurityAlertFaultyDevice().asStringUriOnly());
} else {
message = mContext.getString(R.string.security_alert);

View file

@ -46,6 +46,7 @@ import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;
public class ContactDetailsFragment extends Fragment implements OnClickListener {
private LinphoneContact contact;
@ -76,7 +77,7 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
Core lc = LinphoneManager.getLc();
Address participant = Factory.instance().createAddress(tag);
ProxyConfig defaultProxyConfig = lc.getDefaultProxyConfig();
if (defaultProxyConfig != null) {
if (defaultProxyConfig != null && defaultProxyConfig.getContact() != null) {
ChatRoom room = lc.findOneToOneChatRoom(defaultProxyConfig.getContact(), participant);
if (room != null) {
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly(), null);
@ -93,6 +94,8 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly(), null);
}
}
} else {
LinphoneActivity.instance().displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
}
}
}

View file

@ -29,6 +29,7 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import org.linphone.LinphoneManager;
import org.linphone.LinphonePreferences;
@ -205,20 +206,24 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
} else if (id == R.id.chat) {
Core lc = LinphoneManager.getLc();
Address participant = Factory.instance().createAddress(sipUri);
ChatRoom room = lc.findOneToOneChatRoom(lc.getDefaultProxyConfig().getContact(), participant);
if (room != null) {
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly(), null);
} else {
ProxyConfig lpc = lc.getDefaultProxyConfig();
if (lpc != null && lpc.getConferenceFactoryUri() != null && !LinphonePreferences.instance().useBasicChatRoomFor1To1()) {
mWaitLayout.setVisibility(View.VISIBLE);
mChatRoom = lc.createClientGroupChatRoom(getString(R.string.dummy_group_chat_subject), false);
mChatRoom.addListener(mChatRoomCreationListener);
mChatRoom.addParticipant(participant);
} else {
room = lc.getChatRoom(participant);
if (lc.getDefaultProxyConfig().getContact() != null) {
ChatRoom room = lc.findOneToOneChatRoom(lc.getDefaultProxyConfig().getContact(), participant);
if (room != null) {
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly(), null);
} else {
ProxyConfig lpc = lc.getDefaultProxyConfig();
if (lpc != null && lpc.getConferenceFactoryUri() != null && !LinphonePreferences.instance().useBasicChatRoomFor1To1()) {
mWaitLayout.setVisibility(View.VISIBLE);
mChatRoom = lc.createClientGroupChatRoom(getString(R.string.dummy_group_chat_subject), false);
mChatRoom.addListener(mChatRoomCreationListener);
mChatRoom.addParticipant(participant);
} else {
room = lc.getChatRoom(participant);
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly(), null);
}
}
} else {
LinphoneActivity.instance().displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
}
} else if (id == R.id.add_contact) {
Address addr = Factory.instance().createAddress(sipUri);

@ -1 +1 @@
Subproject commit 4dab4917c02456a1a0ccb2988b57dc98475077b7
Subproject commit 8d3a016378aedcc14438ac55d5549faf79a7325b