Skip to content

Commit

Permalink
Keep source list info in InfoItemBuilder
Browse files Browse the repository at this point in the history
Also remove some unused code
  • Loading branch information
Stypox committed Apr 11, 2023
1 parent 25b94c8 commit bb01da3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ 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 @@ -72,6 +73,8 @@ public void onResume() {
doInitialLoadLogic();
}
}

infoListAdapter.setSourceListInfo(currentInfo);
}

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

currentInfo = null;
infoListAdapter.setSourceListInfo(null);

if (currentWorker != null) {
currentWorker.dispose();
}
Expand All @@ -144,6 +149,7 @@ 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
60 changes: 12 additions & 48 deletions app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
package org.schabi.newpipe.info_list;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.Info;
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;
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 @@ -54,44 +42,12 @@ 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 @@ -128,4 +84,12 @@ 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,6 +13,7 @@

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 @@ -115,6 +116,10 @@ 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

0 comments on commit bb01da3

Please sign in to comment.