Fix crash

This commit is contained in:
NekoInverter 2020-03-07 15:45:34 +08:00
parent f894de15d8
commit 31072e7095
No known key found for this signature in database
GPG Key ID: 280D6CCCF95715F9

View File

@ -1563,53 +1563,55 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
if (pressedBotButton != -1) {
BotButton button = botButtons.get(pressedBotButton);
Gson gson = new Gson();
if (!TextUtils.isEmpty(button.button.url)) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setItems(new CharSequence[]{LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("CopyLink", R.string.CopyLink), LocaleController.getString("CopyDetails", R.string.CopyDetails)}, (dialogInterface, i) -> {
if (i == 0) {
try {
AndroidUtilities.addToClipboard(button.button.text);
Toast.makeText(getContext(), LocaleController.getString("TextCopied", R.string.TextCopied), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
FileLog.e(e);
if (button.button != null) {
if (!TextUtils.isEmpty(button.button.url)) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setItems(new CharSequence[]{LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("CopyLink", R.string.CopyLink), LocaleController.getString("CopyDetails", R.string.CopyDetails)}, (dialogInterface, i) -> {
if (i == 0) {
try {
AndroidUtilities.addToClipboard(button.button.text);
Toast.makeText(getContext(), LocaleController.getString("TextCopied", R.string.TextCopied), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
FileLog.e(e);
}
} else if (i == 1) {
try {
AndroidUtilities.addToClipboard(button.button.url);
Toast.makeText(getContext(), LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
FileLog.e(e);
}
} else if (i == 2) {
try {
AndroidUtilities.addToClipboard(gson.toJson(button.button));
Toast.makeText(getContext(), LocaleController.getString("TextCopied", R.string.TextCopied), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
FileLog.e(e);
}
}
} else if (i == 1) {
try {
AndroidUtilities.addToClipboard(button.button.url);
Toast.makeText(getContext(), LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
FileLog.e(e);
});
builder.show();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setItems(new CharSequence[]{LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("CopyDetails", R.string.CopyDetails)}, (dialogInterface, i) -> {
if (i == 0) {
try {
AndroidUtilities.addToClipboard(button.button.text);
Toast.makeText(getContext(), LocaleController.getString("TextCopied", R.string.TextCopied), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
FileLog.e(e);
}
} else if (i == 1) {
try {
AndroidUtilities.addToClipboard(gson.toJson(button.button));
Toast.makeText(getContext(), LocaleController.getString("TextCopied", R.string.TextCopied), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
FileLog.e(e);
}
}
} else if (i == 2) {
try {
AndroidUtilities.addToClipboard(gson.toJson(button.button));
Toast.makeText(getContext(), LocaleController.getString("TextCopied", R.string.TextCopied), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
FileLog.e(e);
}
}
});
builder.show();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setItems(new CharSequence[]{LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("CopyDetails", R.string.CopyDetails)}, (dialogInterface, i) -> {
if (i == 0) {
try {
AndroidUtilities.addToClipboard(button.button.text);
Toast.makeText(getContext(), LocaleController.getString("TextCopied", R.string.TextCopied), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
FileLog.e(e);
}
} else if (i == 1) {
try {
AndroidUtilities.addToClipboard(gson.toJson(button.button));
Toast.makeText(getContext(), LocaleController.getString("TextCopied", R.string.TextCopied), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
FileLog.e(e);
}
}
});
builder.show();
});
builder.show();
}
}
pressedBotButton = -1;
invalidate();