Fix issue #931 - Click on card does not open Mastodon posts inside the app

This commit is contained in:
Thomas 2023-08-09 16:59:40 +02:00
parent 243039151a
commit 65b9015d51
2 changed files with 111 additions and 106 deletions

View File

@ -598,6 +598,21 @@ public class SpannableHelper {
public void onClick(@NonNull View textView) { public void onClick(@NonNull View textView) {
textView.setTag(CLICKABLE_SPAN); textView.setTag(CLICKABLE_SPAN);
linkClickAction(context, finalUrl);
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (linkColor != -1) {
ds.setColor(linkColor);
}
}
}, start, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
public static void linkClickAction(Context context, String finalUrl) {
Pattern link = Pattern.compile("https?://([\\da-z.-]+\\.[a-z.]{2,10})/(@[\\w._-]*[0-9]*)(/[0-9]+)?$"); Pattern link = Pattern.compile("https?://([\\da-z.-]+\\.[a-z.]{2,10})/(@[\\w._-]*[0-9]*)(/[0-9]+)?$");
Matcher matcherLink = link.matcher(finalUrl); Matcher matcherLink = link.matcher(finalUrl);
Pattern linkLong = Pattern.compile("https?://([\\da-z.-]+\\.[a-z.]{2,10})/(@[\\w_.-]+@[a-zA-Z0-9][a-zA-Z0-9.-]{1,61}[a-zA-Z0-9](?:\\.[a-zA-Z]{2,})+)(/[0-9]+)?$"); Pattern linkLong = Pattern.compile("https?://([\\da-z.-]+\\.[a-z.]{2,10})/(@[\\w_.-]+@[a-zA-Z0-9][a-zA-Z0-9.-]{1,61}[a-zA-Z0-9](?:\\.[a-zA-Z]{2,})+)(/[0-9]+)?$");
@ -705,18 +720,6 @@ public class SpannableHelper {
} }
} }
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (linkColor != -1) {
ds.setColor(linkColor);
}
}
}, start, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
private static void emails(Context context, Spannable content) { private static void emails(Context context, Spannable content) {
// --- For all patterns defined in Helper class --- // --- For all patterns defined in Helper class ---
Pattern pattern = Helper.emailPattern; Pattern pattern = Helper.emailPattern;

View File

@ -844,7 +844,9 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.cardTitle.setText(statusToDeal.card.title); holder.binding.cardTitle.setText(statusToDeal.card.title);
holder.binding.cardDescription.setText(statusToDeal.card.description); holder.binding.cardDescription.setText(statusToDeal.card.description);
holder.binding.cardUrl.setText(Helper.transformURL(context, statusToDeal.card.url)); holder.binding.cardUrl.setText(Helper.transformURL(context, statusToDeal.card.url));
holder.binding.card.setOnClickListener(v -> Helper.openBrowser(context, Helper.transformURL(context, statusToDeal.card.url))); holder.binding.card.setOnClickListener(v -> {
SpannableHelper.linkClickAction(context, statusToDeal.card.url);
});
holder.binding.card.setVisibility(View.VISIBLE); holder.binding.card.setVisibility(View.VISIBLE);
} else { } else {
holder.binding.card.setVisibility(View.GONE); holder.binding.card.setVisibility(View.GONE);