Skip to content

Commit

Permalink
use FilterItem for tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
evermind-zz committed Jan 1, 2024
1 parent 6bcca69 commit 7b300ec
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
112 changes: 51 additions & 61 deletions app/src/main/java/org/schabi/newpipe/util/ChannelTabHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,24 +21,19 @@ 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);
}

/**
* @param tab the channel tab link handler to check
* @return whether the tab should contain (playable) streams or not
*/
public static boolean isStreamsTab(final ListLinkHandler tab) {
final List<String> contentFilters = tab.getContentFilters();
final List<FilterItem> contentFilters = tab.getContentFilters();
if (contentFilters.isEmpty()) {
return false; // this should never happen, but check just to be sure
} else {
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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<String> contentFilters = tab.getContentFilters();
final List<FilterItem> contentFilters = tab.getContentFilters();
if (contentFilters.isEmpty()) {
return false; // this should never happen, but check just to be sure
}
Expand Down

0 comments on commit 7b300ec

Please sign in to comment.