From 19d75a0e1c2a17f691bce1e461d8c52b7ea06434 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Mon, 17 Jun 2019 21:30:07 +0200 Subject: handle some rare npe --- .../java/de/pixart/messenger/ui/util/SendButtonAction.java | 5 ++++- .../java/de/pixart/messenger/ui/util/SendButtonTool.java | 13 ++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main/java/de/pixart/messenger/ui/util/SendButtonAction.java b/src/main/java/de/pixart/messenger/ui/util/SendButtonAction.java index 825ca3f17..00e82fd92 100644 --- a/src/main/java/de/pixart/messenger/ui/util/SendButtonAction.java +++ b/src/main/java/de/pixart/messenger/ui/util/SendButtonAction.java @@ -39,7 +39,10 @@ import static de.pixart.messenger.ui.ConversationFragment.ATTACHMENT_CHOICE_TAKE public enum SendButtonAction { TEXT, TAKE_PHOTO, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE, RECORD_VIDEO, CHOOSE_ATTACHMENT; - public static SendButtonAction valueOfOrDefault(String setting, SendButtonAction text) { + public static SendButtonAction valueOfOrDefault(final String setting) { + if (setting == null) { + return TEXT; + } try { return valueOf(setting); } catch (IllegalArgumentException e) { diff --git a/src/main/java/de/pixart/messenger/ui/util/SendButtonTool.java b/src/main/java/de/pixart/messenger/ui/util/SendButtonTool.java index 96bcad183..2c9307323 100644 --- a/src/main/java/de/pixart/messenger/ui/util/SendButtonTool.java +++ b/src/main/java/de/pixart/messenger/ui/util/SendButtonTool.java @@ -43,7 +43,10 @@ import de.pixart.messenger.utils.UIHelper; public class SendButtonTool { - public static SendButtonAction getAction(Activity activity, Conversation c, String text) { + public static SendButtonAction getAction(final Activity activity, final Conversation c, final String text) { + if (activity == null) { + return SendButtonAction.TEXT; + } final boolean empty = text.length() == 0; final boolean conference = c.getMode() == Conversation.MODE_MULTI; if (c.getCorrectingMessage() != null && (empty || text.equals(c.getCorrectingMessage().getBody()))) { @@ -66,14 +69,14 @@ public class SendButtonTool { } else if (quickShareChoice(activity) && !AttachmentsVisible(c)) { return SendButtonAction.TEXT; } else { - if (!setting.equals("none") && UIHelper.receivedLocationQuestion(c.getLatestMessage())) { + if (!"none".equals(setting) && UIHelper.receivedLocationQuestion(c.getLatestMessage())) { return SendButtonAction.SEND_LOCATION; } else { - if (setting.equals("recent")) { + if ("recent".equals(setting)) { setting = preferences.getString(ConversationFragment.RECENTLY_USED_QUICK_ACTION, SendButtonAction.TEXT.toString()); - return SendButtonAction.valueOfOrDefault(setting, SendButtonAction.TEXT); + return SendButtonAction.valueOfOrDefault(setting); } else { - return SendButtonAction.valueOfOrDefault(setting, SendButtonAction.TEXT); + return SendButtonAction.valueOfOrDefault(setting); } } } -- cgit v1.2.3