Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class CommentSectionInstrumentedTest {
fun commentListLoadsAndScrolls() {
val comments = (1..25).map { index ->
CommentsInfoItem(
commentText = Description("Comment $index", Description.PLAIN_TEXT),
commentText = Description("Comment $index", Description.Type.PLAIN_TEXT),
uploaderName = "Uploader $index",
replies = Page(""),
replyCount = 0
Expand Down Expand Up @@ -135,7 +135,7 @@ class CommentSectionInstrumentedTest {
.performClick()

val recoveredComment = CommentsInfoItem(
commentText = Description("Recovered comment", Description.PLAIN_TEXT),
commentText = Description("Recovered comment", Description.Type.PLAIN_TEXT),
uploaderName = "Uploader",
replies = Page(""),
replyCount = 0
Expand Down Expand Up @@ -181,7 +181,7 @@ class CommentSectionInstrumentedTest {
.performClick()

val recoveredComment = CommentsInfoItem(
commentText = Description("Recovered comment", Description.PLAIN_TEXT),
commentText = Description("Recovered comment", Description.Type.PLAIN_TEXT),
uploaderName = "Uploader",
replies = Page(""),
replyCount = 0
Expand Down Expand Up @@ -226,7 +226,7 @@ class CommentSectionInstrumentedTest {
.performClick()

val firstComment = CommentsInfoItem(
commentText = Description("First comment", Description.PLAIN_TEXT),
commentText = Description("First comment", Description.Type.PLAIN_TEXT),
uploaderName = "Uploader",
replies = Page(""),
replyCount = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.schabi.newpipe.fragments.detail;

import static android.text.TextUtils.isEmpty;
import static org.schabi.newpipe.extractor.utils.Utils.isBlank;
import static org.schabi.newpipe.util.text.TextLinkifier.SET_LINK_MOVEMENT_METHOD;

Expand Down Expand Up @@ -38,6 +37,7 @@
import org.schabi.newpipe.util.text.TextLinkifier;

import java.util.List;
import java.util.Optional;

import io.reactivex.rxjava3.disposables.CompositeDisposable;

Expand Down Expand Up @@ -66,8 +66,8 @@ public void onDestroy() {
* Get the description to display.
* @return description object, if available
*/
@Nullable
protected abstract Description getDescription();
@NonNull
protected abstract Optional<Description> getDescription();

/**
* Get the streaming service. Used for generating description links.
Expand Down Expand Up @@ -104,9 +104,8 @@ public void onDestroy() {
protected abstract void setupMetadata(LayoutInflater inflater, LinearLayout layout);

private void setupDescription() {
final Description description = getDescription();
if (description == null || isEmpty(description.getContent())
|| description == Description.EMPTY_DESCRIPTION) {
final var description = getDescription().orElse(Description.EMPTY_DESCRIPTION);
if (description.equals(Description.EMPTY_DESCRIPTION)) {
binding.detailDescriptionView.setVisibility(View.GONE);
binding.detailSelectDescriptionButton.setVisibility(View.GONE);
return;
Expand Down Expand Up @@ -137,8 +136,8 @@ private void enableDescriptionSelection() {

private void disableDescriptionSelection() {
// show description content again, otherwise some links are not clickable
final Description description = getDescription();
if (description != null) {
final var description = getDescription().orElse(Description.EMPTY_DESCRIPTION);
if (!description.equals(Description.EMPTY_DESCRIPTION)) {
TextLinkifier.fromDescription(binding.detailDescriptionView,
description, HtmlCompat.FROM_HTML_MODE_LEGACY,
getService(), getStreamUrl(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import com.evernote.android.state.State;
Expand All @@ -20,6 +19,7 @@
import org.schabi.newpipe.util.Localization;

import java.util.List;
import java.util.Optional;

public class DescriptionFragment extends BaseDescriptionFragment {

Expand All @@ -35,10 +35,10 @@ public DescriptionFragment() {
}


@Nullable
@NonNull
@Override
protected Description getDescription() {
return streamInfo.getDescription();
protected Optional<Description> getDescription() {
return Optional.ofNullable(streamInfo.getDescription());
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.schabi.newpipe.util.Localization;

import java.util.List;
import java.util.Optional;

public class ChannelAboutFragment extends BaseDescriptionFragment {
@State
Expand All @@ -40,10 +41,11 @@ protected void initViews(final View rootView, final Bundle savedInstanceState) {
binding.constraintLayout.setPadding(0, DeviceUtils.dpToPx(8, requireContext()), 0, 0);
}

@Nullable
@NonNull
@Override
protected Description getDescription() {
return new Description(channelInfo.getDescription(), Description.PLAIN_TEXT);
protected Optional<Description> getDescription() {
final String description = channelInfo.getDescription();
return Optional.of(Description.of(description, Description.Type.PLAIN_TEXT));
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.schabi.newpipe.fragments.list.playlist;

import static org.schabi.newpipe.extractor.utils.Utils.isBlank;
import static org.schabi.newpipe.ktx.ViewUtils.animate;
import static org.schabi.newpipe.ktx.ViewUtils.animateHideRecyclerViewAllowingScrolling;
import static org.schabi.newpipe.util.ServiceHelper.getServiceById;
Expand Down Expand Up @@ -58,6 +57,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -328,11 +328,11 @@ public void handleResult(@NonNull final PlaylistInfo result) {
streamCount = result.getStreamCount();
setStreamCountAndOverallDuration(result.getRelatedItems(), !result.hasNextPage());

final Description description = result.getDescription();
if (description != null && description != Description.EMPTY_DESCRIPTION
&& !isBlank(description.getContent())) {
final TextEllipsizer ellipsizer = new TextEllipsizer(
headerBinding.playlistDescription, 5, getServiceById(result.getServiceId()));
final var description = Optional.ofNullable(result.getDescription())
.orElse(Description.EMPTY_DESCRIPTION);
if (!description.equals(Description.EMPTY_DESCRIPTION)) {
final var ellipsizer = new TextEllipsizer(headerBinding.playlistDescription, 5,
getServiceById(result.getServiceId()));
ellipsizer.setStateChangeListener(isEllipsized ->
headerBinding.playlistDescriptionReadMore.setText(
Boolean.TRUE.equals(isEllipsized) ? R.string.show_more : R.string.show_less
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fun DescriptionText(
fun rememberParsedDescription(description: Description): AnnotatedString {
// TODO: Handle links and hashtags, Markdown.
return remember(description) {
if (description.type == Description.HTML) {
if (description.type == Description.Type.HTML) {
val styles = TextLinkStyles(SpanStyle(textDecoration = TextDecoration.Underline))
AnnotatedString.fromHtml(description.content, styles)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fun CommentsInfoItem(
private class CommentPreviewProvider : CollectionPreviewParameterProvider<CommentsInfoItem>(
listOf(
CommentsInfoItem(
commentText = Description("Hello world!\n\nThis line should be hidden by default.", Description.PLAIN_TEXT),
commentText = Description("Hello world!\n\nThis line should be hidden by default.", Description.Type.PLAIN_TEXT),
uploaderName = "Test",
likeCount = 100,
isPinned = false,
Expand All @@ -228,7 +228,7 @@ private class CommentPreviewProvider : CollectionPreviewParameterProvider<Commen
replyCount = 0
),
CommentsInfoItem(
commentText = Description("Hello world, long long long text lorem ipsum dolor sit amet!<br><br>This line should be hidden by default.", Description.HTML),
commentText = Description("Hello world, long long long text lorem ipsum dolor sit amet!<br><br>This line should be hidden by default.", Description.Type.HTML),
uploaderName = "Test",
likeCount = 92847,
isPinned = true,
Expand All @@ -237,7 +237,7 @@ private class CommentPreviewProvider : CollectionPreviewParameterProvider<Commen
replyCount = 10
),
CommentsInfoItem(
commentText = Description("Hello world, long long long text lorem ipsum dolor sit amet!<br><br>This line should be hidden by default.", Description.HTML),
commentText = Description("Hello world, long long long text lorem ipsum dolor sit amet!<br><br>This line should be hidden by default.", Description.Type.HTML),
uploaderName = "Test really long long long long lorem ipsum dolor sit amet consectetur",
likeCount = 92847,
isPinned = true,
Expand All @@ -246,7 +246,7 @@ private class CommentPreviewProvider : CollectionPreviewParameterProvider<Commen
replyCount = 0
),
CommentsInfoItem(
commentText = Description("Short comment", Description.HTML),
commentText = Description("Short comment", Description.Type.HTML),
uploaderName = "Test really long long long long lorem ipsum dolor sit amet consectetur",
likeCount = 92847,
isPinned = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private fun CommentRepliesDialog(
@Composable
private fun CommentRepliesDialogPreview() {
val comment = CommentsInfoItem(
commentText = Description("Hello world!", Description.PLAIN_TEXT),
commentText = Description("Hello world!", Description.Type.PLAIN_TEXT),
uploaderName = "Test",
likeCount = 100,
isPinned = true,
Expand All @@ -169,7 +169,7 @@ private fun CommentRepliesDialogPreview() {
CommentsInfoItem(
commentText = Description(
"Reply $i: ${LoremIpsum(i * i).values.first()}",
Description.PLAIN_TEXT
Description.Type.PLAIN_TEXT
),
uploaderName = LoremIpsum(11 - i).values.first()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fun CommentRepliesHeader(comment: CommentsInfoItem, onCommentAuthorOpened: () ->
@Composable
fun CommentRepliesHeaderPreview() {
val comment = CommentsInfoItem(
commentText = Description(LoremIpsum(50).values.first(), Description.PLAIN_TEXT),
commentText = Description(LoremIpsum(50).values.first(), Description.Type.PLAIN_TEXT),
uploaderName = "Test really long lorem ipsum dolor sit",
likeCount = 1000,
isPinned = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@ private fun CommentSectionSuccessPreview() {
CommentsInfoItem(
commentText = Description(
"Comment 1\n\nThis line should be hidden by default.",
Description.PLAIN_TEXT
Description.Type.PLAIN_TEXT
),
uploaderName = "Test",
replies = Page(""),
replyCount = 10
)
) + (2..10).map {
CommentsInfoItem(
commentText = Description("Comment $it", Description.PLAIN_TEXT),
commentText = Description("Comment $it", Description.Type.PLAIN_TEXT),
uploaderName = "Test"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public static void showMetaInfoInTextView(@Nullable final List<MetaInfo> metaInf
.append(Localization.DOT_SEPARATOR);
}

String content = metaInfo.getContent().getContent().trim();
String content = metaInfo.getContent().content().trim();
if (content.endsWith(".")) {
content = content.substring(0, content.length() - 1); // remove . at end
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ public static void fromDescription(@NonNull final TextView textView,
@Nullable final String relatedStreamUrl,
@NonNull final CompositeDisposable disposables,
@Nullable final Consumer<TextView> onCompletion) {
switch (description.getType()) {
case Description.HTML:
TextLinkifier.fromHtml(textView, description.getContent(), htmlCompatFlag,
switch (description.type()) {
case Description.Type.HTML:
TextLinkifier.fromHtml(textView, description.content(), htmlCompatFlag,
relatedInfoService, relatedStreamUrl, disposables, onCompletion);
break;
case Description.MARKDOWN:
TextLinkifier.fromMarkdown(textView, description.getContent(),
case Description.Type.MARKDOWN:
TextLinkifier.fromMarkdown(textView, description.content(),
relatedInfoService, relatedStreamUrl, disposables, onCompletion);
break;
case Description.PLAIN_TEXT: default:
TextLinkifier.fromPlainText(textView, description.getContent(),
case Description.Type.PLAIN_TEXT: default:
TextLinkifier.fromPlainText(textView, description.content(),
relatedInfoService, relatedStreamUrl, disposables, onCompletion);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ teamnewpipe-nanojson = "e9d656ddb49a412a5a0a5d5ef20ca7ef09549996"
# the corresponding commit hash, since JitPack sometimes deletes artifacts.
# If there’s already a git hash, just add more of it to the end (or remove a letter)
# to cause jitpack to regenerate the artifact.
teamnewpipe-newpipe-extractor = "1512cf3222b0c5d87a249e6ac231b98090c42623"
teamnewpipe-newpipe-extractor = "70661defa1d18117b98a4c35b9918c75dfb91e64"
webkit = "1.15.0"
work = "2.11.2"

Expand Down
Loading