Keep bottom hash tags in profile note (fix #1268)

This commit is contained in:
0xd9a 2025-08-05 02:48:52 +05:30
parent 37b744b3e5
commit 43193951c2
4 changed files with 18 additions and 8 deletions

View file

@ -589,7 +589,7 @@ public class ProfileActivity extends BaseActivity {
account.getSpanNote(ProfileActivity.this,
new WeakReference<>(binding.accountNote)), TextView.BufferType.SPANNABLE);
}),
}, true),
TextView.BufferType.SPANNABLE);
binding.accountNote.setMovementMethod(LinkMovementMethod.getInstance());

View file

@ -112,8 +112,8 @@ public class Account implements Serializable {
public synchronized Spannable getSpanNote(Context context, WeakReference<View> viewWeakReference) {
return SpannableHelper.convert(context, note, null, this, null, viewWeakReference, null, true, false);
}
public synchronized Spannable getSpanNote(Context context, WeakReference<View> viewWeakReference, Status.Callback callback) {
return SpannableHelper.convert(context, note, null, this, null, viewWeakReference, callback, true, false);
public synchronized Spannable getSpanNote(Context context, WeakReference<View> viewWeakReference, Status.Callback callback, boolean keepOriginalBottomHashTags) {
return SpannableHelper.convert(context, note, null, this, null, viewWeakReference, callback, true, false, keepOriginalBottomHashTags);
}
@Override

View file

@ -195,7 +195,7 @@ public class Status implements Serializable, Cloneable {
public synchronized Spannable getSpanContent(Context context, boolean checkRemotely, WeakReference<View> viewWeakReference, Callback callback) {
if (contentSpan == null) {
contentSpan = SpannableHelper.convert(context, content, this, null, null, checkRemotely, viewWeakReference, callback, true, true);
contentSpan = SpannableHelper.convert(context, content, this, null, null, checkRemotely, viewWeakReference, callback, true, true, false);
}
return contentSpan;
}

View file

@ -135,12 +135,22 @@ public class SpannableHelper {
public static Spannable convert(Context context, String text,
Status status, Account account, Announcement announcement,
WeakReference<View> viewWeakReference, Status.Callback callback, boolean convertHtml, boolean convertMarkdown) {
return convert(context, text, status, account, announcement, false, viewWeakReference, callback, convertHtml, convertMarkdown);
return convert(context, text, status, account, announcement, false, viewWeakReference, callback, convertHtml, convertMarkdown, false);
}
public static Spannable convert(Context context, String text,
Status status, Account account, Announcement announcement, boolean checkRemotely,
WeakReference<View> viewWeakReference, Status.Callback callback, boolean convertHtml, boolean convertMarkdown) {
Status status, Account account, Announcement announcement, WeakReference<View> viewWeakReference,
Status.Callback callback, boolean convertHtml, boolean convertMarkdown, boolean keepOriginalBottomHashTags) {
return convert(context, text, status, account, announcement, false, viewWeakReference, callback, convertHtml, convertMarkdown, keepOriginalBottomHashTags);
}
/**
* @param keepOriginalBottomHashTags set this to {@code true} to preserve original bottom hash tags. For example, in account note
* <i>(profile bio/description)</i> in {@link app.fedilab.android.mastodon.activities.ProfileActivity ProfileActivity}
*/
public static Spannable convert(Context context, String text, Status status, Account account, Announcement announcement,
boolean checkRemotely, WeakReference<View> viewWeakReference, Status.Callback callback,
boolean convertHtml, boolean convertMarkdown, boolean keepOriginalBottomHashTags) {
if (text == null) {
return null;
}
@ -395,7 +405,7 @@ public class SpannableHelper {
}
boolean underlineBottomHashTags = sharedpreferences.getBoolean(context.getString(R.string.SET_UNDERLINE_BOTTOM_HASHTAGS), true);
if(underlineBottomHashTags) {
if(underlineBottomHashTags && !keepOriginalBottomHashTags) {
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
final Pattern bottomTagsPattern = Pattern.compile(patternBottomTags, Pattern.CASE_INSENSITIVE);
Matcher matcherBottomTags = bottomTagsPattern.matcher(content);