From 50a3ae67d21538f70c91d26cebc28156f0ea2c10 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 379379ad94c..3b17faa501a 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 @@ -64,7 +64,6 @@ public void onPause() { @Override public void onResume() { super.onResume(); - // Check if it was loading when the fragment was stopped/paused, if (wasLoading.getAndSet(false)) { if (hasMoreItems() && !infoListAdapter.getItemsList().isEmpty()) { @@ -73,8 +72,6 @@ public void onResume() { doInitialLoadLogic(); } } - - infoListAdapter.setSourceListInfo(currentInfo); } @Override @@ -138,8 +135,6 @@ public void startLoading(final boolean forceLoad) { infoListAdapter.clearStreamItemList(); currentInfo = null; - infoListAdapter.setSourceListInfo(null); - if (currentWorker != null) { currentWorker.dispose(); } @@ -149,7 +144,6 @@ public void startLoading(final boolean forceLoad) { .subscribe((@NonNull L result) -> { 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 7405bcf26bf..ed3f7eddcbb 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.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; @@ -36,10 +35,7 @@ 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(); @@ -47,16 +43,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 @@ -121,14 +117,12 @@ HtmlCompat.FROM_HTML_MODE_LEGACY, getServiceById(item.getServiceId()), @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(); } @@ -146,7 +140,10 @@ protected Single loadResult(final boolean forceLoad) { @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 3b66fa648ab..d959c63277c 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 void setOnCommentsSelectedListener( 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 902c4665c9f..575568c00f9 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 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 void setOnCommentsSelectedListener(final OnClickGesture infoItemBuilder.setOnCommentsSelectedListener(listener); } - public void setSourceListInfo(final ListInfo 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 1fdc6317911..4545b68def5 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 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; @@ -173,7 +172,7 @@ private void openCommentAuthor(final CommentsInfoItem item) { 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 d5d472d6f28..04b37349192 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java @@ -168,6 +168,15 @@ public static Single> getMoreCommentItems( 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 8cc397f515a..193359646f1 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.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 static void openCommentAuthorIfPresent(@NonNull final FragmentActivity ac } 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(); }