From bb062f07f9415150f4c4b53df6d599de5fae5009 Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Sun, 23 Oct 2022 21:13:43 +0200 Subject: [PATCH] feat: add option to hide channel tabs --- .../list/channel/ChannelFragment.java | 18 ++++- .../list/channel/ChannelInfoFragment.java | 2 +- .../org/schabi/newpipe/util/ChannelTabs.java | 65 +++++++++++++++++++ app/src/main/res/values-de/strings.xml | 8 +++ app/src/main/res/values/settings_keys.xml | 20 ++++++ app/src/main/res/values/strings.xml | 8 +++ app/src/main/res/xml/content_settings.xml | 10 +++ 7 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/util/ChannelTabs.java diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 6e7473b1e..f71791d8e 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -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 { 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"); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelInfoFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelInfoFragment.java index 2ab4ce419..6e7e49876 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelInfoFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelInfoFragment.java @@ -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, diff --git a/app/src/main/java/org/schabi/newpipe/util/ChannelTabs.java b/app/src/main/java/org/schabi/newpipe/util/ChannelTabs.java new file mode 100644 index 000000000..983daf349 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/util/ChannelTabs.java @@ -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 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); + } +} diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index c5260fa03..76abdfbe2 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -767,4 +767,12 @@ Das Media-Tunneling wurde auf dem Gerät standardmäßig deaktiviert, da das Gerätemodell diese Funktion bekanntermaßen nicht unterstützt. Keine Live-Streams Keine Streams + Videos + Live + Shorts + Wiedergabelisten + Kanäle + Info + Tabs auf den Kanalseiten + Welche Tabs auf den Kanalseiten angezeigt werden \ No newline at end of file diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 56fc19eed..00c501643 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -274,6 +274,26 @@ main_tabs_position + channel_tabs + show_channel_tabs_playlists + show_channel_tabs_live + show_channel_tabs_shorts + show_channel_tabs_channels + show_channel_tabs_info + + @string/show_channel_tabs_playlists + @string/show_channel_tabs_livestreams + @string/show_channel_tabs_shorts + @string/show_channel_tabs_channels + @string/show_channel_tabs_info + + + @string/channel_tab_playlists + @string/channel_tab_livestreams + @string/channel_tab_shorts + @string/channel_tab_channels + @string/channel_tab_info + show_search_suggestions show_local_search_suggestions show_remote_search_suggestions diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7d65807b7..fd0971761 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -797,4 +797,12 @@ original dubbed descriptive + Videos + Live + Shorts + Playlists + Channels + Info + Channel tabs + What tabs are shown on the channel pages \ No newline at end of file diff --git a/app/src/main/res/xml/content_settings.xml b/app/src/main/res/xml/content_settings.xml index fddb966c8..8783ff1ed 100644 --- a/app/src/main/res/xml/content_settings.xml +++ b/app/src/main/res/xml/content_settings.xml @@ -41,6 +41,16 @@ app:singleLineTitle="false" app:iconSpaceReserved="false" /> + +