Skip to content

Commit

Permalink
Revert relying on source ListInfo, use commentsInfoItem.getUrl() instead
Browse files Browse the repository at this point in the history
This reverts commit bb01da3. This commit was not needed
  • Loading branch information
Stypox committed Apr 12, 2023
1 parent a3f6ae0 commit 50a3ae6
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -73,8 +72,6 @@ public void onResume() {
doInitialLoadLogic();
}
}

infoListAdapter.setSourceListInfo(currentInfo);
}

@Override
Expand Down Expand Up @@ -138,8 +135,6 @@ public void startLoading(final boolean forceLoad) {
infoListAdapter.clearStreamItemList();

currentInfo = null;
infoListAdapter.setSourceListInfo(null);

if (currentWorker != null) {
currentWorker.dispose();
}
Expand All @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,27 +35,24 @@
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();


/*//////////////////////////////////////////////////////////////////////////
// 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
Expand Down Expand Up @@ -121,14 +117,12 @@ HtmlCompat.FROM_HTML_MODE_LEGACY, getServiceById(item.getServiceId()),
@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();
}

Expand All @@ -146,7 +140,10 @@ protected Single<CommentRepliesInfo> loadResult(final boolean forceLoad) {

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


Expand Down
60 changes: 48 additions & 12 deletions app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java
Original file line number Diff line number Diff line change
@@ -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;

/*
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -84,12 +128,4 @@ public void setOnCommentsSelectedListener(
final OnClickGesture<CommentsInfoItem> onCommentsSelectedListener) {
this.onCommentsSelectedListener = onCommentsSelectedListener;
}

public Info getSourceListInfo() {
return sourceListInfo;
}

public void setSourceListInfo(final ListInfo<?> sourceListInfo) {
this.sourceListInfo = sourceListInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,10 +115,6 @@ public void setOnCommentsSelectedListener(final OnClickGesture<CommentsInfoItem>
infoItemBuilder.setOnCommentsSelectedListener(listener);
}

public void setSourceListInfo(final ListInfo<?> sourceInfo) {
infoItemBuilder.setSourceListInfo(sourceInfo);
}

public void setUseMiniVariant(final boolean useMiniVariant) {
this.useMiniVariant = useMiniVariant;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ public static Single<InfoItemsPage<CommentsInfoItem>> getMoreCommentItems(
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 50a3ae6

Please sign in to comment.