From 7b300eca6f26adcf9ff6bcba562eabaa0002ef6f Mon Sep 17 00:00:00 2001 From: evermind Date: Sat, 30 Dec 2023 22:44:06 +0100 Subject: [PATCH] use FilterItem for tabs --- .../list/channel/ChannelFragment.java | 3 +- .../schabi/newpipe/util/ChannelTabHelper.java | 112 ++++++++---------- 2 files changed, 53 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index b16f40a4ae5..fe9ec6997cb 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -38,6 +38,7 @@ import org.schabi.newpipe.extractor.channel.ChannelInfo; import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; 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.detail.TabAdapter; import org.schabi.newpipe.ktx.AnimationType; @@ -461,7 +462,7 @@ private void updateTabs() { .getDefaultSharedPreferences(context); 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)) { final ChannelTabFragment channelTabFragment = ChannelTabFragment.getInstance(serviceId, linkHandler, name); diff --git a/app/src/main/java/org/schabi/newpipe/util/ChannelTabHelper.java b/app/src/main/java/org/schabi/newpipe/util/ChannelTabHelper.java index 8e8d3849007..633de1b9a4f 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ChannelTabHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ChannelTabHelper.java @@ -8,6 +8,7 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs; import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; +import org.schabi.newpipe.extractor.search.filter.FilterItem; import java.util.List; import java.util.Set; @@ -20,16 +21,11 @@ private ChannelTabHelper() { * @param tab the channel tab to check * @return whether the tab should contain (playable) streams or not */ - public static boolean isStreamsTab(final String tab) { - switch (tab) { - case ChannelTabs.VIDEOS: - case ChannelTabs.TRACKS: - case ChannelTabs.SHORTS: - case ChannelTabs.LIVESTREAMS: - return true; - default: - return false; - } + public static boolean isStreamsTab(final FilterItem tab) { + return tab.equals(ChannelTabs.VIDEOS) + || tab.equals(ChannelTabs.TRACKS) + || tab.equals(ChannelTabs.SHORTS) + || tab.equals(ChannelTabs.LIVESTREAMS); } /** @@ -37,7 +33,7 @@ public static boolean isStreamsTab(final String tab) { * @return whether the tab should contain (playable) streams or not */ public static boolean isStreamsTab(final ListLinkHandler tab) { - final List contentFilters = tab.getContentFilters(); + final List contentFilters = tab.getContentFilters(); if (contentFilters.isEmpty()) { return false; // this should never happen, but check just to be sure } else { @@ -46,63 +42,57 @@ public static boolean isStreamsTab(final ListLinkHandler tab) { } @StringRes - private static int getShowTabKey(final String tab) { - switch (tab) { - case ChannelTabs.VIDEOS: - return R.string.show_channel_tabs_videos; - case ChannelTabs.TRACKS: - return R.string.show_channel_tabs_tracks; - case ChannelTabs.SHORTS: - return R.string.show_channel_tabs_shorts; - case ChannelTabs.LIVESTREAMS: - return R.string.show_channel_tabs_livestreams; - case ChannelTabs.CHANNELS: - return R.string.show_channel_tabs_channels; - case ChannelTabs.PLAYLISTS: - return R.string.show_channel_tabs_playlists; - case ChannelTabs.ALBUMS: - return R.string.show_channel_tabs_albums; - default: - return -1; + private static int getShowTabKey(final FilterItem tab) { + if (tab.equals(ChannelTabs.VIDEOS)) { + return R.string.show_channel_tabs_videos; + } else if (tab.equals(ChannelTabs.TRACKS)) { + return R.string.show_channel_tabs_tracks; + } else if (tab.equals(ChannelTabs.SHORTS)) { + return R.string.show_channel_tabs_shorts; + } else if (tab.equals(ChannelTabs.LIVESTREAMS)) { + return R.string.show_channel_tabs_livestreams; + } else if (tab.equals(ChannelTabs.CHANNELS)) { + return R.string.show_channel_tabs_channels; + } else if (tab.equals(ChannelTabs.PLAYLISTS)) { + return R.string.show_channel_tabs_playlists; + } else if (tab.equals(ChannelTabs.ALBUMS)) { + return R.string.show_channel_tabs_albums; } + return -1; } @StringRes - private static int getFetchFeedTabKey(final String tab) { - switch (tab) { - case ChannelTabs.VIDEOS: - return R.string.fetch_channel_tabs_videos; - case ChannelTabs.TRACKS: - return R.string.fetch_channel_tabs_tracks; - case ChannelTabs.SHORTS: - return R.string.fetch_channel_tabs_shorts; - case ChannelTabs.LIVESTREAMS: - return R.string.fetch_channel_tabs_livestreams; - default: - return -1; + private static int getFetchFeedTabKey(final FilterItem tab) { + if (tab.equals(ChannelTabs.VIDEOS)) { + return R.string.fetch_channel_tabs_videos; + } else if (tab.equals(ChannelTabs.TRACKS)) { + return R.string.fetch_channel_tabs_tracks; + } else if (tab.equals(ChannelTabs.SHORTS)) { + return R.string.fetch_channel_tabs_shorts; + } else if (tab.equals(ChannelTabs.LIVESTREAMS)) { + return R.string.fetch_channel_tabs_livestreams; } + return -1; } @StringRes - public static int getTranslationKey(final String tab) { - switch (tab) { - case ChannelTabs.VIDEOS: - return R.string.channel_tab_videos; - case ChannelTabs.TRACKS: - return R.string.channel_tab_tracks; - case ChannelTabs.SHORTS: - return R.string.channel_tab_shorts; - case ChannelTabs.LIVESTREAMS: - return R.string.channel_tab_livestreams; - case ChannelTabs.CHANNELS: - return R.string.channel_tab_channels; - case ChannelTabs.PLAYLISTS: - return R.string.channel_tab_playlists; - case ChannelTabs.ALBUMS: - return R.string.channel_tab_albums; - default: - return R.string.unknown_content; + public static int getTranslationKey(final FilterItem tab) { + if (tab.equals(ChannelTabs.VIDEOS)) { + return R.string.channel_tab_videos; + } else if (tab.equals(ChannelTabs.TRACKS)) { + return R.string.channel_tab_tracks; + } else if (tab.equals(ChannelTabs.SHORTS)) { + return R.string.channel_tab_shorts; + } else if (tab.equals(ChannelTabs.LIVESTREAMS)) { + return R.string.channel_tab_livestreams; + } else if (tab.equals(ChannelTabs.CHANNELS)) { + return R.string.channel_tab_channels; + } else if (tab.equals(ChannelTabs.PLAYLISTS)) { + return R.string.channel_tab_playlists; + } else if (tab.equals(ChannelTabs.ALBUMS)) { + return R.string.channel_tab_albums; } + return R.string.unknown_content; } public static boolean showChannelTab(final Context context, @@ -119,7 +109,7 @@ public static boolean showChannelTab(final Context context, public static boolean showChannelTab(final Context context, final SharedPreferences sharedPreferences, - final String tab) { + final FilterItem tab) { final int key = ChannelTabHelper.getShowTabKey(tab); if (key == -1) { return false; @@ -130,7 +120,7 @@ public static boolean showChannelTab(final Context context, public static boolean fetchFeedChannelTab(final Context context, final SharedPreferences sharedPreferences, final ListLinkHandler tab) { - final List contentFilters = tab.getContentFilters(); + final List contentFilters = tab.getContentFilters(); if (contentFilters.isEmpty()) { return false; // this should never happen, but check just to be sure }