From 75139a852376c047b065ff244720991dc7b66da6 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 22 Mar 2023 17:43:35 +0100 Subject: [PATCH] Fix issue #830 - Poll having html --- .../mastodon/client/entities/api/Poll.java | 2 +- .../mastodon/helper/SpannableHelper.java | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Poll.java b/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Poll.java index ec5a37db..e9270f06 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Poll.java +++ b/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Poll.java @@ -61,7 +61,7 @@ public class Poll implements Serializable { public transient Spannable span_title; public Spannable getSpanTitle(Context context, Status status, WeakReference viewWeakReference) { - span_title = SpannableHelper.convert(context, title, status, null, null, viewWeakReference); + span_title = SpannableHelper.convert(context, title, status, null, null, viewWeakReference, null, false); return span_title; } } diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java index f9947510..00549a0d 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java @@ -95,12 +95,18 @@ public class SpannableHelper { public static Spannable convert(Context context, String text, Status status, Account account, Announcement announcement, WeakReference viewWeakReference) { - return convert(context, text, status, account, announcement, viewWeakReference, null); + return convert(context, text, status, account, announcement, viewWeakReference, null, true); } public static Spannable convert(Context context, String text, Status status, Account account, Announcement announcement, WeakReference viewWeakReference, Status.Callback callback) { + return convert(context, text, status, account, announcement, viewWeakReference, callback, true); + } + + public static Spannable convert(Context context, String text, + Status status, Account account, Announcement announcement, + WeakReference viewWeakReference, Status.Callback callback, boolean convertHtml) { if (text == null) { return null; } @@ -133,10 +139,14 @@ public class SpannableHelper { text = text.trim().replaceAll("\\s{3}", "   "); text = text.trim().replaceAll("\\s{2}", "  "); SpannableString initialContent; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - initialContent = new SpannableString(Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY)); - else - initialContent = new SpannableString(Html.fromHtml(text)); + if (convertHtml) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + initialContent = new SpannableString(Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY)); + else + initialContent = new SpannableString(Html.fromHtml(text)); + } else { + initialContent = new SpannableString(text); + } //Get all links SpannableStringBuilder content = new SpannableStringBuilder(initialContent);