1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-22 16:10:31 +00:00

feat: filter fetched channel tabs

This commit is contained in:
ThetaDev 2023-04-16 16:30:40 +02:00 committed by Stypox
parent a2a717bd49
commit 28d952a643
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
5 changed files with 84 additions and 3 deletions

View File

@ -80,7 +80,9 @@ class FeedLoadManager(private val context: Context) {
* subscriptions which have not been updated within the feed updated threshold
*/
val outdatedSubscriptions = when (groupId) {
FeedGroupEntity.GROUP_ALL_ID -> feedDatabaseManager.outdatedSubscriptions(outdatedThreshold)
FeedGroupEntity.GROUP_ALL_ID -> feedDatabaseManager.outdatedSubscriptions(
outdatedThreshold
)
GROUP_NOTIFICATION_ENABLED -> feedDatabaseManager.outdatedSubscriptionsWithNotificationMode(
outdatedThreshold, NotificationMode.ENABLED
)
@ -146,7 +148,13 @@ class FeedLoadManager(private val context: Context) {
originalInfo = channelInfo
streams = channelInfo.tabs
.filter(ChannelTabHelper::isStreamsTab)
.filter { tab ->
ChannelTabHelper.fetchFeedChannelTab(
context,
defaultSharedPreferences,
tab
)
}
.map {
Pair(
getChannelTab(subscriptionEntity.serviceId, it, true)
@ -208,7 +216,12 @@ class FeedLoadManager(private val context: Context) {
}
private fun broadcastProgress() {
FeedEventManager.postEvent(FeedEventManager.Event.ProgressEvent(currentProgress.get(), maxProgress.get()))
FeedEventManager.postEvent(
FeedEventManager.Event.ProgressEvent(
currentProgress.get(),
maxProgress.get()
)
)
}
/**

View File

@ -67,6 +67,22 @@ public final class ChannelTabHelper {
}
}
@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) {
@ -110,4 +126,26 @@ public final class ChannelTabHelper {
}
return showChannelTab(context, sharedPreferences, key);
}
public static boolean fetchFeedChannelTab(final Context context,
final SharedPreferences sharedPreferences,
final ListLinkHandler tab) {
final List<String> 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));
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));
}
}
}

View File

@ -372,6 +372,24 @@
</string-array>
<string name="feed_use_dedicated_fetch_method_key">feed_use_dedicated_fetch_method</string>
<string name="feed_fetch_channel_tabs_key">feed_fetch_channel_tabs</string>
<string name="fetch_channel_tabs_videos">fetch_channel_tabs_videos</string>
<string name="fetch_channel_tabs_tracks">fetch_channel_tabs_tracks</string>
<string name="fetch_channel_tabs_shorts">fetch_channel_tabs_shorts</string>
<string name="fetch_channel_tabs_livestreams">fetch_channel_tabs_live</string>
<string-array name="feed_fetch_channel_tabs_value_list">
<item>@string/fetch_channel_tabs_videos</item>
<item>@string/fetch_channel_tabs_tracks</item>
<item>@string/fetch_channel_tabs_shorts</item>
<item>@string/fetch_channel_tabs_livestreams</item>
</string-array>
<string-array name="feed_fetch_channel_tabs_description_list">
<item>@string/channel_tab_videos</item>
<item>@string/channel_tab_tracks</item>
<item>@string/channel_tab_shorts</item>
<item>@string/channel_tab_livestreams</item>
</string-array>
<string name="import_export_data_path">import_export_data_path</string>
<string name="import_data">import_data</string>
<string name="export_data">export_data</string>

View File

@ -714,6 +714,8 @@
\nSo the choice boils down to what you prefer: speed or precise information.</string>
<string name="feed_hide_streams_title">Show the following streams</string>
<string name="feed_show_hide_streams">Show/Hide streams</string>
<string name="feed_fetch_channel_tabs">Fetch channel tabs</string>
<string name="feed_fetch_channel_tabs_summary">Tabs to fetch when updating the feed. This option has no effect if a channel is updated using fast mode.</string>
<string name="content_not_supported">This content is not yet supported by NewPipe.\n\nIt will hopefully be supported in a future version.</string>
<string name="detail_sub_channel_thumbnail_view_description">Channel\'s avatar thumbnail</string>
<string name="channel_created_by">Created by %s</string>

View File

@ -162,5 +162,15 @@
app:singleLineTitle="false"
app:iconSpaceReserved="false" />
<MultiSelectListPreference
android:key="@string/feed_fetch_channel_tabs_key"
android:summary="@string/feed_fetch_channel_tabs_summary"
android:title="@string/feed_fetch_channel_tabs"
android:entries="@array/feed_fetch_channel_tabs_description_list"
android:entryValues="@array/feed_fetch_channel_tabs_value_list"
android:defaultValue="@array/feed_fetch_channel_tabs_value_list"
app:iconSpaceReserved="false"
app:singleLineTitle="false" />
</PreferenceCategory>
</PreferenceScreen>