From 8c9287d0c87dc2eb1e99f186535a5e2cb686c037 Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 12 Apr 2023 15:44:50 +0200 Subject: [PATCH] Revert relying on source ListInfo, use commentsInfoItem.getUrl() instead This reverts commit bb01da3691ff1d5c3dccd41b7ca1a5deb1b5676f. This commit was not needed --- .../fragments/list/BaseListInfoFragment.java | 6 -- .../list/comments/CommentRepliesFragment.java | 21 +++---- .../newpipe/info_list/InfoItemBuilder.java | 60 +++++++++++++++---- .../newpipe/info_list/InfoListAdapter.java | 5 -- .../holder/CommentInfoItemHolder.java | 3 +- .../schabi/newpipe/util/ExtractorHelper.java | 9 +++ .../schabi/newpipe/util/NavigationHelper.java | 5 +- 7 files changed, 68 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java index 715512e02..dd5eb6c8a 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java @@ -66,7 +66,6 @@ public abstract class BaseListInfoFragment { isLoading.set(false); currentInfo = result; - infoListAdapter.setSourceListInfo(result); currentNextPage = result.getNextPage(); handleResult(result); }, throwable -> diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentRepliesFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentRepliesFragment.java index 2e0f0d7c6..a28a7f7d5 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentRepliesFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentRepliesFragment.java @@ -16,7 +16,6 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.databinding.CommentRepliesHeaderBinding; import org.schabi.newpipe.error.UserAction; import org.schabi.newpipe.extractor.ListExtractor; -import org.schabi.newpipe.extractor.comments.CommentsInfo; import org.schabi.newpipe.extractor.comments.CommentsInfoItem; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; import org.schabi.newpipe.info_list.ItemViewMode; @@ -37,10 +36,7 @@ import io.reactivex.rxjava3.disposables.CompositeDisposable; public final class CommentRepliesFragment extends BaseListInfoFragment { - // the original comments info loaded alongside the stream - private CommentsInfo commentsInfo; - // the comment to show replies of - private CommentsInfoItem commentsInfoItem; + private CommentsInfoItem commentsInfoItem; // the comment to show replies of private final CompositeDisposable disposables = new CompositeDisposable(); @@ -48,16 +44,16 @@ public final class CommentRepliesFragment // Constructors and lifecycle //////////////////////////////////////////////////////////////////////////*/ + // only called by the Android framework, after which readFrom is called and restores all data public CommentRepliesFragment() { super(UserAction.REQUESTED_COMMENT_REPLIES); } - public CommentRepliesFragment(final CommentsInfo commentsInfo, - final CommentsInfoItem commentsInfoItem) { + public CommentRepliesFragment(final CommentsInfoItem commentsInfoItem) { this(); - this.commentsInfo = commentsInfo; this.commentsInfoItem = commentsInfoItem; - setInitialData(commentsInfo.getServiceId(), commentsInfo.getUrl(), commentsInfo.getName()); + // setting "" as title since the title will be properly set right after + setInitialData(commentsInfoItem.getServiceId(), commentsInfoItem.getUrl(), ""); } @Nullable @@ -122,14 +118,12 @@ public final class CommentRepliesFragment @Override public void writeTo(final Queue objectsToSave) { super.writeTo(objectsToSave); - objectsToSave.add(commentsInfo); objectsToSave.add(commentsInfoItem); } @Override public void readFrom(@NonNull final Queue savedObjects) throws Exception { super.readFrom(savedObjects); - commentsInfo = (CommentsInfo) savedObjects.poll(); commentsInfoItem = (CommentsInfoItem) savedObjects.poll(); } @@ -147,7 +141,10 @@ public final class CommentRepliesFragment @Override protected Single> loadMoreItemsLogic() { - return ExtractorHelper.getMoreCommentItems(serviceId, commentsInfo, currentNextPage); + // commentsInfoItem.getUrl() should contain the url of the original + // ListInfo, which should be the stream url + return ExtractorHelper.getMoreCommentItems( + serviceId, commentsInfoItem.getUrl(), currentNextPage); } diff --git a/app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java index 3b66fa648..d959c6327 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java @@ -1,13 +1,25 @@ package org.schabi.newpipe.info_list; import android.content.Context; +import android.view.View; +import android.view.ViewGroup; -import org.schabi.newpipe.extractor.Info; -import org.schabi.newpipe.extractor.ListInfo; +import androidx.annotation.NonNull; + +import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.channel.ChannelInfoItem; import org.schabi.newpipe.extractor.comments.CommentsInfoItem; import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem; +import org.schabi.newpipe.info_list.holder.ChannelInfoItemHolder; +import org.schabi.newpipe.info_list.holder.ChannelMiniInfoItemHolder; +import org.schabi.newpipe.info_list.holder.CommentInfoItemHolder; +import org.schabi.newpipe.info_list.holder.InfoItemHolder; +import org.schabi.newpipe.info_list.holder.PlaylistInfoItemHolder; +import org.schabi.newpipe.info_list.holder.PlaylistMiniInfoItemHolder; +import org.schabi.newpipe.info_list.holder.StreamInfoItemHolder; +import org.schabi.newpipe.info_list.holder.StreamMiniInfoItemHolder; +import org.schabi.newpipe.local.history.HistoryRecordManager; import org.schabi.newpipe.util.OnClickGesture; /* @@ -42,12 +54,44 @@ public class InfoItemBuilder { private OnClickGesture onPlaylistSelectedListener; private OnClickGesture onCommentsSelectedListener; - private ListInfo sourceListInfo; // the list-info the info-items from this list belong to - public InfoItemBuilder(final Context context) { this.context = context; } + public View buildView(@NonNull final ViewGroup parent, @NonNull final InfoItem infoItem, + final HistoryRecordManager historyRecordManager) { + return buildView(parent, infoItem, historyRecordManager, false); + } + + public View buildView(@NonNull final ViewGroup parent, @NonNull final InfoItem infoItem, + final HistoryRecordManager historyRecordManager, + final boolean useMiniVariant) { + final InfoItemHolder holder = + holderFromInfoType(parent, infoItem.getInfoType(), useMiniVariant); + holder.updateFromItem(infoItem, historyRecordManager); + return holder.itemView; + } + + private InfoItemHolder holderFromInfoType(@NonNull final ViewGroup parent, + @NonNull final InfoItem.InfoType infoType, + final boolean useMiniVariant) { + switch (infoType) { + case STREAM: + return useMiniVariant ? new StreamMiniInfoItemHolder(this, parent) + : new StreamInfoItemHolder(this, parent); + case CHANNEL: + return useMiniVariant ? new ChannelMiniInfoItemHolder(this, parent) + : new ChannelInfoItemHolder(this, parent); + case PLAYLIST: + return useMiniVariant ? new PlaylistMiniInfoItemHolder(this, parent) + : new PlaylistInfoItemHolder(this, parent); + case COMMENT: + return new CommentInfoItemHolder(this, parent); + default: + throw new RuntimeException("InfoType not expected = " + infoType.name()); + } + } + public Context getContext() { return context; } @@ -84,12 +128,4 @@ public class InfoItemBuilder { final OnClickGesture onCommentsSelectedListener) { this.onCommentsSelectedListener = onCommentsSelectedListener; } - - public Info getSourceListInfo() { - return sourceListInfo; - } - - public void setSourceListInfo(final ListInfo sourceListInfo) { - this.sourceListInfo = sourceListInfo; - } } diff --git a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java index 902c4665c..575568c00 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java @@ -13,7 +13,6 @@ import androidx.recyclerview.widget.RecyclerView; import org.schabi.newpipe.databinding.PignateFooterBinding; import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.ListInfo; import org.schabi.newpipe.extractor.channel.ChannelInfoItem; import org.schabi.newpipe.extractor.comments.CommentsInfoItem; import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem; @@ -116,10 +115,6 @@ public class InfoListAdapter extends RecyclerView.Adapter sourceInfo) { - infoItemBuilder.setSourceListInfo(sourceInfo); - } - public void setUseMiniVariant(final boolean useMiniVariant) { this.useMiniVariant = useMiniVariant; } diff --git a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentInfoItemHolder.java b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentInfoItemHolder.java index ef949a745..ec336f677 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentInfoItemHolder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentInfoItemHolder.java @@ -21,7 +21,6 @@ import androidx.fragment.app.FragmentActivity; import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.comments.CommentsInfo; import org.schabi.newpipe.extractor.comments.CommentsInfoItem; import org.schabi.newpipe.extractor.stream.Description; import org.schabi.newpipe.info_list.InfoItemBuilder; @@ -174,7 +173,7 @@ public class CommentInfoItemHolder extends InfoItemHolder { private void openCommentReplies(final CommentsInfoItem item) { NavigationHelper.openCommentRepliesFragment((FragmentActivity) itemBuilder.getContext(), - (CommentsInfo) itemBuilder.getSourceListInfo(), item); + item); } private void allowLinkFocus() { diff --git a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java index 07d0f516d..c2748f725 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java @@ -162,6 +162,15 @@ public final class ExtractorHelper { CommentsInfo.getMoreItems(NewPipe.getService(serviceId), info, nextPage)); } + public static Single> getMoreCommentItems( + final int serviceId, + final String url, + final Page nextPage) { + checkServiceId(serviceId); + return Single.fromCallable(() -> + CommentsInfo.getMoreItems(NewPipe.getService(serviceId), url, nextPage)); + } + public static Single getPlaylistInfo(final int serviceId, final String url, final boolean forceLoad) { diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index e105e551b..00af400b6 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -34,7 +34,6 @@ import org.schabi.newpipe.download.DownloadActivity; import org.schabi.newpipe.error.ErrorUtil; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.comments.CommentsInfo; import org.schabi.newpipe.extractor.comments.CommentsInfoItem; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.stream.AudioStream; @@ -503,11 +502,9 @@ public final class NavigationHelper { } public static void openCommentRepliesFragment(@NonNull final FragmentActivity activity, - final CommentsInfo commentsInfo, final CommentsInfoItem commentsInfoItem) { defaultTransaction(activity.getSupportFragmentManager()) - .replace(R.id.fragment_holder, - new CommentRepliesFragment(commentsInfo, commentsInfoItem)) + .replace(R.id.fragment_holder, new CommentRepliesFragment(commentsInfoItem)) .addToBackStack(null) .commit(); }