make ongoing call check null safe. fixes #3951

This commit is contained in:
Daniel Gultsch 2020-12-22 14:30:54 +01:00
parent 39229c34f6
commit b4db2e5284

View file

@ -182,7 +182,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private Toast messageLoaderToast; private Toast messageLoaderToast;
private ConversationsActivity activity; private ConversationsActivity activity;
private boolean reInitRequiredOnStart = true; private boolean reInitRequiredOnStart = true;
private OnClickListener clickToMuc = new OnClickListener() { private final OnClickListener clickToMuc = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -192,14 +192,14 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
startActivity(intent); startActivity(intent);
} }
}; };
private OnClickListener leaveMuc = new OnClickListener() { private final OnClickListener leaveMuc = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
activity.xmppConnectionService.archiveConversation(conversation); activity.xmppConnectionService.archiveConversation(conversation);
} }
}; };
private OnClickListener joinMuc = new OnClickListener() { private final OnClickListener joinMuc = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -207,7 +207,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
}; };
private OnClickListener acceptJoin = new OnClickListener() { private final OnClickListener acceptJoin = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
conversation.setAttribute("accept_non_anonymous", true); conversation.setAttribute("accept_non_anonymous", true);
@ -216,7 +216,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
}; };
private OnClickListener enterPassword = new OnClickListener() { private final OnClickListener enterPassword = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -231,7 +231,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}); });
} }
}; };
private OnScrollListener mOnScrollListener = new OnScrollListener() { private final OnScrollListener mOnScrollListener = new OnScrollListener() {
@Override @Override
public void onScrollStateChanged(AbsListView view, int scrollState) { public void onScrollStateChanged(AbsListView view, int scrollState) {
@ -310,7 +310,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
} }
}; };
private EditMessage.OnCommitContentListener mEditorContentListener = new EditMessage.OnCommitContentListener() { private final EditMessage.OnCommitContentListener mEditorContentListener = new EditMessage.OnCommitContentListener() {
@Override @Override
public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts, String[] contentMimeTypes) { public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts, String[] contentMimeTypes) {
// try to get permission to read the image, if applicable // try to get permission to read the image, if applicable
@ -333,7 +333,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
}; };
private Message selectedMessage; private Message selectedMessage;
private OnClickListener mEnableAccountListener = new OnClickListener() { private final OnClickListener mEnableAccountListener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final Account account = conversation == null ? null : conversation.getAccount(); final Account account = conversation == null ? null : conversation.getAccount();
@ -343,7 +343,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
} }
}; };
private OnClickListener mUnblockClickListener = new OnClickListener() { private final OnClickListener mUnblockClickListener = new OnClickListener() {
@Override @Override
public void onClick(final View v) { public void onClick(final View v) {
v.post(() -> v.setVisibility(View.INVISIBLE)); v.post(() -> v.setVisibility(View.INVISIBLE));
@ -354,8 +354,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
} }
}; };
private OnClickListener mBlockClickListener = this::showBlockSubmenu; private final OnClickListener mBlockClickListener = this::showBlockSubmenu;
private OnClickListener mAddBackClickListener = new OnClickListener() { private final OnClickListener mAddBackClickListener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -366,8 +366,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
} }
}; };
private View.OnLongClickListener mLongPressBlockListener = this::showBlockSubmenu; private final View.OnLongClickListener mLongPressBlockListener = this::showBlockSubmenu;
private OnClickListener mAllowPresenceSubscription = new OnClickListener() { private final OnClickListener mAllowPresenceSubscription = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final Contact contact = conversation == null ? null : conversation.getContact(); final Contact contact = conversation == null ? null : conversation.getContact();
@ -400,8 +400,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
updateSnackBar(conversation); updateSnackBar(conversation);
} }
}; };
private AtomicBoolean mSendingPgpMessage = new AtomicBoolean(false); private final AtomicBoolean mSendingPgpMessage = new AtomicBoolean(false);
private OnEditorActionListener mEditorActionListener = (v, actionId, event) -> { private final OnEditorActionListener mEditorActionListener = (v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_SEND) { if (actionId == EditorInfo.IME_ACTION_SEND) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null && imm.isFullscreenMode()) { if (imm != null && imm.isFullscreenMode()) {
@ -413,7 +413,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return false; return false;
} }
}; };
private OnClickListener mScrollButtonListener = new OnClickListener() { private final OnClickListener mScrollButtonListener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -421,7 +421,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
setSelection(binding.messagesView.getCount() - 1, true); setSelection(binding.messagesView.getCount() - 1, true);
} }
}; };
private OnClickListener mSendButtonListener = new OnClickListener() { private final OnClickListener mSendButtonListener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -517,7 +517,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private static Conversation getConversation(Activity activity, @IdRes int res) { private static Conversation getConversation(Activity activity, @IdRes int res) {
final Fragment fragment = activity.getFragmentManager().findFragmentById(res); final Fragment fragment = activity.getFragmentManager().findFragmentById(res);
if (fragment != null && fragment instanceof ConversationFragment) { if (fragment instanceof ConversationFragment) {
return ((ConversationFragment) fragment).getConversation(); return ((ConversationFragment) fragment).getConversation();
} else { } else {
return null; return null;
@ -527,11 +527,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
public static ConversationFragment get(Activity activity) { public static ConversationFragment get(Activity activity) {
FragmentManager fragmentManager = activity.getFragmentManager(); FragmentManager fragmentManager = activity.getFragmentManager();
Fragment fragment = fragmentManager.findFragmentById(R.id.main_fragment); Fragment fragment = fragmentManager.findFragmentById(R.id.main_fragment);
if (fragment != null && fragment instanceof ConversationFragment) { if (fragment instanceof ConversationFragment) {
return (ConversationFragment) fragment; return (ConversationFragment) fragment;
} else { } else {
fragment = fragmentManager.findFragmentById(R.id.secondary_fragment); fragment = fragmentManager.findFragmentById(R.id.secondary_fragment);
return fragment != null && fragment instanceof ConversationFragment ? (ConversationFragment) fragment : null; return fragment instanceof ConversationFragment ? (ConversationFragment) fragment : null;
} }
} }
@ -986,7 +986,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
menuCall.setVisible(false); menuCall.setVisible(false);
menuOngoingCall.setVisible(false); menuOngoingCall.setVisible(false);
} else { } else {
final Optional<OngoingRtpSession> ongoingRtpSession = activity.xmppConnectionService.getJingleConnectionManager().getOngoingRtpConnection(conversation.getContact()); final XmppConnectionService service = activity.xmppConnectionService;
final Optional<OngoingRtpSession> ongoingRtpSession = service == null ? Optional.absent() : service.getJingleConnectionManager().getOngoingRtpConnection(conversation.getContact());
if (ongoingRtpSession.isPresent()) { if (ongoingRtpSession.isPresent()) {
menuOngoingCall.setVisible(true); menuOngoingCall.setVisible(true);
menuCall.setVisible(false); menuCall.setVisible(false);
@ -998,7 +999,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
menuContactDetails.setVisible(!this.conversation.withSelf()); menuContactDetails.setVisible(!this.conversation.withSelf());
menuMucDetails.setVisible(false); menuMucDetails.setVisible(false);
final XmppConnectionService service = activity.xmppConnectionService;
menuInviteContact.setVisible(service != null && service.findConferenceServer(conversation.getAccount()) != null); menuInviteContact.setVisible(service != null && service.findConferenceServer(conversation.getAccount()) != null);
} }
if (conversation.isMuted()) { if (conversation.isMuted()) {