1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-21 18:42:35 +01:00

Revert relying on source ListInfo, use commentsInfoItem.getUrl() instead

This reverts commit bb01da3691ff1d5c3dccd41b7ca1a5deb1b5676f. This commit was not needed
This commit is contained in:
Stypox 2023-04-12 15:44:50 +02:00
parent 3f37e27852
commit 8c9287d0c8
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
7 changed files with 68 additions and 41 deletions

View File

@ -66,7 +66,6 @@ public abstract class BaseListInfoFragment<I extends InfoItem, L extends ListInf
@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()) {
@ -75,8 +74,6 @@ public abstract class BaseListInfoFragment<I extends InfoItem, L extends ListInf
doInitialLoadLogic();
}
}
infoListAdapter.setSourceListInfo(currentInfo);
}
@Override
@ -140,8 +137,6 @@ public abstract class BaseListInfoFragment<I extends InfoItem, L extends ListInf
infoListAdapter.clearStreamItemList();
currentInfo = null;
infoListAdapter.setSourceListInfo(null);
if (currentWorker != null) {
currentWorker.dispose();
}
@ -151,7 +146,6 @@ public abstract class BaseListInfoFragment<I extends InfoItem, L extends ListInf
.subscribe((@NonNull L result) -> {
isLoading.set(false);
currentInfo = result;
infoListAdapter.setSourceListInfo(result);
currentNextPage = result.getNextPage();
handleResult(result);
}, throwable ->

View File

@ -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<CommentsInfoItem, CommentRepliesInfo> {
// 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<Object> objectsToSave) {
super.writeTo(objectsToSave);
objectsToSave.add(commentsInfo);
objectsToSave.add(commentsInfoItem);
}
@Override
public void readFrom(@NonNull final Queue<Object> 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<ListExtractor.InfoItemsPage<CommentsInfoItem>> loadMoreItemsLogic() {
return ExtractorHelper.getMoreCommentItems(serviceId, commentsInfo, currentNextPage);
// commentsInfoItem.getUrl() should contain the url of the original
// ListInfo<CommentsInfoItem>, which should be the stream url
return ExtractorHelper.getMoreCommentItems(
serviceId, commentsInfoItem.getUrl(), currentNextPage);
}

View File

@ -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<PlaylistInfoItem> onPlaylistSelectedListener;
private OnClickGesture<CommentsInfoItem> 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<CommentsInfoItem> onCommentsSelectedListener) {
this.onCommentsSelectedListener = onCommentsSelectedListener;
}
public Info getSourceListInfo() {
return sourceListInfo;
}
public void setSourceListInfo(final ListInfo<?> sourceListInfo) {
this.sourceListInfo = sourceListInfo;
}
}

View File

@ -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<RecyclerView.ViewHolde
infoItemBuilder.setOnCommentsSelectedListener(listener);
}
public void setSourceListInfo(final ListInfo<?> sourceInfo) {
infoItemBuilder.setSourceListInfo(sourceInfo);
}
public void setUseMiniVariant(final boolean useMiniVariant) {
this.useMiniVariant = useMiniVariant;
}

View File

@ -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() {

View File

@ -162,6 +162,15 @@ public final class ExtractorHelper {
CommentsInfo.getMoreItems(NewPipe.getService(serviceId), info, nextPage));
}
public static Single<InfoItemsPage<CommentsInfoItem>> 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<PlaylistInfo> getPlaylistInfo(final int serviceId,
final String url,
final boolean forceLoad) {

View File

@ -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();
}