-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathChannelTabHelper.java
More file actions
117 lines (104 loc) · 4.25 KB
/
ChannelTabHelper.java
File metadata and controls
117 lines (104 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package org.schabi.newpipe.util;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.annotation.StringRes;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.linkhandler.ChannelTabs;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.search.filter.FilterItem;
import java.util.List;
import java.util.Set;
public final class ChannelTabHelper {
private ChannelTabHelper() {
}
@StringRes
private static int getShowTabKey(final String tab) {
switch (tab) {
case ChannelTabs.PLAYLISTS:
return R.string.show_channel_tabs_playlists;
case ChannelTabs.LIVESTREAMS:
return R.string.show_channel_tabs_livestreams;
case ChannelTabs.SHORTS:
return R.string.show_channel_tabs_shorts;
case ChannelTabs.CHANNELS:
return R.string.show_channel_tabs_channels;
case ChannelTabs.ALBUMS:
return R.string.show_channel_tabs_albums;
case ChannelTabs.PODCASTS:
return R.string.show_channel_tabs_podcasts;
}
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;
}
}
@StringRes
public static int getTranslationKey(final String tab) {
switch (tab) {
case ChannelTabs.PLAYLISTS:
return R.string.channel_tab_playlists;
case ChannelTabs.LIVESTREAMS:
return R.string.channel_tab_livestreams;
case ChannelTabs.SHORTS:
return R.string.channel_tab_shorts;
case ChannelTabs.CHANNELS:
return R.string.channel_tab_channels;
case ChannelTabs.ALBUMS:
return R.string.channel_tab_albums;
case ChannelTabs.PODCASTS:
return R.string.channel_tab_podcasts;
}
return R.string.unknown_content;
}
public static boolean showChannelTab(final Context context,
final SharedPreferences sharedPreferences,
@StringRes final int key) {
final Set<String> enabledTabs = sharedPreferences.getStringSet(
context.getString(R.string.show_channel_tabs_key), null);
if (enabledTabs == null) {
return true; // default to true
} else {
return enabledTabs.contains(context.getString(key));
}
}
public static boolean showChannelTab(final Context context,
final SharedPreferences sharedPreferences,
final String tab) {
final int key = ChannelTabHelper.getShowTabKey(tab);
if (key == -1) {
return false;
}
return showChannelTab(context, sharedPreferences, key);
}
public static boolean fetchFeedChannelTab(final Context context,
final SharedPreferences sharedPreferences,
final ListLinkHandler tab) {
final List<FilterItem> contentFilters = tab.getContentFilters();
if (contentFilters.isEmpty()) {
return false; // this should never happen, but check just to be sure
}
final int key = ChannelTabHelper.getFetchFeedTabKey(contentFilters.get(0).getName());
if (key == -1) {
return false;
}
final Set<String> enabledTabs = sharedPreferences.getStringSet(
context.getString(R.string.feed_fetch_channel_tabs_key), null);
if (enabledTabs == null) {
return true; // default to true
} else {
return enabledTabs.contains(context.getString(key));
}
}
}