Skip to content

Commit

Permalink
fix thumbnail for PeerTube, and description changes
Browse files Browse the repository at this point in the history
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 TeamNewPipe/NewPipeExtractor#239, so it need to be merged before this PR
  • Loading branch information
B0pol committed Feb 2, 2020
1 parent b589ee6 commit c95126f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ dependencies {
exclude module: 'support-annotations'
})

implementation 'com.github.TeamNewPipe:NewPipeExtractor:ff61e284'
implementation 'com.github.B0pol:NewPipeExtractor:b671a4ba18611f6d0e76789ba1e07ecb4d8045e9'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();


/*////////////////////////////////////////////////////////////////////////*/

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c95126f

Please sign in to comment.