Skip to content

Commit 7b300ec

Browse files
committed
use FilterItem for tabs
1 parent 6bcca69 commit 7b300ec

2 files changed

Lines changed: 53 additions & 62 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.schabi.newpipe.extractor.channel.ChannelInfo;
3939
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
4040
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
41+
import org.schabi.newpipe.extractor.search.filter.FilterItem;
4142
import org.schabi.newpipe.fragments.BaseStateFragment;
4243
import org.schabi.newpipe.fragments.detail.TabAdapter;
4344
import org.schabi.newpipe.ktx.AnimationType;
@@ -461,7 +462,7 @@ private void updateTabs() {
461462
.getDefaultSharedPreferences(context);
462463

463464
for (final ListLinkHandler linkHandler : currentInfo.getTabs()) {
464-
final String tab = linkHandler.getContentFilters().get(0);
465+
final FilterItem tab = linkHandler.getContentFilters().get(0);
465466
if (ChannelTabHelper.showChannelTab(context, preferences, tab)) {
466467
final ChannelTabFragment channelTabFragment =
467468
ChannelTabFragment.getInstance(serviceId, linkHandler, name);

app/src/main/java/org/schabi/newpipe/util/ChannelTabHelper.java

Lines changed: 51 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.schabi.newpipe.R;
99
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs;
1010
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
11+
import org.schabi.newpipe.extractor.search.filter.FilterItem;
1112

1213
import java.util.List;
1314
import java.util.Set;
@@ -20,24 +21,19 @@ private ChannelTabHelper() {
2021
* @param tab the channel tab to check
2122
* @return whether the tab should contain (playable) streams or not
2223
*/
23-
public static boolean isStreamsTab(final String tab) {
24-
switch (tab) {
25-
case ChannelTabs.VIDEOS:
26-
case ChannelTabs.TRACKS:
27-
case ChannelTabs.SHORTS:
28-
case ChannelTabs.LIVESTREAMS:
29-
return true;
30-
default:
31-
return false;
32-
}
24+
public static boolean isStreamsTab(final FilterItem tab) {
25+
return tab.equals(ChannelTabs.VIDEOS)
26+
|| tab.equals(ChannelTabs.TRACKS)
27+
|| tab.equals(ChannelTabs.SHORTS)
28+
|| tab.equals(ChannelTabs.LIVESTREAMS);
3329
}
3430

3531
/**
3632
* @param tab the channel tab link handler to check
3733
* @return whether the tab should contain (playable) streams or not
3834
*/
3935
public static boolean isStreamsTab(final ListLinkHandler tab) {
40-
final List<String> contentFilters = tab.getContentFilters();
36+
final List<FilterItem> contentFilters = tab.getContentFilters();
4137
if (contentFilters.isEmpty()) {
4238
return false; // this should never happen, but check just to be sure
4339
} else {
@@ -46,63 +42,57 @@ public static boolean isStreamsTab(final ListLinkHandler tab) {
4642
}
4743

4844
@StringRes
49-
private static int getShowTabKey(final String tab) {
50-
switch (tab) {
51-
case ChannelTabs.VIDEOS:
52-
return R.string.show_channel_tabs_videos;
53-
case ChannelTabs.TRACKS:
54-
return R.string.show_channel_tabs_tracks;
55-
case ChannelTabs.SHORTS:
56-
return R.string.show_channel_tabs_shorts;
57-
case ChannelTabs.LIVESTREAMS:
58-
return R.string.show_channel_tabs_livestreams;
59-
case ChannelTabs.CHANNELS:
60-
return R.string.show_channel_tabs_channels;
61-
case ChannelTabs.PLAYLISTS:
62-
return R.string.show_channel_tabs_playlists;
63-
case ChannelTabs.ALBUMS:
64-
return R.string.show_channel_tabs_albums;
65-
default:
66-
return -1;
45+
private static int getShowTabKey(final FilterItem tab) {
46+
if (tab.equals(ChannelTabs.VIDEOS)) {
47+
return R.string.show_channel_tabs_videos;
48+
} else if (tab.equals(ChannelTabs.TRACKS)) {
49+
return R.string.show_channel_tabs_tracks;
50+
} else if (tab.equals(ChannelTabs.SHORTS)) {
51+
return R.string.show_channel_tabs_shorts;
52+
} else if (tab.equals(ChannelTabs.LIVESTREAMS)) {
53+
return R.string.show_channel_tabs_livestreams;
54+
} else if (tab.equals(ChannelTabs.CHANNELS)) {
55+
return R.string.show_channel_tabs_channels;
56+
} else if (tab.equals(ChannelTabs.PLAYLISTS)) {
57+
return R.string.show_channel_tabs_playlists;
58+
} else if (tab.equals(ChannelTabs.ALBUMS)) {
59+
return R.string.show_channel_tabs_albums;
6760
}
61+
return -1;
6862
}
6963

7064
@StringRes
71-
private static int getFetchFeedTabKey(final String tab) {
72-
switch (tab) {
73-
case ChannelTabs.VIDEOS:
74-
return R.string.fetch_channel_tabs_videos;
75-
case ChannelTabs.TRACKS:
76-
return R.string.fetch_channel_tabs_tracks;
77-
case ChannelTabs.SHORTS:
78-
return R.string.fetch_channel_tabs_shorts;
79-
case ChannelTabs.LIVESTREAMS:
80-
return R.string.fetch_channel_tabs_livestreams;
81-
default:
82-
return -1;
65+
private static int getFetchFeedTabKey(final FilterItem tab) {
66+
if (tab.equals(ChannelTabs.VIDEOS)) {
67+
return R.string.fetch_channel_tabs_videos;
68+
} else if (tab.equals(ChannelTabs.TRACKS)) {
69+
return R.string.fetch_channel_tabs_tracks;
70+
} else if (tab.equals(ChannelTabs.SHORTS)) {
71+
return R.string.fetch_channel_tabs_shorts;
72+
} else if (tab.equals(ChannelTabs.LIVESTREAMS)) {
73+
return R.string.fetch_channel_tabs_livestreams;
8374
}
75+
return -1;
8476
}
8577

8678
@StringRes
87-
public static int getTranslationKey(final String tab) {
88-
switch (tab) {
89-
case ChannelTabs.VIDEOS:
90-
return R.string.channel_tab_videos;
91-
case ChannelTabs.TRACKS:
92-
return R.string.channel_tab_tracks;
93-
case ChannelTabs.SHORTS:
94-
return R.string.channel_tab_shorts;
95-
case ChannelTabs.LIVESTREAMS:
96-
return R.string.channel_tab_livestreams;
97-
case ChannelTabs.CHANNELS:
98-
return R.string.channel_tab_channels;
99-
case ChannelTabs.PLAYLISTS:
100-
return R.string.channel_tab_playlists;
101-
case ChannelTabs.ALBUMS:
102-
return R.string.channel_tab_albums;
103-
default:
104-
return R.string.unknown_content;
79+
public static int getTranslationKey(final FilterItem tab) {
80+
if (tab.equals(ChannelTabs.VIDEOS)) {
81+
return R.string.channel_tab_videos;
82+
} else if (tab.equals(ChannelTabs.TRACKS)) {
83+
return R.string.channel_tab_tracks;
84+
} else if (tab.equals(ChannelTabs.SHORTS)) {
85+
return R.string.channel_tab_shorts;
86+
} else if (tab.equals(ChannelTabs.LIVESTREAMS)) {
87+
return R.string.channel_tab_livestreams;
88+
} else if (tab.equals(ChannelTabs.CHANNELS)) {
89+
return R.string.channel_tab_channels;
90+
} else if (tab.equals(ChannelTabs.PLAYLISTS)) {
91+
return R.string.channel_tab_playlists;
92+
} else if (tab.equals(ChannelTabs.ALBUMS)) {
93+
return R.string.channel_tab_albums;
10594
}
95+
return R.string.unknown_content;
10696
}
10797

10898
public static boolean showChannelTab(final Context context,
@@ -119,7 +109,7 @@ public static boolean showChannelTab(final Context context,
119109

120110
public static boolean showChannelTab(final Context context,
121111
final SharedPreferences sharedPreferences,
122-
final String tab) {
112+
final FilterItem tab) {
123113
final int key = ChannelTabHelper.getShowTabKey(tab);
124114
if (key == -1) {
125115
return false;
@@ -130,7 +120,7 @@ public static boolean showChannelTab(final Context context,
130120
public static boolean fetchFeedChannelTab(final Context context,
131121
final SharedPreferences sharedPreferences,
132122
final ListLinkHandler tab) {
133-
final List<String> contentFilters = tab.getContentFilters();
123+
final List<FilterItem> contentFilters = tab.getContentFilters();
134124
if (contentFilters.isEmpty()) {
135125
return false; // this should never happen, but check just to be sure
136126
}

0 commit comments

Comments
 (0)