Initial work: add support for opening timestamps in plain text descriptions

This commit adds support for opening plain text timestamps by parsing the description text using a regular expression, add a click listener for each timestamp which opens the popup player at the indicated time in the timestamp.
In order to do this, playOnPopup method of the URLHandler class. Also, handleUrl method of this class has been renamed to canHandleUrl.
This commit is contained in:
TiA4f8R 2021-03-13 12:20:45 +01:00
parent 2f9ffe61db
commit 27687b18e8
5 changed files with 150 additions and 40 deletions

View file

@ -19,6 +19,7 @@ import org.schabi.newpipe.R;
import org.schabi.newpipe.databinding.FragmentDescriptionBinding;
import org.schabi.newpipe.databinding.ItemMetadataBinding;
import org.schabi.newpipe.databinding.ItemMetadataTagsBinding;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.stream.Description;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.util.Localization;
@ -131,19 +132,24 @@ public class DescriptionFragment extends BaseFragment {
private void loadDescriptionContent() {
final Description description = streamInfo.getDescription();
final String contentUrl = streamInfo.getUrl();
final StreamingService service = streamInfo.getService();
switch (description.getType()) {
case Description.HTML:
descriptionDisposable = TextLinkifier.createLinksFromHtmlBlock(requireContext(),
description.getContent(), binding.detailDescriptionView,
HtmlCompat.FROM_HTML_MODE_LEGACY);
service, contentUrl, HtmlCompat.FROM_HTML_MODE_LEGACY);
break;
case Description.MARKDOWN:
descriptionDisposable = TextLinkifier.createLinksFromMarkdownText(requireContext(),
description.getContent(), binding.detailDescriptionView);
description.getContent(), binding.detailDescriptionView,
service, contentUrl);
break;
case Description.PLAIN_TEXT: default:
descriptionDisposable = TextLinkifier.createLinksFromPlainText(requireContext(),
description.getContent(), binding.detailDescriptionView);
description.getContent(), binding.detailDescriptionView,
service, contentUrl);
break;
}
}
@ -199,7 +205,7 @@ public class DescriptionFragment extends BaseFragment {
if (linkifyContent) {
TextLinkifier.createLinksFromPlainText(requireContext(),
content, itemBinding.metadataContentView);
content, itemBinding.metadataContentView, null, null);
} else {
itemBinding.metadataContentView.setText(content);
}