1212import android .widget .TextView ;
1313
1414import androidx .appcompat .app .AppCompatActivity ;
15+ import androidx .core .text .util .LinkifyCompat ;
1516
1617import org .schabi .newpipe .R ;
1718import org .schabi .newpipe .error .ErrorUtil ;
2728import org .schabi .newpipe .util .external_communication .ShareUtils ;
2829import org .schabi .newpipe .util .external_communication .TimestampExtractor ;
2930
30- import java .util .regex . Matcher ;
31+ import java .util .Objects ;
3132
3233public class CommentsMiniInfoItemHolder extends InfoItemHolder {
3334 private static final String TAG = "CommentsMiniIIHolder" ;
@@ -39,35 +40,14 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder {
3940 private final int commentVerticalPadding ;
4041
4142 private final RelativeLayout itemRoot ;
42- public final ImageView itemThumbnailView ;
43+ private final ImageView itemThumbnailView ;
4344 private final TextView itemContentView ;
4445 private final TextView itemLikesCountView ;
4546 private final TextView itemPublishedTime ;
4647
4748 private String commentText ;
4849 private String streamUrl ;
4950
50- private final Linkify .TransformFilter timestampLink = new Linkify .TransformFilter () {
51- @ Override
52- public String transformUrl (final Matcher match , final String url ) {
53- try {
54- final TimestampExtractor .TimestampMatchDTO timestampMatchDTO =
55- TimestampExtractor .getTimestampFromMatcher (match , commentText );
56-
57- if (timestampMatchDTO == null ) {
58- return url ;
59- }
60-
61- return streamUrl + url .replace (
62- match .group (0 ),
63- "#timestamp=" + timestampMatchDTO .seconds ());
64- } catch (final Exception ex ) {
65- Log .e (TAG , "Unable to process url='" + url + "' as timestampLink" , ex );
66- return url ;
67- }
68- }
69- };
70-
7151 CommentsMiniInfoItemHolder (final InfoItemBuilder infoItemBuilder , final int layoutId ,
7252 final ViewGroup parent ) {
7353 super (infoItemBuilder , layoutId , parent );
@@ -243,14 +223,21 @@ private void expand() {
243223 }
244224
245225 private void linkify () {
246- Linkify .addLinks (
247- itemContentView ,
248- Linkify .WEB_URLS );
249- Linkify .addLinks (
250- itemContentView ,
251- TimestampExtractor .TIMESTAMPS_PATTERN ,
252- null ,
253- null ,
254- timestampLink );
226+ LinkifyCompat .addLinks (itemContentView , Linkify .WEB_URLS );
227+ LinkifyCompat .addLinks (itemContentView , TimestampExtractor .TIMESTAMPS_PATTERN , null , null ,
228+ (match , url ) -> {
229+ try {
230+ final var timestampMatch = TimestampExtractor
231+ .getTimestampFromMatcher (match , commentText );
232+ if (timestampMatch == null ) {
233+ return url ;
234+ }
235+ return streamUrl + url .replace (Objects .requireNonNull (match .group (0 )),
236+ "#timestamp=" + timestampMatch .seconds ());
237+ } catch (final Exception ex ) {
238+ Log .e (TAG , "Unable to process url='" + url + "' as timestampLink" , ex );
239+ return url ;
240+ }
241+ });
255242 }
256243}
0 commit comments