1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-01-23 23:46:57 +00:00

use FilterItem for tabs

This commit is contained in:
evermind 2023-12-30 22:44:06 +01:00
parent 6bcca69563
commit 7b300eca6f
2 changed files with 53 additions and 62 deletions

View File

@ -38,6 +38,7 @@ 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.ListLinkHandler; import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.search.filter.FilterItem;
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.ktx.AnimationType; import org.schabi.newpipe.ktx.AnimationType;
@ -461,7 +462,7 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo>
.getDefaultSharedPreferences(context); .getDefaultSharedPreferences(context);
for (final ListLinkHandler linkHandler : currentInfo.getTabs()) { for (final ListLinkHandler linkHandler : currentInfo.getTabs()) {
final String tab = linkHandler.getContentFilters().get(0); final FilterItem tab = linkHandler.getContentFilters().get(0);
if (ChannelTabHelper.showChannelTab(context, preferences, tab)) { if (ChannelTabHelper.showChannelTab(context, preferences, tab)) {
final ChannelTabFragment channelTabFragment = final ChannelTabFragment channelTabFragment =
ChannelTabFragment.getInstance(serviceId, linkHandler, name); ChannelTabFragment.getInstance(serviceId, linkHandler, name);

View File

@ -8,6 +8,7 @@ import androidx.annotation.StringRes;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs; import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.search.filter.FilterItem;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -20,16 +21,11 @@ public final class ChannelTabHelper {
* @param tab the channel tab to check * @param tab the channel tab to check
* @return whether the tab should contain (playable) streams or not * @return whether the tab should contain (playable) streams or not
*/ */
public static boolean isStreamsTab(final String tab) { public static boolean isStreamsTab(final FilterItem tab) {
switch (tab) { return tab.equals(ChannelTabs.VIDEOS)
case ChannelTabs.VIDEOS: || tab.equals(ChannelTabs.TRACKS)
case ChannelTabs.TRACKS: || tab.equals(ChannelTabs.SHORTS)
case ChannelTabs.SHORTS: || tab.equals(ChannelTabs.LIVESTREAMS);
case ChannelTabs.LIVESTREAMS:
return true;
default:
return false;
}
} }
/** /**
@ -37,7 +33,7 @@ public final class ChannelTabHelper {
* @return whether the tab should contain (playable) streams or not * @return whether the tab should contain (playable) streams or not
*/ */
public static boolean isStreamsTab(final ListLinkHandler tab) { public static boolean isStreamsTab(final ListLinkHandler tab) {
final List<String> contentFilters = tab.getContentFilters(); final List<FilterItem> contentFilters = tab.getContentFilters();
if (contentFilters.isEmpty()) { if (contentFilters.isEmpty()) {
return false; // this should never happen, but check just to be sure return false; // this should never happen, but check just to be sure
} else { } else {
@ -46,63 +42,57 @@ public final class ChannelTabHelper {
} }
@StringRes @StringRes
private static int getShowTabKey(final String tab) { private static int getShowTabKey(final FilterItem tab) {
switch (tab) { if (tab.equals(ChannelTabs.VIDEOS)) {
case ChannelTabs.VIDEOS: return R.string.show_channel_tabs_videos;
return R.string.show_channel_tabs_videos; } else if (tab.equals(ChannelTabs.TRACKS)) {
case ChannelTabs.TRACKS: return R.string.show_channel_tabs_tracks;
return R.string.show_channel_tabs_tracks; } else if (tab.equals(ChannelTabs.SHORTS)) {
case ChannelTabs.SHORTS: return R.string.show_channel_tabs_shorts;
return R.string.show_channel_tabs_shorts; } else if (tab.equals(ChannelTabs.LIVESTREAMS)) {
case ChannelTabs.LIVESTREAMS: return R.string.show_channel_tabs_livestreams;
return R.string.show_channel_tabs_livestreams; } else if (tab.equals(ChannelTabs.CHANNELS)) {
case ChannelTabs.CHANNELS: return R.string.show_channel_tabs_channels;
return R.string.show_channel_tabs_channels; } else if (tab.equals(ChannelTabs.PLAYLISTS)) {
case ChannelTabs.PLAYLISTS: return R.string.show_channel_tabs_playlists;
return R.string.show_channel_tabs_playlists; } else if (tab.equals(ChannelTabs.ALBUMS)) {
case ChannelTabs.ALBUMS: return R.string.show_channel_tabs_albums;
return R.string.show_channel_tabs_albums;
default:
return -1;
} }
return -1;
} }
@StringRes @StringRes
private static int getFetchFeedTabKey(final String tab) { private static int getFetchFeedTabKey(final FilterItem tab) {
switch (tab) { if (tab.equals(ChannelTabs.VIDEOS)) {
case ChannelTabs.VIDEOS: return R.string.fetch_channel_tabs_videos;
return R.string.fetch_channel_tabs_videos; } else if (tab.equals(ChannelTabs.TRACKS)) {
case ChannelTabs.TRACKS: return R.string.fetch_channel_tabs_tracks;
return R.string.fetch_channel_tabs_tracks; } else if (tab.equals(ChannelTabs.SHORTS)) {
case ChannelTabs.SHORTS: return R.string.fetch_channel_tabs_shorts;
return R.string.fetch_channel_tabs_shorts; } else if (tab.equals(ChannelTabs.LIVESTREAMS)) {
case ChannelTabs.LIVESTREAMS: return R.string.fetch_channel_tabs_livestreams;
return R.string.fetch_channel_tabs_livestreams;
default:
return -1;
} }
return -1;
} }
@StringRes @StringRes
public static int getTranslationKey(final String tab) { public static int getTranslationKey(final FilterItem tab) {
switch (tab) { if (tab.equals(ChannelTabs.VIDEOS)) {
case ChannelTabs.VIDEOS: return R.string.channel_tab_videos;
return R.string.channel_tab_videos; } else if (tab.equals(ChannelTabs.TRACKS)) {
case ChannelTabs.TRACKS: return R.string.channel_tab_tracks;
return R.string.channel_tab_tracks; } else if (tab.equals(ChannelTabs.SHORTS)) {
case ChannelTabs.SHORTS: return R.string.channel_tab_shorts;
return R.string.channel_tab_shorts; } else if (tab.equals(ChannelTabs.LIVESTREAMS)) {
case ChannelTabs.LIVESTREAMS: return R.string.channel_tab_livestreams;
return R.string.channel_tab_livestreams; } else if (tab.equals(ChannelTabs.CHANNELS)) {
case ChannelTabs.CHANNELS: return R.string.channel_tab_channels;
return R.string.channel_tab_channels; } else if (tab.equals(ChannelTabs.PLAYLISTS)) {
case ChannelTabs.PLAYLISTS: return R.string.channel_tab_playlists;
return R.string.channel_tab_playlists; } else if (tab.equals(ChannelTabs.ALBUMS)) {
case ChannelTabs.ALBUMS: return R.string.channel_tab_albums;
return R.string.channel_tab_albums;
default:
return R.string.unknown_content;
} }
return R.string.unknown_content;
} }
public static boolean showChannelTab(final Context context, public static boolean showChannelTab(final Context context,
@ -119,7 +109,7 @@ public final class ChannelTabHelper {
public static boolean showChannelTab(final Context context, public static boolean showChannelTab(final Context context,
final SharedPreferences sharedPreferences, final SharedPreferences sharedPreferences,
final String tab) { final FilterItem tab) {
final int key = ChannelTabHelper.getShowTabKey(tab); final int key = ChannelTabHelper.getShowTabKey(tab);
if (key == -1) { if (key == -1) {
return false; return false;
@ -130,7 +120,7 @@ public final class ChannelTabHelper {
public static boolean fetchFeedChannelTab(final Context context, public static boolean fetchFeedChannelTab(final Context context,
final SharedPreferences sharedPreferences, final SharedPreferences sharedPreferences,
final ListLinkHandler tab) { final ListLinkHandler tab) {
final List<String> contentFilters = tab.getContentFilters(); final List<FilterItem> contentFilters = tab.getContentFilters();
if (contentFilters.isEmpty()) { if (contentFilters.isEmpty()) {
return false; // this should never happen, but check just to be sure return false; // this should never happen, but check just to be sure
} }