Fix issue #226 - Crashes when long pressing links on some messages

This commit is contained in:
Thomas 2022-07-05 07:44:43 +02:00
parent 0f513f00c4
commit 6219c010d0
1 changed files with 6 additions and 4 deletions

View File

@ -256,14 +256,15 @@ public class SpannableHelper {
content.setSpan(new LongClickableSpan() { content.setSpan(new LongClickableSpan() {
@Override @Override
public void onLongClick(View view) { public void onLongClick(View view) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context, Helper.dialogStyle()); Context mContext = view.getContext();
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext, Helper.dialogStyle());
PopupLinksBinding popupLinksBinding = PopupLinksBinding.inflate(LayoutInflater.from(context)); PopupLinksBinding popupLinksBinding = PopupLinksBinding.inflate(LayoutInflater.from(context));
dialogBuilder.setView(popupLinksBinding.getRoot()); dialogBuilder.setView(popupLinksBinding.getRoot());
AlertDialog alertDialog = dialogBuilder.create(); AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show(); alertDialog.show();
popupLinksBinding.displayFullLink.setOnClickListener(v -> { popupLinksBinding.displayFullLink.setOnClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(context, Helper.dialogStyle()); AlertDialog.Builder builder = new AlertDialog.Builder(mContext, Helper.dialogStyle());
builder.setMessage(url); builder.setMessage(url);
builder.setTitle(context.getString(R.string.display_full_link)); builder.setTitle(context.getString(R.string.display_full_link));
builder.setPositiveButton(R.string.close, (dialog, which) -> dialog.dismiss()) builder.setPositiveButton(R.string.close, (dialog, which) -> dialog.dismiss())
@ -720,14 +721,15 @@ public class SpannableHelper {
content.setSpan(new LongClickableSpan() { content.setSpan(new LongClickableSpan() {
@Override @Override
public void onLongClick(View view) { public void onLongClick(View view) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(view.getContext(), Helper.dialogStyle()); Context mContext = view.getContext();
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext, Helper.dialogStyle());
PopupLinksBinding popupLinksBinding = PopupLinksBinding.inflate(LayoutInflater.from(context)); PopupLinksBinding popupLinksBinding = PopupLinksBinding.inflate(LayoutInflater.from(context));
dialogBuilder.setView(popupLinksBinding.getRoot()); dialogBuilder.setView(popupLinksBinding.getRoot());
AlertDialog alertDialog = dialogBuilder.create(); AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show(); alertDialog.show();
popupLinksBinding.displayFullLink.setOnClickListener(v -> { popupLinksBinding.displayFullLink.setOnClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(context, Helper.dialogStyle()); AlertDialog.Builder builder = new AlertDialog.Builder(mContext, Helper.dialogStyle());
builder.setMessage(url); builder.setMessage(url);
builder.setTitle(context.getString(R.string.display_full_link)); builder.setTitle(context.getString(R.string.display_full_link));
builder.setPositiveButton(R.string.close, (dialog, which) -> dialog.dismiss()) builder.setPositiveButton(R.string.close, (dialog, which) -> dialog.dismiss())