1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-22 11:02:35 +01:00

refactor: adjustments to updated tab extractor API

This commit is contained in:
ThetaDev 2022-11-05 00:23:03 +01:00 committed by Stypox
parent 2c98d079de
commit 2c03ba204e
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
4 changed files with 36 additions and 35 deletions

View File

@ -26,12 +26,12 @@ import org.schabi.newpipe.error.ErrorInfo;
import org.schabi.newpipe.error.UserAction; import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.extractor.channel.ChannelInfo; import org.schabi.newpipe.extractor.channel.ChannelInfo;
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
import org.schabi.newpipe.extractor.linkhandler.ChannelTabHandler; import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.fragments.BaseStateFragment; import org.schabi.newpipe.fragments.BaseStateFragment;
import org.schabi.newpipe.fragments.detail.TabAdapter; import org.schabi.newpipe.fragments.detail.TabAdapter;
import org.schabi.newpipe.local.feed.notifications.NotificationHelper; import org.schabi.newpipe.local.feed.notifications.NotificationHelper;
import org.schabi.newpipe.local.subscription.SubscriptionManager; import org.schabi.newpipe.local.subscription.SubscriptionManager;
import org.schabi.newpipe.util.ChannelTabs; import org.schabi.newpipe.util.ChannelTabHelper;
import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.ExtractorHelper;
import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.NavigationHelper;
@ -281,17 +281,18 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo>
final SharedPreferences preferences = PreferenceManager final SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(context); .getDefaultSharedPreferences(context);
for (final ChannelTabHandler tab : currentInfo.getTabs()) { for (final ListLinkHandler linkHandler : currentInfo.getTabs()) {
if (ChannelTabs.showChannelTab(context, preferences, tab.getTab())) { final String tab = linkHandler.getContentFilters().get(0);
if (ChannelTabHelper.showChannelTab(context, preferences, tab)) {
tabAdapter.addFragment( tabAdapter.addFragment(
ChannelTabFragment.getInstance(serviceId, tab), ChannelTabFragment.getInstance(serviceId, linkHandler),
context.getString(ChannelTabs.getTranslationKey(tab.getTab()))); context.getString(ChannelTabHelper.getTranslationKey(tab)));
} }
} }
final String description = currentInfo.getDescription(); final String description = currentInfo.getDescription();
if (description != null && !description.isEmpty() if (description != null && !description.isEmpty()
&& ChannelTabs.showChannelTab( && ChannelTabHelper.showChannelTab(
context, preferences, R.string.show_channel_tabs_info)) { context, preferences, R.string.show_channel_tabs_info)) {
tabAdapter.addFragment( tabAdapter.addFragment(
ChannelInfoFragment.getInstance(currentInfo), "Info"); ChannelInfoFragment.getInstance(currentInfo), "Info");

View File

@ -13,7 +13,7 @@ import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.channel.ChannelTabInfo; import org.schabi.newpipe.extractor.channel.ChannelTabInfo;
import org.schabi.newpipe.extractor.linkhandler.ChannelTabHandler; import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.fragments.list.BaseListInfoFragment; import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.ExtractorHelper;
@ -27,10 +27,10 @@ public class ChannelTabFragment extends BaseListInfoFragment<InfoItem, ChannelTa
protected int serviceId = Constants.NO_SERVICE_ID; protected int serviceId = Constants.NO_SERVICE_ID;
@State @State
protected ChannelTabHandler tabHandler; protected ListLinkHandler tabHandler;
public static ChannelTabFragment getInstance(final int serviceId, public static ChannelTabFragment getInstance(final int serviceId,
final ChannelTabHandler tabHandler) { final ListLinkHandler tabHandler) {
final ChannelTabFragment instance = new ChannelTabFragment(); final ChannelTabFragment instance = new ChannelTabFragment();
instance.serviceId = serviceId; instance.serviceId = serviceId;
instance.tabHandler = tabHandler; instance.tabHandler = tabHandler;

View File

@ -6,43 +6,43 @@ import android.content.SharedPreferences;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.linkhandler.ChannelTabHandler.Tab; import org.schabi.newpipe.extractor.linkhandler.ChannelTabs;
import java.util.Set; import java.util.Set;
public final class ChannelTabs { public final class ChannelTabHelper {
private ChannelTabs() { private ChannelTabHelper() {
} }
@StringRes @StringRes
private static int getShowTabKey(final Tab tab) { private static int getShowTabKey(final String tab) {
switch (tab) { switch (tab) {
case Playlists: case ChannelTabs.PLAYLISTS:
return R.string.show_channel_tabs_playlists; return R.string.show_channel_tabs_playlists;
case Livestreams: case ChannelTabs.LIVESTREAMS:
return R.string.show_channel_tabs_livestreams; return R.string.show_channel_tabs_livestreams;
case Shorts: case ChannelTabs.SHORTS:
return R.string.show_channel_tabs_shorts; return R.string.show_channel_tabs_shorts;
case Channels: case ChannelTabs.CHANNELS:
return R.string.show_channel_tabs_channels; return R.string.show_channel_tabs_channels;
case Albums: case ChannelTabs.ALBUMS:
return R.string.show_channel_tabs_albums; return R.string.show_channel_tabs_albums;
} }
return -1; return -1;
} }
@StringRes @StringRes
public static int getTranslationKey(final Tab tab) { public static int getTranslationKey(final String tab) {
switch (tab) { switch (tab) {
case Playlists: case ChannelTabs.PLAYLISTS:
return R.string.channel_tab_playlists; return R.string.channel_tab_playlists;
case Livestreams: case ChannelTabs.LIVESTREAMS:
return R.string.channel_tab_livestreams; return R.string.channel_tab_livestreams;
case Shorts: case ChannelTabs.SHORTS:
return R.string.channel_tab_shorts; return R.string.channel_tab_shorts;
case Channels: case ChannelTabs.CHANNELS:
return R.string.channel_tab_channels; return R.string.channel_tab_channels;
case Albums: case ChannelTabs.ALBUMS:
return R.string.channel_tab_albums; return R.string.channel_tab_albums;
} }
return R.string.unknown_content; return R.string.unknown_content;
@ -62,8 +62,8 @@ public final class ChannelTabs {
public static boolean showChannelTab(final Context context, public static boolean showChannelTab(final Context context,
final SharedPreferences sharedPreferences, final SharedPreferences sharedPreferences,
final Tab tab) { final String tab) {
final int key = ChannelTabs.getShowTabKey(tab); final int key = ChannelTabHelper.getShowTabKey(tab);
if (key == -1) { if (key == -1) {
return false; return false;
} }

View File

@ -48,7 +48,7 @@ import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
import org.schabi.newpipe.extractor.feed.FeedExtractor; import org.schabi.newpipe.extractor.feed.FeedExtractor;
import org.schabi.newpipe.extractor.feed.FeedInfo; import org.schabi.newpipe.extractor.feed.FeedInfo;
import org.schabi.newpipe.extractor.kiosk.KioskInfo; import org.schabi.newpipe.extractor.kiosk.KioskInfo;
import org.schabi.newpipe.extractor.linkhandler.ChannelTabHandler; import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.playlist.PlaylistInfo; import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
import org.schabi.newpipe.extractor.search.SearchInfo; import org.schabi.newpipe.extractor.search.SearchInfo;
import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.StreamInfo;
@ -154,23 +154,23 @@ public final class ExtractorHelper {
} }
public static Single<ChannelTabInfo> getChannelTab(final int serviceId, public static Single<ChannelTabInfo> getChannelTab(final int serviceId,
final ChannelTabHandler tabHandler, final ListLinkHandler listLinkHandler,
final boolean forceLoad) { final boolean forceLoad) {
checkServiceId(serviceId); checkServiceId(serviceId);
return checkCache(forceLoad, serviceId, return checkCache(forceLoad, serviceId,
tabHandler.getUrl() + "/" listLinkHandler.getUrl(), InfoItem.InfoType.CHANNEL,
+ tabHandler.getTab().name(), InfoItem.InfoType.CHANNEL,
Single.fromCallable(() -> Single.fromCallable(() ->
ChannelTabInfo.getInfo(NewPipe.getService(serviceId), tabHandler))); ChannelTabInfo.getInfo(NewPipe.getService(serviceId), listLinkHandler)));
} }
public static Single<InfoItemsPage<InfoItem>> getMoreChannelTabItems(final int serviceId, public static Single<InfoItemsPage<InfoItem>> getMoreChannelTabItems(final int serviceId,
final ChannelTabHandler final ListLinkHandler
tabHandler, listLinkHandler,
final Page nextPage) { final Page nextPage) {
checkServiceId(serviceId); checkServiceId(serviceId);
return Single.fromCallable(() -> return Single.fromCallable(() ->
ChannelTabInfo.getMoreItems(NewPipe.getService(serviceId), tabHandler, nextPage)); ChannelTabInfo.getMoreItems(NewPipe.getService(serviceId),
listLinkHandler, nextPage));
} }
public static Single<CommentsInfo> getCommentsInfo(final int serviceId, final String url, public static Single<CommentsInfo> getCommentsInfo(final int serviceId, final String url,