2022-10-23 08:27:35 +00:00
|
|
|
package org.schabi.newpipe.fragments.list.channel;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
|
|
import org.schabi.newpipe.R;
|
2023-04-15 22:58:30 +00:00
|
|
|
import org.schabi.newpipe.databinding.PlaylistControlBinding;
|
2022-10-23 08:27:35 +00:00
|
|
|
import org.schabi.newpipe.error.UserAction;
|
|
|
|
import org.schabi.newpipe.extractor.InfoItem;
|
|
|
|
import org.schabi.newpipe.extractor.ListExtractor;
|
2023-08-02 20:45:53 +00:00
|
|
|
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabInfo;
|
2022-11-04 23:23:03 +00:00
|
|
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
2023-04-15 22:58:30 +00:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
2022-10-23 08:27:35 +00:00
|
|
|
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
|
2023-09-09 23:11:00 +00:00
|
|
|
import org.schabi.newpipe.fragments.list.playlist.PlaylistControlViewHolder;
|
2023-04-15 22:58:30 +00:00
|
|
|
import org.schabi.newpipe.player.playqueue.ChannelTabPlayQueue;
|
|
|
|
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
|
|
|
import org.schabi.newpipe.util.ChannelTabHelper;
|
2022-10-23 08:27:35 +00:00
|
|
|
import org.schabi.newpipe.util.ExtractorHelper;
|
2023-09-09 23:11:00 +00:00
|
|
|
import org.schabi.newpipe.util.PlayButtonHelper;
|
2023-04-15 22:58:30 +00:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
import java.util.stream.Collectors;
|
2022-10-23 08:27:35 +00:00
|
|
|
|
|
|
|
import icepick.State;
|
|
|
|
import io.reactivex.rxjava3.core.Single;
|
|
|
|
|
2023-09-09 23:11:00 +00:00
|
|
|
public class ChannelTabFragment extends BaseListInfoFragment<InfoItem, ChannelTabInfo>
|
|
|
|
implements PlaylistControlViewHolder {
|
2022-10-23 08:27:35 +00:00
|
|
|
|
|
|
|
@State
|
2022-11-04 23:23:03 +00:00
|
|
|
protected ListLinkHandler tabHandler;
|
2022-11-29 18:25:35 +00:00
|
|
|
@State
|
|
|
|
protected String channelName;
|
|
|
|
|
2023-04-15 22:58:30 +00:00
|
|
|
private PlaylistControlBinding playlistControlBinding;
|
2022-10-23 08:27:35 +00:00
|
|
|
public static ChannelTabFragment getInstance(final int serviceId,
|
2022-11-29 18:25:35 +00:00
|
|
|
final ListLinkHandler tabHandler,
|
|
|
|
final String channelName) {
|
2022-10-23 08:27:35 +00:00
|
|
|
final ChannelTabFragment instance = new ChannelTabFragment();
|
|
|
|
instance.serviceId = serviceId;
|
|
|
|
instance.tabHandler = tabHandler;
|
2022-11-29 18:25:35 +00:00
|
|
|
instance.channelName = channelName;
|
2022-10-23 08:27:35 +00:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ChannelTabFragment() {
|
|
|
|
super(UserAction.REQUESTED_CHANNEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// LifeCycle
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2022-10-23 09:28:34 +00:00
|
|
|
@Override
|
2022-10-23 19:28:54 +00:00
|
|
|
public void onCreate(final Bundle savedInstanceState) {
|
2022-10-23 09:28:34 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setHasOptionsMenu(false);
|
|
|
|
}
|
|
|
|
|
2022-10-23 08:27:35 +00:00
|
|
|
@Override
|
|
|
|
public View onCreateView(@NonNull final LayoutInflater inflater,
|
|
|
|
@Nullable final ViewGroup container,
|
|
|
|
@Nullable final Bundle savedInstanceState) {
|
|
|
|
return inflater.inflate(R.layout.fragment_channel_tab, container, false);
|
|
|
|
}
|
|
|
|
|
2023-04-15 22:58:30 +00:00
|
|
|
@Override
|
2023-09-09 23:11:00 +00:00
|
|
|
public void onDestroyView() {
|
|
|
|
super.onDestroyView();
|
2023-04-15 22:58:30 +00:00
|
|
|
playlistControlBinding = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Supplier<View> getListHeaderSupplier() {
|
|
|
|
if (ChannelTabHelper.isStreamsTab(tabHandler)) {
|
|
|
|
playlistControlBinding = PlaylistControlBinding
|
|
|
|
.inflate(activity.getLayoutInflater(), itemsList, false);
|
|
|
|
return playlistControlBinding::getRoot;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-10-23 08:27:35 +00:00
|
|
|
@Override
|
|
|
|
protected Single<ChannelTabInfo> loadResult(final boolean forceLoad) {
|
|
|
|
return ExtractorHelper.getChannelTab(serviceId, tabHandler, forceLoad);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Single<ListExtractor.InfoItemsPage<InfoItem>> loadMoreItemsLogic() {
|
|
|
|
return ExtractorHelper.getMoreChannelTabItems(serviceId, tabHandler, currentNextPage);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setTitle(final String title) {
|
2022-11-29 18:25:35 +00:00
|
|
|
super.setTitle(channelName);
|
2022-10-23 08:27:35 +00:00
|
|
|
}
|
2023-04-15 22:58:30 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handleResult(final @NonNull ChannelTabInfo result) {
|
|
|
|
super.handleResult(result);
|
|
|
|
|
|
|
|
if (playlistControlBinding != null) {
|
|
|
|
// PlaylistControls should be visible only if there is some item in
|
|
|
|
// infoListAdapter other than header
|
|
|
|
if (infoListAdapter.getItemCount() > 1) {
|
|
|
|
playlistControlBinding.getRoot().setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
playlistControlBinding.getRoot().setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2023-09-09 23:11:00 +00:00
|
|
|
PlayButtonHelper.initPlaylistControlClickListener(
|
|
|
|
activity, playlistControlBinding, this);
|
2023-04-15 22:58:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-09 23:11:00 +00:00
|
|
|
public PlayQueue getPlayQueue() {
|
2023-04-15 22:58:30 +00:00
|
|
|
final List<StreamInfoItem> streamItems = infoListAdapter.getItemsList().stream()
|
|
|
|
.filter(StreamInfoItem.class::isInstance)
|
|
|
|
.map(StreamInfoItem.class::cast)
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
return new ChannelTabPlayQueue(currentInfo.getServiceId(), tabHandler,
|
|
|
|
currentInfo.getNextPage(), streamItems, 0);
|
|
|
|
}
|
2022-10-23 08:27:35 +00:00
|
|
|
}
|