handle some rare npe
This commit is contained in:
parent
2fbd9e6744
commit
52c0bf73a0
|
@ -38,7 +38,10 @@ import static eu.siacs.conversations.ui.ConversationFragment.ATTACHMENT_CHOICE_T
|
||||||
public enum SendButtonAction {
|
public enum SendButtonAction {
|
||||||
TEXT, TAKE_PHOTO, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE, RECORD_VIDEO;
|
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 {
|
try {
|
||||||
return valueOf(setting);
|
return valueOf(setting);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
|
|
@ -42,7 +42,10 @@ import eu.siacs.conversations.utils.UIHelper;
|
||||||
|
|
||||||
public class SendButtonTool {
|
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 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||||
final boolean empty = text.length() == 0;
|
final boolean empty = text.length() == 0;
|
||||||
final boolean conference = c.getMode() == Conversation.MODE_MULTI;
|
final boolean conference = c.getMode() == Conversation.MODE_MULTI;
|
||||||
|
@ -60,14 +63,14 @@ public class SendButtonTool {
|
||||||
return SendButtonAction.CANCEL;
|
return SendButtonAction.CANCEL;
|
||||||
} else {
|
} else {
|
||||||
String setting = preferences.getString("quick_action", activity.getResources().getString(R.string.quick_action));
|
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;
|
return SendButtonAction.SEND_LOCATION;
|
||||||
} else {
|
} else {
|
||||||
if (setting.equals("recent")) {
|
if ("recent".equals(setting)) {
|
||||||
setting = preferences.getString(ConversationFragment.RECENTLY_USED_QUICK_ACTION, SendButtonAction.TEXT.toString());
|
setting = preferences.getString(ConversationFragment.RECENTLY_USED_QUICK_ACTION, SendButtonAction.TEXT.toString());
|
||||||
return SendButtonAction.valueOfOrDefault(setting, SendButtonAction.TEXT);
|
return SendButtonAction.valueOfOrDefault(setting);
|
||||||
} else {
|
} else {
|
||||||
return SendButtonAction.valueOfOrDefault(setting, SendButtonAction.TEXT);
|
return SendButtonAction.valueOfOrDefault(setting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue