diff --git a/app/build.gradle b/app/build.gradle index f8fc1565f..0f7ad5f92 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -62,7 +62,7 @@ dependencies { exclude module: 'support-annotations' }) - implementation 'com.github.TeamNewPipe:NewPipeExtractor:ff61e284' + implementation 'com.github.B0pol:NewPipeExtractor:5756df8dc7e89b7383d1d1e07a91c30bdab6f868' 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 f59cfaef0..a297cddf3 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 @@ -2,7 +2,6 @@ package org.schabi.newpipe.fragments.detail; import android.app.Activity; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; @@ -18,7 +17,6 @@ import androidx.fragment.app.Fragment; import androidx.core.content.ContextCompat; import androidx.viewpager.widget.ViewPager; import androidx.appcompat.app.ActionBar; -import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import android.text.Html; import android.text.Spanned; @@ -193,6 +191,14 @@ 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(); + /*////////////////////////////////////////////////////////////////////////*/ @@ -483,7 +489,6 @@ public class VideoDetailFragment videoUploadDateView = rootView.findViewById(R.id.detail_upload_date_view); videoDescriptionView = rootView.findViewById(R.id.detail_description_view); videoDescriptionView.setMovementMethod(LinkMovementMethod.getInstance()); - videoDescriptionView.setAutoLinkMask(Linkify.WEB_URLS); thumbsUpTextView = rootView.findViewById(R.id.detail_thumbs_up_count_view); thumbsUpImageView = rootView.findViewById(R.id.detail_thumbs_up_img_view); @@ -919,28 +924,39 @@ public class VideoDetailFragment return sortedVideoStreams != null ? sortedVideoStreams.get(selectedVideoStreamIndex) : null; } - private void prepareDescription(final String descriptionHtml) { - if (TextUtils.isEmpty(descriptionHtml)) { + private void prepareDescription(final String descriptionText, int descriptionTypeId) { + if (TextUtils.isEmpty(descriptionText)) { return; } - disposables.add(Single.just(descriptionHtml) - .map((@io.reactivex.annotations.NonNull String description) -> { - Spanned parsedDescription; - if (Build.VERSION.SDK_INT >= 24) { - parsedDescription = Html.fromHtml(description, 0); - } else { - //noinspection deprecation - parsedDescription = Html.fromHtml(description); - } - return parsedDescription; - }) - .subscribeOn(Schedulers.computation()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe((@io.reactivex.annotations.NonNull Spanned spanned) -> { - videoDescriptionView.setText(spanned); - videoDescriptionView.setVisibility(View.VISIBLE); - })); + 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) -> { + Spanned parsedDescription; + if (Build.VERSION.SDK_INT >= 24) { + parsedDescription = Html.fromHtml(description, 0); + } else { + //noinspection deprecation + parsedDescription = Html.fromHtml(description); + } + return parsedDescription; + }) + .subscribeOn(Schedulers.computation()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe((@io.reactivex.annotations.NonNull Spanned spanned) -> { + videoDescriptionView.setText(spanned); + videoDescriptionView.setVisibility(View.VISIBLE); + })); + } } private void setHeightThumbnail() { @@ -1126,7 +1142,20 @@ public class VideoDetailFragment videoUploadDateView.setVisibility(View.GONE); } - prepareDescription(info.getDescription()); + 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); + } + updateProgressInfo(info); animateView(spinnerToolbar, true, 500);