mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-11-05 09:36:22 +00:00
Keep source list info in InfoItemBuilder
Also remove some unused code
This commit is contained in:
parent
5d350aec87
commit
4f7b36cd70
@ -66,6 +66,7 @@ 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()) {
|
||||
@ -74,6 +75,8 @@ public abstract class BaseListInfoFragment<I extends InfoItem, L extends ListInf
|
||||
doInitialLoadLogic();
|
||||
}
|
||||
}
|
||||
|
||||
infoListAdapter.setSourceListInfo(currentInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -137,6 +140,8 @@ public abstract class BaseListInfoFragment<I extends InfoItem, L extends ListInf
|
||||
infoListAdapter.clearStreamItemList();
|
||||
|
||||
currentInfo = null;
|
||||
infoListAdapter.setSourceListInfo(null);
|
||||
|
||||
if (currentWorker != null) {
|
||||
currentWorker.dispose();
|
||||
}
|
||||
@ -146,6 +151,7 @@ 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 ->
|
||||
|
@ -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;
|
||||
|
||||
/*
|
||||
@ -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;
|
||||
}
|
||||
@ -128,4 +84,12 @@ public class InfoItemBuilder {
|
||||
final OnClickGesture<CommentsInfoItem> onCommentsSelectedListener) {
|
||||
this.onCommentsSelectedListener = onCommentsSelectedListener;
|
||||
}
|
||||
|
||||
public Info getSourceListInfo() {
|
||||
return sourceListInfo;
|
||||
}
|
||||
|
||||
public void setSourceListInfo(final ListInfo<?> sourceListInfo) {
|
||||
this.sourceListInfo = sourceListInfo;
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ 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;
|
||||
@ -115,6 +116,10 @@ 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user