From 4f7b36cd70a1f0a6104713608f12d3ceb6fa6b69 Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 11 Apr 2023 22:26:35 +0200 Subject: [PATCH] Keep source list info in InfoItemBuilder Also remove some unused code --- .../fragments/list/BaseListInfoFragment.java | 6 ++ .../newpipe/info_list/InfoItemBuilder.java | 60 ++++--------------- .../newpipe/info_list/InfoListAdapter.java | 5 ++ 3 files changed, 23 insertions(+), 48 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 e7e9f5aad..cf09d083e 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 @@ -66,6 +66,7 @@ public abstract class BaseListInfoFragment { isLoading.set(false); currentInfo = result; + infoListAdapter.setSourceListInfo(result); currentNextPage = result.getNextPage(); handleResult(result); }, throwable -> 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 d959c6327..3b66fa648 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,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 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; } @@ -128,4 +84,12 @@ public class InfoItemBuilder { 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 575568c00..902c4665c 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,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 sourceInfo) { + infoItemBuilder.setSourceListInfo(sourceInfo); + } + public void setUseMiniVariant(final boolean useMiniVariant) { this.useMiniVariant = useMiniVariant; }