handle some rare npe

This commit is contained in:
Daniel Gultsch 2019-06-16 18:04:43 +02:00
parent 2fbd9e6744
commit 52c0bf73a0
2 changed files with 12 additions and 6 deletions

View File

@ -38,7 +38,10 @@ import static eu.siacs.conversations.ui.ConversationFragment.ATTACHMENT_CHOICE_T
public enum SendButtonAction {
TEXT, TAKE_PHOTO, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE, RECORD_VIDEO;
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) {

View File

@ -42,7 +42,10 @@ import eu.siacs.conversations.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 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
final boolean empty = text.length() == 0;
final boolean conference = c.getMode() == Conversation.MODE_MULTI;
@ -60,14 +63,14 @@ public class SendButtonTool {
return SendButtonAction.CANCEL;
} else {
String setting = preferences.getString("quick_action", activity.getResources().getString(R.string.quick_action));
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);
}
}
}