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

feat: add option to hide channel tabs

This commit is contained in:
ThetaDev 2022-10-23 21:13:43 +02:00 committed by Stypox
parent c3d1e75a8f
commit bb062f07f9
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
7 changed files with 127 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package org.schabi.newpipe.fragments.list.channel;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
@ -13,6 +14,7 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;
import org.schabi.newpipe.R;
import org.schabi.newpipe.database.subscription.NotificationMode;
@ -27,6 +29,7 @@ import org.schabi.newpipe.fragments.BaseStateFragment;
import org.schabi.newpipe.fragments.detail.TabAdapter;
import org.schabi.newpipe.local.feed.notifications.NotificationHelper;
import org.schabi.newpipe.local.subscription.SubscriptionManager;
import org.schabi.newpipe.util.ChannelTabs;
import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.ExtractorHelper;
import org.schabi.newpipe.util.NavigationHelper;
@ -268,13 +271,22 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo> {
tabAdapter.addFragment(
ChannelVideosFragment.getInstance(currentInfo), "Videos");
final Context context = getContext();
final SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(context);
for (final ChannelTabHandler tab : currentInfo.getTabs()) {
tabAdapter.addFragment(
ChannelTabFragment.getInstance(serviceId, tab), tab.getTab().name());
if (ChannelTabs.showChannelTab(context, preferences, tab.getTab())) {
tabAdapter.addFragment(
ChannelTabFragment.getInstance(serviceId, tab),
context.getString(ChannelTabs.getTranslationKey(tab.getTab())));
}
}
final String description = currentInfo.getDescription();
if (description != null && !description.isEmpty()) {
if (description != null && !description.isEmpty() &&
ChannelTabs.showChannelTab(
context, preferences, R.string.show_channel_tabs_info)) {
tabAdapter.addFragment(
ChannelInfoFragment.getInstance(currentInfo), "Info");
}

View File

@ -79,7 +79,7 @@ public class ChannelInfoFragment extends BaseFragment {
private void setupMetadata(final LayoutInflater inflater,
final LinearLayout layout) {
Context context = getActivity();
Context context = getContext();
if (channelInfo.getSubscriberCount() != UNKNOWN_SUBSCRIBER_COUNT) {
addMetadataItem(inflater, layout, R.string.metadata_subscribers,

View File

@ -0,0 +1,65 @@
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.ChannelTabHandler.Tab;
import java.util.Set;
public class ChannelTabs {
@StringRes
private static int getShowTabKey(final Tab tab) {
switch (tab) {
case Playlists:
return R.string.show_channel_tabs_playlists;
case Livestreams:
return R.string.show_channel_tabs_livestreams;
case Shorts:
return R.string.show_channel_tabs_shorts;
case Channels:
return R.string.show_channel_tabs_channels;
}
return -1;
}
@StringRes
public static int getTranslationKey(final Tab tab) {
switch (tab) {
case Playlists:
return R.string.channel_tab_playlists;
case Livestreams:
return R.string.channel_tab_livestreams;
case Shorts:
return R.string.channel_tab_shorts;
case Channels:
return R.string.channel_tab_channels;
}
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 Tab tab) {
final int key = ChannelTabs.getShowTabKey(tab);
if (key == -1) {
return false;
}
return showChannelTab(context, sharedPreferences, key);
}
}

View File

@ -767,4 +767,12 @@
<string name="disable_media_tunneling_automatic_info">Das Media-Tunneling wurde auf dem Gerät standardmäßig deaktiviert, da das Gerätemodell diese Funktion bekanntermaßen nicht unterstützt.</string>
<string name="no_live_streams">Keine Live-Streams</string>
<string name="no_streams">Keine Streams</string>
<string name="channel_tab_videos">Videos</string>
<string name="channel_tab_livestreams">Live</string>
<string name="channel_tab_shorts">Shorts</string>
<string name="channel_tab_playlists">Wiedergabelisten</string>
<string name="channel_tab_channels">Kanäle</string>
<string name="channel_tab_info">Info</string>
<string name="show_channel_tabs">Tabs auf den Kanalseiten</string>
<string name="show_channel_tabs_summary">Welche Tabs auf den Kanalseiten angezeigt werden</string>
</resources>

View File

@ -274,6 +274,26 @@
<string name="main_tabs_position_key">main_tabs_position</string>
<!-- Content & History -->
<string name="show_channel_tabs_key">channel_tabs</string>
<string name="show_channel_tabs_playlists">show_channel_tabs_playlists</string>
<string name="show_channel_tabs_livestreams">show_channel_tabs_live</string>
<string name="show_channel_tabs_shorts">show_channel_tabs_shorts</string>
<string name="show_channel_tabs_channels">show_channel_tabs_channels</string>
<string name="show_channel_tabs_info">show_channel_tabs_info</string>
<string-array name="show_channel_tabs_value_list">
<item>@string/show_channel_tabs_playlists</item>
<item>@string/show_channel_tabs_livestreams</item>
<item>@string/show_channel_tabs_shorts</item>
<item>@string/show_channel_tabs_channels</item>
<item>@string/show_channel_tabs_info</item>
</string-array>
<string-array name="show_channel_tabs_description_list">
<item>@string/channel_tab_playlists</item>
<item>@string/channel_tab_livestreams</item>
<item>@string/channel_tab_shorts</item>
<item>@string/channel_tab_channels</item>
<item>@string/channel_tab_info</item>
</string-array>
<string name="show_search_suggestions_key">show_search_suggestions</string>
<string name="show_local_search_suggestions_key">show_local_search_suggestions</string>
<string name="show_remote_search_suggestions_key">show_remote_search_suggestions</string>

View File

@ -797,4 +797,12 @@
<string name="audio_track_type_original">original</string>
<string name="audio_track_type_dubbed">dubbed</string>
<string name="audio_track_type_descriptive">descriptive</string>
<string name="channel_tab_videos">Videos</string>
<string name="channel_tab_livestreams">Live</string>
<string name="channel_tab_shorts">Shorts</string>
<string name="channel_tab_playlists">Playlists</string>
<string name="channel_tab_channels">Channels</string>
<string name="channel_tab_info">Info</string>
<string name="show_channel_tabs">Channel tabs</string>
<string name="show_channel_tabs_summary">What tabs are shown on the channel pages</string>
</resources>

View File

@ -41,6 +41,16 @@
app:singleLineTitle="false"
app:iconSpaceReserved="false" />
<MultiSelectListPreference
android:key="@string/show_channel_tabs_key"
android:summary="@string/show_channel_tabs_summary"
android:title="@string/show_channel_tabs"
android:entries="@array/show_channel_tabs_description_list"
android:entryValues="@array/show_channel_tabs_value_list"
android:defaultValue="@array/show_channel_tabs_value_list"
app:iconSpaceReserved="false"
app:singleLineTitle="false" />
<PreferenceScreen
android:fragment="org.schabi.newpipe.settings.PeertubeInstanceListFragment"
android:key="@string/peertube_instance_setup_key"