|
1 | 1 | package org.schabi.newpipe.info_list.holder; |
2 | 2 |
|
3 | 3 | import static org.schabi.newpipe.util.ServiceHelper.getServiceById; |
| 4 | +import static org.schabi.newpipe.util.text.TouchUtils.getOffsetForHorizontalLine; |
4 | 5 |
|
| 6 | +import android.text.Spanned; |
5 | 7 | import android.text.method.LinkMovementMethod; |
| 8 | +import android.text.style.ClickableSpan; |
6 | 9 | import android.text.style.URLSpan; |
| 10 | +import android.view.MotionEvent; |
7 | 11 | import android.view.View; |
8 | 12 | import android.view.ViewGroup; |
9 | 13 | import android.widget.Button; |
|
25 | 29 | import org.schabi.newpipe.util.external_communication.ShareUtils; |
26 | 30 | import org.schabi.newpipe.util.image.ImageStrategy; |
27 | 31 | import org.schabi.newpipe.util.image.PicassoHelper; |
28 | | -import org.schabi.newpipe.util.text.CommentTextOnTouchListener; |
29 | 32 | import org.schabi.newpipe.util.text.TextEllipsizer; |
30 | 33 |
|
31 | 34 | public class CommentInfoItemHolder extends InfoItemHolder { |
@@ -128,7 +131,26 @@ public void updateFromItem(final InfoItem infoItem, |
128 | 131 | textEllipsizer.ellipsize(); |
129 | 132 |
|
130 | 133 | //noinspection ClickableViewAccessibility |
131 | | - itemContentView.setOnTouchListener(CommentTextOnTouchListener.INSTANCE); |
| 134 | + itemContentView.setOnTouchListener((v, event) -> { |
| 135 | + final CharSequence text = itemContentView.getText(); |
| 136 | + if (text instanceof Spanned buffer) { |
| 137 | + final int action = event.getAction(); |
| 138 | + |
| 139 | + if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) { |
| 140 | + final int offset = getOffsetForHorizontalLine(itemContentView, event); |
| 141 | + final var links = buffer.getSpans(offset, offset, ClickableSpan.class); |
| 142 | + |
| 143 | + if (links.length != 0) { |
| 144 | + if (action == MotionEvent.ACTION_UP) { |
| 145 | + links[0].onClick(itemContentView); |
| 146 | + } |
| 147 | + // we handle events that intersect links, so return true |
| 148 | + return true; |
| 149 | + } |
| 150 | + } |
| 151 | + } |
| 152 | + return false; |
| 153 | + }); |
132 | 154 |
|
133 | 155 | itemView.setOnClickListener(view -> { |
134 | 156 | textEllipsizer.toggle(); |
|
0 commit comments