mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-01-09 17:00:32 +00:00
refactor Description
This commit is contained in:
parent
7045f9711c
commit
badaff8ebc
@ -62,7 +62,7 @@ dependencies {
|
|||||||
exclude module: 'support-annotations'
|
exclude module: 'support-annotations'
|
||||||
})
|
})
|
||||||
|
|
||||||
implementation 'com.github.B0pol:NewPipeExtractor:5756df8dc7e89b7383d1d1e07a91c30bdab6f868'
|
implementation 'com.github.B0pol:NewPipeExtractor:11bcc78d9c8eb39e8d61a6f4bc4112025937f087'
|
||||||
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'
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor;
|
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor;
|
||||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
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.Stream;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||||
@ -191,14 +192,6 @@ 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();
|
|
||||||
|
|
||||||
|
|
||||||
/*////////////////////////////////////////////////////////////////////////*/
|
/*////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
@ -924,29 +917,24 @@ public class VideoDetailFragment
|
|||||||
return sortedVideoStreams != null ? sortedVideoStreams.get(selectedVideoStreamIndex) : null;
|
return sortedVideoStreams != null ? sortedVideoStreams.get(selectedVideoStreamIndex) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareDescription(final String descriptionText, int descriptionTypeId) {
|
private void prepareDescription(Description description) {
|
||||||
if (TextUtils.isEmpty(descriptionText)) {
|
if (TextUtils.isEmpty(description.getContent()) || description == Description.emptyDescription) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (descriptionTypeId == DESCRIPTION_PLAIN_TEXT) {
|
if (description.getType() != Description.HTML) {
|
||||||
videoDescriptionView.setText(descriptionText, TextView.BufferType.SPANNABLE);
|
videoDescriptionView.setAutoLinkMask(Linkify.WEB_URLS);
|
||||||
videoDescriptionView.setVisibility(View.VISIBLE);
|
}
|
||||||
} else if (descriptionTypeId == DESCRIPTION_MARKDOWN) {
|
|
||||||
//in the future we would use a library or a good method to show markdown.
|
if (description.getType() == Description.HTML) {
|
||||||
//rn, we just remove **bold**, and let plain_text otherwise
|
disposables.add(Single.just(description.getContent())
|
||||||
videoDescriptionView.setText(descriptionText.replace("**", ""), TextView.BufferType.SPANNABLE);
|
.map((@io.reactivex.annotations.NonNull String descriptionText) -> {
|
||||||
videoDescriptionView.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
//== DESCRIPTION_HTML
|
|
||||||
disposables.add(Single.just(descriptionText)
|
|
||||||
.map((@io.reactivex.annotations.NonNull String description) -> {
|
|
||||||
Spanned parsedDescription;
|
Spanned parsedDescription;
|
||||||
if (Build.VERSION.SDK_INT >= 24) {
|
if (Build.VERSION.SDK_INT >= 24) {
|
||||||
parsedDescription = Html.fromHtml(description, 0);
|
parsedDescription = Html.fromHtml(descriptionText, 0);
|
||||||
} else {
|
} else {
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
parsedDescription = Html.fromHtml(description);
|
parsedDescription = Html.fromHtml(descriptionText);
|
||||||
}
|
}
|
||||||
return parsedDescription;
|
return parsedDescription;
|
||||||
})
|
})
|
||||||
@ -956,6 +944,15 @@ public class VideoDetailFragment
|
|||||||
videoDescriptionView.setText(spanned);
|
videoDescriptionView.setText(spanned);
|
||||||
videoDescriptionView.setVisibility(View.VISIBLE);
|
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);
|
videoUploadDateView.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int serviceId = info.getServiceId();
|
prepareDescription(info.getDescription());
|
||||||
|
|
||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user