Skip to content

Commit 3e3d1fd

Browse files
Merge pull request #11075 from Isira-Seneviratne/Comment-touch-lambda
Convert comment touch listener to a lambda
2 parents 8645618 + 4613934 commit 3e3d1fd

2 files changed

Lines changed: 24 additions & 44 deletions

File tree

app/src/main/java/org/schabi/newpipe/info_list/holder/CommentInfoItemHolder.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package org.schabi.newpipe.info_list.holder;
22

33
import static org.schabi.newpipe.util.ServiceHelper.getServiceById;
4+
import static org.schabi.newpipe.util.text.TouchUtils.getOffsetForHorizontalLine;
45

6+
import android.text.Spanned;
57
import android.text.method.LinkMovementMethod;
8+
import android.text.style.ClickableSpan;
69
import android.text.style.URLSpan;
10+
import android.view.MotionEvent;
711
import android.view.View;
812
import android.view.ViewGroup;
913
import android.widget.Button;
@@ -25,7 +29,6 @@
2529
import org.schabi.newpipe.util.external_communication.ShareUtils;
2630
import org.schabi.newpipe.util.image.ImageStrategy;
2731
import org.schabi.newpipe.util.image.PicassoHelper;
28-
import org.schabi.newpipe.util.text.CommentTextOnTouchListener;
2932
import org.schabi.newpipe.util.text.TextEllipsizer;
3033

3134
public class CommentInfoItemHolder extends InfoItemHolder {
@@ -128,7 +131,26 @@ public void updateFromItem(final InfoItem infoItem,
128131
textEllipsizer.ellipsize();
129132

130133
//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+
});
132154

133155
itemView.setOnClickListener(view -> {
134156
textEllipsizer.toggle();

app/src/main/java/org/schabi/newpipe/util/text/CommentTextOnTouchListener.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)