From 7045f9711c04a4a0610553f605c8c69a7fd4f21f Mon Sep 17 00:00:00 2001 From: bopol Date: Sun, 2 Feb 2020 16:54:09 +0100 Subject: [PATCH] fix thumbnail for PeerTube, and description changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit description: - PeerTube: it's now full description (it cut at 250 characters before), and it displays ok (newlines are ok, but markdown isn't) - MediaCCC: descriptions are now displayed well (newlines added) - YouTube: timestamps in descriptions are clickable and work more PeerTube fixes: thumbnail is now high quality age limit is now handled upload date in «recently added» feed is good now (it was one hour delayed) all fixes come from https://github.com/TeamNewPipe/NewPipeExtractor/pull/239, so it need to be merged before this PR --- app/build.gradle | 2 +- .../fragments/detail/VideoDetailFragment.java | 75 +++++++++++++------ 2 files changed, 53 insertions(+), 24 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f8fc1565fcf..0f7ad5f9233 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 f59cfaef0b4..a297cddf372 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 @@ 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.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 @@ protected void initViews(View rootView, Bundle savedInstanceState) { 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 @@ private VideoStream getSelectedVideoStream() { 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 void handleResult(@NonNull StreamInfo info) { 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);