mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-02 06:50:13 +01:00
Use LinkifyCompat.
This commit is contained in:
parent
ebce4c5b7e
commit
464a646671
@ -12,6 +12,7 @@ import android.widget.RelativeLayout;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.core.text.util.LinkifyCompat;
|
||||||
|
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.error.ErrorUtil;
|
import org.schabi.newpipe.error.ErrorUtil;
|
||||||
@ -27,7 +28,7 @@ import org.schabi.newpipe.util.PicassoHelper;
|
|||||||
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
||||||
import org.schabi.newpipe.util.external_communication.TimestampExtractor;
|
import org.schabi.newpipe.util.external_communication.TimestampExtractor;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class CommentsMiniInfoItemHolder extends InfoItemHolder {
|
public class CommentsMiniInfoItemHolder extends InfoItemHolder {
|
||||||
private static final String TAG = "CommentsMiniIIHolder";
|
private static final String TAG = "CommentsMiniIIHolder";
|
||||||
@ -39,7 +40,7 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder {
|
|||||||
private final int commentVerticalPadding;
|
private final int commentVerticalPadding;
|
||||||
|
|
||||||
private final RelativeLayout itemRoot;
|
private final RelativeLayout itemRoot;
|
||||||
public final ImageView itemThumbnailView;
|
private final ImageView itemThumbnailView;
|
||||||
private final TextView itemContentView;
|
private final TextView itemContentView;
|
||||||
private final TextView itemLikesCountView;
|
private final TextView itemLikesCountView;
|
||||||
private final TextView itemPublishedTime;
|
private final TextView itemPublishedTime;
|
||||||
@ -47,27 +48,6 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder {
|
|||||||
private String commentText;
|
private String commentText;
|
||||||
private String streamUrl;
|
private String streamUrl;
|
||||||
|
|
||||||
private final Linkify.TransformFilter timestampLink = new Linkify.TransformFilter() {
|
|
||||||
@Override
|
|
||||||
public String transformUrl(final Matcher match, final String url) {
|
|
||||||
try {
|
|
||||||
final TimestampExtractor.TimestampMatchDTO timestampMatchDTO =
|
|
||||||
TimestampExtractor.getTimestampFromMatcher(match, commentText);
|
|
||||||
|
|
||||||
if (timestampMatchDTO == null) {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
return streamUrl + url.replace(
|
|
||||||
match.group(0),
|
|
||||||
"#timestamp=" + timestampMatchDTO.seconds());
|
|
||||||
} catch (final Exception ex) {
|
|
||||||
Log.e(TAG, "Unable to process url='" + url + "' as timestampLink", ex);
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
CommentsMiniInfoItemHolder(final InfoItemBuilder infoItemBuilder, final int layoutId,
|
CommentsMiniInfoItemHolder(final InfoItemBuilder infoItemBuilder, final int layoutId,
|
||||||
final ViewGroup parent) {
|
final ViewGroup parent) {
|
||||||
super(infoItemBuilder, layoutId, parent);
|
super(infoItemBuilder, layoutId, parent);
|
||||||
@ -243,14 +223,21 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void linkify() {
|
private void linkify() {
|
||||||
Linkify.addLinks(
|
LinkifyCompat.addLinks(itemContentView, Linkify.WEB_URLS);
|
||||||
itemContentView,
|
LinkifyCompat.addLinks(itemContentView, TimestampExtractor.TIMESTAMPS_PATTERN, null, null,
|
||||||
Linkify.WEB_URLS);
|
(match, url) -> {
|
||||||
Linkify.addLinks(
|
try {
|
||||||
itemContentView,
|
final var timestampMatch = TimestampExtractor
|
||||||
TimestampExtractor.TIMESTAMPS_PATTERN,
|
.getTimestampFromMatcher(match, commentText);
|
||||||
null,
|
if (timestampMatch == null) {
|
||||||
null,
|
return url;
|
||||||
timestampLink);
|
}
|
||||||
|
return streamUrl + url.replace(Objects.requireNonNull(match.group(0)),
|
||||||
|
"#timestamp=" + timestampMatch.seconds());
|
||||||
|
} catch (final Exception ex) {
|
||||||
|
Log.e(TAG, "Unable to process url='" + url + "' as timestampLink", ex);
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user