feat: add channel tabs

This commit is contained in:
ThetaDev 2022-10-23 10:27:35 +02:00 committed by Stypox
parent 7e2ab0d384
commit 6d13cf5e71
No known key found for this signature in database
GPG key ID: 4BDF1B40A49FDD23
12 changed files with 997 additions and 543 deletions

View file

@ -42,11 +42,13 @@ import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelInfo;
import org.schabi.newpipe.extractor.channel.ChannelTabInfo;
import org.schabi.newpipe.extractor.comments.CommentsInfo;
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
import org.schabi.newpipe.extractor.feed.FeedExtractor;
import org.schabi.newpipe.extractor.feed.FeedInfo;
import org.schabi.newpipe.extractor.kiosk.KioskInfo;
import org.schabi.newpipe.extractor.linkhandler.ChannelTabHandler;
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
import org.schabi.newpipe.extractor.search.SearchInfo;
import org.schabi.newpipe.extractor.stream.StreamInfo;
@ -151,6 +153,25 @@ public final class ExtractorHelper {
return maybeFeedInfo.switchIfEmpty(getChannelInfo(serviceId, url, true));
}
public static Single<ChannelTabInfo> getChannelTab(final int serviceId,
final ChannelTabHandler tabHandler,
final boolean forceLoad) {
checkServiceId(serviceId);
return checkCache(forceLoad, serviceId,
tabHandler.getUrl() + tabHandler.getTab().name(), InfoItem.InfoType.CHANNEL,
Single.fromCallable(() ->
ChannelTabInfo.getInfo(NewPipe.getService(serviceId), tabHandler)));
}
public static Single<InfoItemsPage<InfoItem>> getMoreChannelTabItems(final int serviceId,
final ChannelTabHandler
tabHandler,
final Page nextPage) {
checkServiceId(serviceId);
return Single.fromCallable(() ->
ChannelTabInfo.getMoreItems(NewPipe.getService(serviceId), tabHandler, nextPage));
}
public static Single<CommentsInfo> getCommentsInfo(final int serviceId, final String url,
final boolean forceLoad) {
checkServiceId(serviceId);
@ -229,7 +250,7 @@ public final class ExtractorHelper {
load = actualLoadFromNetwork;
} else {
load = Maybe.concat(ExtractorHelper.loadFromCache(serviceId, url, infoType),
actualLoadFromNetwork.toMaybe())
actualLoadFromNetwork.toMaybe())
.firstElement() // Take the first valid
.toSingle();
}
@ -240,10 +261,10 @@ public final class ExtractorHelper {
/**
* Default implementation uses the {@link InfoCache} to get cached results.
*
* @param <I> the item type's class that extends {@link Info}
* @param serviceId the service to load from
* @param url the URL to load
* @param infoType the {@link InfoItem.InfoType} of the item
* @param <I> the item type's class that extends {@link Info}
* @param serviceId the service to load from
* @param url the URL to load
* @param infoType the {@link InfoItem.InfoType} of the item
* @return a {@link Single} that loads the item
*/
private static <I extends Info> Maybe<I> loadFromCache(final int serviceId, final String url,
@ -274,11 +295,12 @@ public final class ExtractorHelper {
* Formats the text contained in the meta info list as HTML and puts it into the text view,
* while also making the separator visible. If the list is null or empty, or the user chose not
* to see meta information, both the text view and the separator are hidden
* @param metaInfos a list of meta information, can be null or empty
* @param metaInfoTextView the text view in which to show the formatted HTML
*
* @param metaInfos a list of meta information, can be null or empty
* @param metaInfoTextView the text view in which to show the formatted HTML
* @param metaInfoSeparator another view to be shown or hidden accordingly to the text view
* @param disposables disposables created by the method are added here and their lifecycle
* should be handled by the calling class
* @param disposables disposables created by the method are added here and their lifecycle
* should be handled by the calling class
*/
public static void showMetaInfoInTextView(@Nullable final List<MetaInfo> metaInfos,
final TextView metaInfoTextView,
@ -287,7 +309,7 @@ public final class ExtractorHelper {
final Context context = metaInfoTextView.getContext();
if (metaInfos == null || metaInfos.isEmpty()
|| !PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
context.getString(R.string.show_meta_info_key), true)) {
context.getString(R.string.show_meta_info_key), true)) {
metaInfoTextView.setVisibility(View.GONE);
metaInfoSeparator.setVisibility(View.GONE);