Commit 43193951 authored by 0xd9a's avatar 0xd9a
Browse files

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

parent 37b744b3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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());
+2 −2
Original line number Diff line number Diff line
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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;
    }
+14 −4
Original line number Diff line number Diff line
@@ -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);