diff --git a/app/build.gradle b/app/build.gradle index 0f7ad5f92..728d380c4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -62,7 +62,7 @@ dependencies { exclude module: 'support-annotations' }) - implementation 'com.github.B0pol:NewPipeExtractor:5756df8dc7e89b7383d1d1e07a91c30bdab6f868' + implementation 'com.github.B0pol:NewPipeExtractor:11bcc78d9c8eb39e8d61a6f4bc4112025937f087' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.23.0' diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index a297cddf3..c6c8ca04c 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -56,6 +56,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; import org.schabi.newpipe.extractor.stream.AudioStream; +import org.schabi.newpipe.extractor.stream.Description; import org.schabi.newpipe.extractor.stream.Stream; import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.StreamType; @@ -191,14 +192,6 @@ public class VideoDetailFragment private TabLayout tabLayout; private FrameLayout relatedStreamsLayout; - private static final int DESCRIPTION_HTML = 1; - private static final int DESCRIPTION_MARKDOWN = 2; - private static final int DESCRIPTION_PLAIN_TEXT = 3; - - private static final int YOUTUBE_SERVICE_ID = ServiceList.YouTube.getServiceId(); - private static final int MEDIACCC_SERVICE_ID = ServiceList.MediaCCC.getServiceId(); - private static final int PEERTUBE_SERVICE_ID = ServiceList.PeerTube.getServiceId(); - /*////////////////////////////////////////////////////////////////////////*/ @@ -924,29 +917,24 @@ public class VideoDetailFragment return sortedVideoStreams != null ? sortedVideoStreams.get(selectedVideoStreamIndex) : null; } - private void prepareDescription(final String descriptionText, int descriptionTypeId) { - if (TextUtils.isEmpty(descriptionText)) { + private void prepareDescription(Description description) { + if (TextUtils.isEmpty(description.getContent()) || description == Description.emptyDescription) { return; } - if (descriptionTypeId == DESCRIPTION_PLAIN_TEXT) { - videoDescriptionView.setText(descriptionText, TextView.BufferType.SPANNABLE); - videoDescriptionView.setVisibility(View.VISIBLE); - } else if (descriptionTypeId == DESCRIPTION_MARKDOWN) { - //in the future we would use a library or a good method to show markdown. - //rn, we just remove **bold**, and let plain_text otherwise - videoDescriptionView.setText(descriptionText.replace("**", ""), TextView.BufferType.SPANNABLE); - videoDescriptionView.setVisibility(View.VISIBLE); - } else { - //== DESCRIPTION_HTML - disposables.add(Single.just(descriptionText) - .map((@io.reactivex.annotations.NonNull String description) -> { + if (description.getType() != Description.HTML) { + videoDescriptionView.setAutoLinkMask(Linkify.WEB_URLS); + } + + if (description.getType() == Description.HTML) { + disposables.add(Single.just(description.getContent()) + .map((@io.reactivex.annotations.NonNull String descriptionText) -> { Spanned parsedDescription; if (Build.VERSION.SDK_INT >= 24) { - parsedDescription = Html.fromHtml(description, 0); + parsedDescription = Html.fromHtml(descriptionText, 0); } else { //noinspection deprecation - parsedDescription = Html.fromHtml(description); + parsedDescription = Html.fromHtml(descriptionText); } return parsedDescription; }) @@ -956,6 +944,15 @@ public class VideoDetailFragment videoDescriptionView.setText(spanned); videoDescriptionView.setVisibility(View.VISIBLE); })); + } else if (description.getType() == Description.MARKDOWN) { + //in the future we would use a library or a good method to show markdown. + //rn, we just remove **bold**, and let PLAIN_TEXT otherwise + videoDescriptionView.setText(description.getContent().replace("**", ""), TextView.BufferType.SPANNABLE); + videoDescriptionView.setVisibility(View.VISIBLE); + } else { + //== Description.PLAIN_TEXT + videoDescriptionView.setText(description.getContent(), TextView.BufferType.SPANNABLE); + videoDescriptionView.setVisibility(View.VISIBLE); } } @@ -1142,20 +1139,7 @@ public class VideoDetailFragment videoUploadDateView.setVisibility(View.GONE); } - int serviceId = info.getServiceId(); - - if (serviceId != YOUTUBE_SERVICE_ID) { - videoDescriptionView.setAutoLinkMask(Linkify.WEB_URLS); - } - - if (serviceId == PEERTUBE_SERVICE_ID) { - prepareDescription(info.getDescription(), DESCRIPTION_MARKDOWN); - } else if (serviceId == MEDIACCC_SERVICE_ID) { - prepareDescription(info.getDescription(), DESCRIPTION_PLAIN_TEXT); - } else { - prepareDescription(info.getDescription(), DESCRIPTION_HTML); - } - + prepareDescription(info.getDescription()); updateProgressInfo(info); animateView(spinnerToolbar, true, 500);