Handle Description conversion to record class

This commit is contained in:
Isira Seneviratne authored and Tobi committed 2026-08-13 11:54:20 +02:00
1 parent 4fb9c9c88b
commit 219324d9d7
7 files changed
+23 -30

No files matched your search

@@ -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;
@@ -66,7 +65,7 @@ public abstract class BaseDescriptionFragment extends BaseFragment {
* Get the description to display.
* @return description object, if available
*/
@Nullable
@NonNull
protected abstract Description getDescription();
/**
@@ -105,8 +104,7 @@ public abstract class BaseDescriptionFragment extends BaseFragment {
private void setupDescription() {
final Description description = getDescription();
if (description == null || isEmpty(description.getContent())
|| description == Description.EMPTY_DESCRIPTION) {
if (Description.EMPTY_DESCRIPTION.equals(description)) {
binding.detailDescriptionView.setVisibility(View.GONE);
binding.detailSelectDescriptionButton.setVisibility(View.GONE);
return;
@@ -137,13 +135,9 @@ public abstract class BaseDescriptionFragment extends BaseFragment {
private void disableDescriptionSelection() {
// show description content again, otherwise some links are not clickable
final Description description = getDescription();
if (description != null) {
TextLinkifier.fromDescription(binding.detailDescriptionView,
description, HtmlCompat.FROM_HTML_MODE_LEGACY,
getService(), getStreamUrl(),
descriptionDisposables, SET_LINK_MOVEMENT_METHOD);
}
TextLinkifier.fromDescription(binding.detailDescriptionView, getDescription(),
HtmlCompat.FROM_HTML_MODE_LEGACY, getService(), getStreamUrl(),
descriptionDisposables, SET_LINK_MOVEMENT_METHOD);
binding.detailDescriptionNoteView.setVisibility(View.GONE);
binding.detailDescriptionView.setTextIsSelectable(false);
@@ -8,7 +8,6 @@ import android.view.View;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import com.evernote.android.state.State;
@@ -34,11 +33,11 @@ public class DescriptionFragment extends BaseDescriptionFragment {
// keep empty constructor for State when resuming fragment from memory
}
@Nullable
@NonNull
@Override
protected Description getDescription() {
return streamInfo.getDescription();
return streamInfo.getDescription() != null ? streamInfo.getDescription()
: Description.EMPTY_DESCRIPTION;
}
@NonNull
@@ -40,10 +40,10 @@ public class ChannelAboutFragment extends BaseDescriptionFragment {
binding.constraintLayout.setPadding(0, DeviceUtils.dpToPx(8, requireContext()), 0, 0);
}
@Nullable
@NonNull
@Override
protected Description getDescription() {
return new Description(channelInfo.getDescription(), Description.PLAIN_TEXT);
return Description.of(channelInfo.getDescription(), Description.Type.PLAIN_TEXT);
}
@NonNull
@@ -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;
@@ -328,9 +327,9 @@ public class PlaylistFragment extends BaseListInfoFragment<StreamInfoItem, Playl
streamCount = result.getStreamCount();
setStreamCountAndOverallDuration(result.getRelatedItems(), !result.hasNextPage());
final Description description = result.getDescription();
if (description != null && description != Description.EMPTY_DESCRIPTION
&& !isBlank(description.getContent())) {
final Description description = result.getDescription() != null ? result.getDescription()
: Description.EMPTY_DESCRIPTION;
if (!Description.EMPTY_DESCRIPTION.equals(description)) {
final TextEllipsizer ellipsizer = new TextEllipsizer(
headerBinding.playlistDescription, 5, getServiceById(result.getServiceId()));
ellipsizer.setStateChangeListener(isEllipsized ->
@@ -315,7 +315,7 @@ public final class ExtractorHelper {
.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
}
@@ -67,17 +67,18 @@ public final class TextLinkifier {
@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;
}
+1 -1
View File
@@ -73,7 +73,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 = "4de221bf67ec0bf8dbdf573fbc9d4412a8561cb0"
teamnewpipe-newpipe-extractor = "55cd9d7155ae92ec6b06886f86908294b78c25f3"
viewpager2 = "1.1.0"
webkit = "1.15.0" # New versions require minSdk 24
work = "2.11.2"