From 750c4ffbd3ccfa9e6cf17ad6fb2f3a0e58e4a2bb Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 29 Dec 2020 22:20:33 +0100 Subject: [PATCH] Add preference to hide description tab in video details --- .../fragments/detail/VideoDetailFragment.java | 69 +++++++++---------- app/src/main/res/values/settings_keys.xml | 3 +- app/src/main/res/values/strings.xml | 6 +- app/src/main/res/xml/content_settings.xml | 13 +++- 4 files changed, 49 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index e9eb22314..375fb0918 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -130,8 +130,6 @@ public final class VideoDetailFragment OnKeyDownListener { public static final String KEY_SWITCHING_PLAYERS = "switching_players"; - private static final int RELATED_STREAMS_UPDATE_FLAG = 0x1; - private static final int COMMENTS_UPDATE_FLAG = 0x2; private static final float MAX_OVERLAY_ALPHA = 0.9f; private static final float MAX_PLAYER_HEIGHT = 0.7f; @@ -151,12 +149,12 @@ public final class VideoDetailFragment private static final String DESCRIPTION_TAB_TAG = "DESCRIPTION TAB"; // tabs - private boolean showRelatedStreams; private boolean showComments; + private boolean showRelatedStreams; + private boolean showDescription; private String selectedTabTag; @AttrRes @NonNull final List tabIcons = new ArrayList<>(); - - private int updateFlags = 0; + private boolean tabSettingsChanged = false; @State protected int serviceId = Constants.NO_SERVICE_ID; @@ -275,17 +273,13 @@ public final class VideoDetailFragment public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - showRelatedStreams = PreferenceManager.getDefaultSharedPreferences(activity) - .getBoolean(getString(R.string.show_next_video_key), true); - - showComments = PreferenceManager.getDefaultSharedPreferences(activity) - .getBoolean(getString(R.string.show_comments_key), true); - - selectedTabTag = PreferenceManager.getDefaultSharedPreferences(activity) - .getString(getString(R.string.stream_info_selected_tab_key), COMMENTS_TAB_TAG); - - PreferenceManager.getDefaultSharedPreferences(activity) - .registerOnSharedPreferenceChangeListener(this); + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); + showComments = prefs.getBoolean(getString(R.string.show_comments_key), true); + showRelatedStreams = prefs.getBoolean(getString(R.string.show_next_video_key), true); + showDescription = prefs.getBoolean(getString(R.string.show_description_key), true); + selectedTabTag = prefs.getString( + getString(R.string.stream_info_selected_tab_key), COMMENTS_TAB_TAG); + prefs.registerOnSharedPreferenceChangeListener(this); setupBroadcastReceiver(); @@ -330,17 +324,12 @@ public final class VideoDetailFragment setupBrightness(); - if (updateFlags != 0) { - if (!isLoading.get() && currentInfo != null) { - if ((updateFlags & RELATED_STREAMS_UPDATE_FLAG) != 0) { - startLoading(false); - } - if ((updateFlags & COMMENTS_UPDATE_FLAG) != 0) { - startLoading(false); - } + if (tabSettingsChanged) { + tabSettingsChanged = false; + initTabs(); + if (currentInfo != null) { + updateTabs(currentInfo); } - - updateFlags = 0; } // Check if it was loading when the fragment was stopped/paused @@ -415,12 +404,15 @@ public final class VideoDetailFragment @Override public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) { - if (key.equals(getString(R.string.show_next_video_key))) { - showRelatedStreams = sharedPreferences.getBoolean(key, true); - updateFlags |= RELATED_STREAMS_UPDATE_FLAG; - } else if (key.equals(getString(R.string.show_comments_key))) { + if (key.equals(getString(R.string.show_comments_key))) { showComments = sharedPreferences.getBoolean(key, true); - updateFlags |= COMMENTS_UPDATE_FLAG; + tabSettingsChanged = true; + } else if (key.equals(getString(R.string.show_next_video_key))) { + showRelatedStreams = sharedPreferences.getBoolean(key, true); + tabSettingsChanged = true; + } else if (key.equals(getString(R.string.show_description_key))) { + showComments = sharedPreferences.getBoolean(key, true); + tabSettingsChanged = true; } } @@ -926,9 +918,11 @@ public final class VideoDetailFragment tabIcons.add(R.drawable.ic_art_track_white_24dp); } - // temp empty fragment. will be updated in handleResult - pageAdapter.addFragment(new Fragment(), DESCRIPTION_TAB_TAG); - tabIcons.add(R.drawable.ic_description_white_24dp); + if (showDescription) { + // temp empty fragment. will be updated in handleResult + pageAdapter.addFragment(new Fragment(), DESCRIPTION_TAB_TAG); + tabIcons.add(R.drawable.ic_description_white_24dp); + } pageAdapter.notifyDataSetUpdate(); if (pageAdapter.getCount() < 2) { @@ -972,8 +966,11 @@ public final class VideoDetailFragment } } - pageAdapter.updateItem(DESCRIPTION_TAB_TAG, - new DescriptionFragment(info)); + if (showDescription) { + pageAdapter.updateItem(DESCRIPTION_TAB_TAG, + new DescriptionFragment(info)); + } + pageAdapter.notifyDataSetUpdate(); updateTabIcons(); } diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 1e74f25a6..1c4ad11a3 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -197,8 +197,9 @@ show_search_suggestions show_play_with_kodi - show_next_video show_comments + show_next_video + show_description show_meta_info stream_info_selected_tab show_hold_to_append diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 82a5bda6c..207680fef 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -91,9 +91,12 @@ Switching from one player to another may replace your queue The active player queue will be replaced Load thumbnails + Turn off to prevent loading thumbnails, saving data and memory usage. Changes clear both in-memory and on-disk image cache. Show comments Turn off to hide comments - Turn off to prevent loading thumbnails, saving data and memory usage. Changes clear both in-memory and on-disk image cache. + Show \'Next\' and \'Similar\' videos + Show description + Turn off to hide video description and additional information Show meta info Turn off to hide meta info boxes with additional information about the stream creator, stream content or a search request. Image cache wiped @@ -124,7 +127,6 @@ Continue playing after interruptions (e.g. phonecalls) Download Autoplay - Show \'Next\' and \'Similar\' videos Show \"Hold to append\" tip Show tip when pressing the background or the popup button in video \"Details:\" Unsupported URL diff --git a/app/src/main/res/xml/content_settings.xml b/app/src/main/res/xml/content_settings.xml index 914fb2e59..70fb3b977 100644 --- a/app/src/main/res/xml/content_settings.xml +++ b/app/src/main/res/xml/content_settings.xml @@ -72,6 +72,13 @@ android:title="@string/download_thumbnail_title" app:iconSpaceReserved="false" /> + +