fix thumbnail for PeerTube, and description changes

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
This commit is contained in:
bopol 2020-02-02 16:54:09 +01:00
parent b589ee6c26
commit 7045f9711c
2 changed files with 53 additions and 24 deletions

View File

@ -62,7 +62,7 @@ dependencies {
exclude module: 'support-annotations' exclude module: 'support-annotations'
}) })
implementation 'com.github.TeamNewPipe:NewPipeExtractor:ff61e284' implementation 'com.github.B0pol:NewPipeExtractor:5756df8dc7e89b7383d1d1e07a91c30bdab6f868'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.0' testImplementation 'org.mockito:mockito-core:2.23.0'

View File

@ -2,7 +2,6 @@ package org.schabi.newpipe.fragments.detail;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
@ -18,7 +17,6 @@ import androidx.fragment.app.Fragment;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.text.Html; import android.text.Html;
import android.text.Spanned; import android.text.Spanned;
@ -193,6 +191,14 @@ public class VideoDetailFragment
private TabLayout tabLayout; private TabLayout tabLayout;
private FrameLayout relatedStreamsLayout; 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); videoUploadDateView = rootView.findViewById(R.id.detail_upload_date_view);
videoDescriptionView = rootView.findViewById(R.id.detail_description_view); videoDescriptionView = rootView.findViewById(R.id.detail_description_view);
videoDescriptionView.setMovementMethod(LinkMovementMethod.getInstance()); videoDescriptionView.setMovementMethod(LinkMovementMethod.getInstance());
videoDescriptionView.setAutoLinkMask(Linkify.WEB_URLS);
thumbsUpTextView = rootView.findViewById(R.id.detail_thumbs_up_count_view); thumbsUpTextView = rootView.findViewById(R.id.detail_thumbs_up_count_view);
thumbsUpImageView = rootView.findViewById(R.id.detail_thumbs_up_img_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; return sortedVideoStreams != null ? sortedVideoStreams.get(selectedVideoStreamIndex) : null;
} }
private void prepareDescription(final String descriptionHtml) { private void prepareDescription(final String descriptionText, int descriptionTypeId) {
if (TextUtils.isEmpty(descriptionHtml)) { if (TextUtils.isEmpty(descriptionText)) {
return; return;
} }
disposables.add(Single.just(descriptionHtml) if (descriptionTypeId == DESCRIPTION_PLAIN_TEXT) {
.map((@io.reactivex.annotations.NonNull String description) -> { videoDescriptionView.setText(descriptionText, TextView.BufferType.SPANNABLE);
Spanned parsedDescription; videoDescriptionView.setVisibility(View.VISIBLE);
if (Build.VERSION.SDK_INT >= 24) { } else if (descriptionTypeId == DESCRIPTION_MARKDOWN) {
parsedDescription = Html.fromHtml(description, 0); //in the future we would use a library or a good method to show markdown.
} else { //rn, we just remove **bold**, and let plain_text otherwise
//noinspection deprecation videoDescriptionView.setText(descriptionText.replace("**", ""), TextView.BufferType.SPANNABLE);
parsedDescription = Html.fromHtml(description); videoDescriptionView.setVisibility(View.VISIBLE);
} } else {
return parsedDescription; //== DESCRIPTION_HTML
}) disposables.add(Single.just(descriptionText)
.subscribeOn(Schedulers.computation()) .map((@io.reactivex.annotations.NonNull String description) -> {
.observeOn(AndroidSchedulers.mainThread()) Spanned parsedDescription;
.subscribe((@io.reactivex.annotations.NonNull Spanned spanned) -> { if (Build.VERSION.SDK_INT >= 24) {
videoDescriptionView.setText(spanned); parsedDescription = Html.fromHtml(description, 0);
videoDescriptionView.setVisibility(View.VISIBLE); } 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() { private void setHeightThumbnail() {
@ -1126,7 +1142,20 @@ public class VideoDetailFragment
videoUploadDateView.setVisibility(View.GONE); 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); updateProgressInfo(info);
animateView(spinnerToolbar, true, 500); animateView(spinnerToolbar, true, 500);