fix NPE after race condition. fixes #4033

This commit is contained in:
Daniel Gultsch 2021-03-13 11:13:19 +01:00
parent bf25b24967
commit 859f3b2a1d
2 changed files with 11 additions and 6 deletions

View File

@ -2992,6 +2992,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
final Menu menu = popupMenu.getMenu();
menu.findItem(R.id.action_manage_accounts).setVisible(QuickConversationsService.isConversations());
popupMenu.setOnMenuItemClickListener(item -> {
final XmppActivity activity = this.activity;
if (activity == null) {
Log.e(Config.LOGTAG,"Unable to perform action. no context provided");
return true;
}
switch (item.getItemId()) {
case R.id.action_show_qr_code:
activity.showQrCode(conversation.getAccount().getShareableUri());

View File

@ -17,7 +17,7 @@ import eu.siacs.conversations.ui.XmppActivity;
public class AccountUtils {
public static final Class MANAGE_ACCOUNT_ACTIVITY;
public static final Class<?> MANAGE_ACCOUNT_ACTIVITY;
static {
MANAGE_ACCOUNT_ACTIVITY = getManageAccountActivityClass();
@ -78,7 +78,7 @@ public class AccountUtils {
return pending;
}
public static void launchManageAccounts(Activity activity) {
public static void launchManageAccounts(final Activity activity) {
if (MANAGE_ACCOUNT_ACTIVITY != null) {
activity.startActivity(new Intent(activity, MANAGE_ACCOUNT_ACTIVITY));
} else {
@ -86,15 +86,15 @@ public class AccountUtils {
}
}
public static void launchManageAccount(XmppActivity xmppActivity) {
Account account = getFirst(xmppActivity.xmppConnectionService);
public static void launchManageAccount(final XmppActivity xmppActivity) {
final Account account = getFirst(xmppActivity.xmppConnectionService);
xmppActivity.switchToAccount(account);
}
private static Class getManageAccountActivityClass() {
private static Class<?> getManageAccountActivityClass() {
try {
return Class.forName("eu.siacs.conversations.ui.ManageAccountActivity");
} catch (ClassNotFoundException e) {
} catch (final ClassNotFoundException e) {
return null;
}
}