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.extractor.channel.ChannelInfo;
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.detail.TabAdapter;
import org.schabi.newpipe.local.feed.notifications.NotificationHelper;
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.ExtractorHelper;
import org.schabi.newpipe.util.NavigationHelper;
@ -281,17 +281,18 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo>
final SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(context);
for (final ChannelTabHandler tab : currentInfo.getTabs()) {
if (ChannelTabs.showChannelTab(context, preferences, tab.getTab())) {
for (final ListLinkHandler linkHandler : currentInfo.getTabs()) {
final String tab = linkHandler.getContentFilters().get(0);
if (ChannelTabHelper.showChannelTab(context, preferences, tab)) {
tabAdapter.addFragment(
ChannelTabFragment.getInstance(serviceId, tab),
context.getString(ChannelTabs.getTranslationKey(tab.getTab())));
ChannelTabFragment.getInstance(serviceId, linkHandler),
context.getString(ChannelTabHelper.getTranslationKey(tab)));
}
}
final String description = currentInfo.getDescription();
if (description != null && !description.isEmpty()
&& ChannelTabs.showChannelTab(
&& ChannelTabHelper.showChannelTab(
context, preferences, R.string.show_channel_tabs_info)) {
tabAdapter.addFragment(
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.ListExtractor;
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.util.Constants;
import org.schabi.newpipe.util.ExtractorHelper;
@ -27,10 +27,10 @@ public class ChannelTabFragment extends BaseListInfoFragment<InfoItem, ChannelTa
protected int serviceId = Constants.NO_SERVICE_ID;
@State
protected ChannelTabHandler tabHandler;
protected ListLinkHandler tabHandler;
public static ChannelTabFragment getInstance(final int serviceId,
final ChannelTabHandler tabHandler) {
final ListLinkHandler tabHandler) {
final ChannelTabFragment instance = new ChannelTabFragment();
instance.serviceId = serviceId;
instance.tabHandler = tabHandler;

View File

@ -6,43 +6,43 @@ import android.content.SharedPreferences;
import androidx.annotation.StringRes;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.linkhandler.ChannelTabHandler.Tab;
import org.schabi.newpipe.extractor.linkhandler.ChannelTabs;
import java.util.Set;
public final class ChannelTabs {
private ChannelTabs() {
public final class ChannelTabHelper {
private ChannelTabHelper() {
}
@StringRes
private static int getShowTabKey(final Tab tab) {
private static int getShowTabKey(final String tab) {
switch (tab) {
case Playlists:
case ChannelTabs.PLAYLISTS:
return R.string.show_channel_tabs_playlists;
case Livestreams:
case ChannelTabs.LIVESTREAMS:
return R.string.show_channel_tabs_livestreams;
case Shorts:
case ChannelTabs.SHORTS:
return R.string.show_channel_tabs_shorts;
case Channels:
case ChannelTabs.CHANNELS:
return R.string.show_channel_tabs_channels;
case Albums:
case ChannelTabs.ALBUMS:
return R.string.show_channel_tabs_albums;
}
return -1;
}
@StringRes
public static int getTranslationKey(final Tab tab) {
public static int getTranslationKey(final String tab) {
switch (tab) {
case Playlists:
case ChannelTabs.PLAYLISTS:
return R.string.channel_tab_playlists;
case Livestreams:
case ChannelTabs.LIVESTREAMS:
return R.string.channel_tab_livestreams;
case Shorts:
case ChannelTabs.SHORTS:
return R.string.channel_tab_shorts;
case Channels:
case ChannelTabs.CHANNELS:
return R.string.channel_tab_channels;
case Albums:
case ChannelTabs.ALBUMS:
return R.string.channel_tab_albums;
}
return R.string.unknown_content;
@ -62,8 +62,8 @@ public final class ChannelTabs {
public static boolean showChannelTab(final Context context,
final SharedPreferences sharedPreferences,
final Tab tab) {
final int key = ChannelTabs.getShowTabKey(tab);
final String tab) {
final int key = ChannelTabHelper.getShowTabKey(tab);
if (key == -1) {
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.FeedInfo;
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.search.SearchInfo;
import org.schabi.newpipe.extractor.stream.StreamInfo;
@ -154,23 +154,23 @@ public final class ExtractorHelper {
}
public static Single<ChannelTabInfo> getChannelTab(final int serviceId,
final ChannelTabHandler tabHandler,
final ListLinkHandler listLinkHandler,
final boolean forceLoad) {
checkServiceId(serviceId);
return checkCache(forceLoad, serviceId,
tabHandler.getUrl() + "/"
+ tabHandler.getTab().name(), InfoItem.InfoType.CHANNEL,
listLinkHandler.getUrl(), InfoItem.InfoType.CHANNEL,
Single.fromCallable(() ->
ChannelTabInfo.getInfo(NewPipe.getService(serviceId), tabHandler)));
ChannelTabInfo.getInfo(NewPipe.getService(serviceId), listLinkHandler)));
}
public static Single<InfoItemsPage<InfoItem>> getMoreChannelTabItems(final int serviceId,
final ChannelTabHandler
tabHandler,
final ListLinkHandler
listLinkHandler,
final Page nextPage) {
checkServiceId(serviceId);
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,