Add preference to hide description tab in video details

This commit is contained in:
Stypox 2020-12-29 22:20:33 +01:00
parent d043a4f410
commit 750c4ffbd3
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
4 changed files with 49 additions and 42 deletions

View File

@ -130,8 +130,6 @@ public final class VideoDetailFragment
OnKeyDownListener { OnKeyDownListener {
public static final String KEY_SWITCHING_PLAYERS = "switching_players"; 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_OVERLAY_ALPHA = 0.9f;
private static final float MAX_PLAYER_HEIGHT = 0.7f; 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"; private static final String DESCRIPTION_TAB_TAG = "DESCRIPTION TAB";
// tabs // tabs
private boolean showRelatedStreams;
private boolean showComments; private boolean showComments;
private boolean showRelatedStreams;
private boolean showDescription;
private String selectedTabTag; private String selectedTabTag;
@AttrRes @NonNull final List<Integer> tabIcons = new ArrayList<>(); @AttrRes @NonNull final List<Integer> tabIcons = new ArrayList<>();
private boolean tabSettingsChanged = false;
private int updateFlags = 0;
@State @State
protected int serviceId = Constants.NO_SERVICE_ID; protected int serviceId = Constants.NO_SERVICE_ID;
@ -275,17 +273,13 @@ public final class VideoDetailFragment
public void onCreate(final Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
showRelatedStreams = PreferenceManager.getDefaultSharedPreferences(activity) final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
.getBoolean(getString(R.string.show_next_video_key), true); showComments = prefs.getBoolean(getString(R.string.show_comments_key), true);
showRelatedStreams = prefs.getBoolean(getString(R.string.show_next_video_key), true);
showComments = PreferenceManager.getDefaultSharedPreferences(activity) showDescription = prefs.getBoolean(getString(R.string.show_description_key), true);
.getBoolean(getString(R.string.show_comments_key), true); selectedTabTag = prefs.getString(
getString(R.string.stream_info_selected_tab_key), COMMENTS_TAB_TAG);
selectedTabTag = PreferenceManager.getDefaultSharedPreferences(activity) prefs.registerOnSharedPreferenceChangeListener(this);
.getString(getString(R.string.stream_info_selected_tab_key), COMMENTS_TAB_TAG);
PreferenceManager.getDefaultSharedPreferences(activity)
.registerOnSharedPreferenceChangeListener(this);
setupBroadcastReceiver(); setupBroadcastReceiver();
@ -330,17 +324,12 @@ public final class VideoDetailFragment
setupBrightness(); setupBrightness();
if (updateFlags != 0) { if (tabSettingsChanged) {
if (!isLoading.get() && currentInfo != null) { tabSettingsChanged = false;
if ((updateFlags & RELATED_STREAMS_UPDATE_FLAG) != 0) { initTabs();
startLoading(false); if (currentInfo != null) {
updateTabs(currentInfo);
} }
if ((updateFlags & COMMENTS_UPDATE_FLAG) != 0) {
startLoading(false);
}
}
updateFlags = 0;
} }
// Check if it was loading when the fragment was stopped/paused // Check if it was loading when the fragment was stopped/paused
@ -415,12 +404,15 @@ public final class VideoDetailFragment
@Override @Override
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
final String key) { final String key) {
if (key.equals(getString(R.string.show_next_video_key))) { if (key.equals(getString(R.string.show_comments_key))) {
showRelatedStreams = sharedPreferences.getBoolean(key, true);
updateFlags |= RELATED_STREAMS_UPDATE_FLAG;
} else if (key.equals(getString(R.string.show_comments_key))) {
showComments = sharedPreferences.getBoolean(key, true); 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); tabIcons.add(R.drawable.ic_art_track_white_24dp);
} }
if (showDescription) {
// temp empty fragment. will be updated in handleResult // temp empty fragment. will be updated in handleResult
pageAdapter.addFragment(new Fragment(), DESCRIPTION_TAB_TAG); pageAdapter.addFragment(new Fragment(), DESCRIPTION_TAB_TAG);
tabIcons.add(R.drawable.ic_description_white_24dp); tabIcons.add(R.drawable.ic_description_white_24dp);
}
pageAdapter.notifyDataSetUpdate(); pageAdapter.notifyDataSetUpdate();
if (pageAdapter.getCount() < 2) { if (pageAdapter.getCount() < 2) {
@ -972,8 +966,11 @@ public final class VideoDetailFragment
} }
} }
if (showDescription) {
pageAdapter.updateItem(DESCRIPTION_TAB_TAG, pageAdapter.updateItem(DESCRIPTION_TAB_TAG,
new DescriptionFragment(info)); new DescriptionFragment(info));
}
pageAdapter.notifyDataSetUpdate(); pageAdapter.notifyDataSetUpdate();
updateTabIcons(); updateTabIcons();
} }

View File

@ -197,8 +197,9 @@
<!-- Content & History --> <!-- Content & History -->
<string name="show_search_suggestions_key" translatable="false">show_search_suggestions</string> <string name="show_search_suggestions_key" translatable="false">show_search_suggestions</string>
<string name="show_play_with_kodi_key" translatable="false">show_play_with_kodi</string> <string name="show_play_with_kodi_key" translatable="false">show_play_with_kodi</string>
<string name="show_next_video_key" translatable="false">show_next_video</string>
<string name="show_comments_key" translatable="false">show_comments</string> <string name="show_comments_key" translatable="false">show_comments</string>
<string name="show_next_video_key" translatable="false">show_next_video</string>
<string name="show_description_key" translatable="false">show_description</string>
<string name="show_meta_info_key" translatable="false">show_meta_info</string> <string name="show_meta_info_key" translatable="false">show_meta_info</string>
<string name="stream_info_selected_tab_key" translatable="false">stream_info_selected_tab</string> <string name="stream_info_selected_tab_key" translatable="false">stream_info_selected_tab</string>
<string name="show_hold_to_append_key" translatable="false">show_hold_to_append</string> <string name="show_hold_to_append_key" translatable="false">show_hold_to_append</string>

View File

@ -91,9 +91,12 @@
<string name="clear_queue_confirmation_summary">Switching from one player to another may replace your queue</string> <string name="clear_queue_confirmation_summary">Switching from one player to another may replace your queue</string>
<string name="clear_queue_confirmation_description">The active player queue will be replaced</string> <string name="clear_queue_confirmation_description">The active player queue will be replaced</string>
<string name="download_thumbnail_title">Load thumbnails</string> <string name="download_thumbnail_title">Load thumbnails</string>
<string name="download_thumbnail_summary">Turn off to prevent loading thumbnails, saving data and memory usage. Changes clear both in-memory and on-disk image cache.</string>
<string name="show_comments_title">Show comments</string> <string name="show_comments_title">Show comments</string>
<string name="show_comments_summary">Turn off to hide comments</string> <string name="show_comments_summary">Turn off to hide comments</string>
<string name="download_thumbnail_summary">Turn off to prevent loading thumbnails, saving data and memory usage. Changes clear both in-memory and on-disk image cache.</string> <string name="show_next_and_similar_title">Show \'Next\' and \'Similar\' videos</string>
<string name="show_description_title">Show description</string>
<string name="show_description_summary">Turn off to hide video description and additional information</string>
<string name="show_meta_info_title">Show meta info</string> <string name="show_meta_info_title">Show meta info</string>
<string name="show_meta_info_summary">Turn off to hide meta info boxes with additional information about the stream creator, stream content or a search request.</string> <string name="show_meta_info_summary">Turn off to hide meta info boxes with additional information about the stream creator, stream content or a search request.</string>
<string name="thumbnail_cache_wipe_complete_notice">Image cache wiped</string> <string name="thumbnail_cache_wipe_complete_notice">Image cache wiped</string>
@ -124,7 +127,6 @@
<string name="resume_on_audio_focus_gain_summary">Continue playing after interruptions (e.g. phonecalls)</string> <string name="resume_on_audio_focus_gain_summary">Continue playing after interruptions (e.g. phonecalls)</string>
<string name="download_dialog_title">Download</string> <string name="download_dialog_title">Download</string>
<string name="autoplay_title">Autoplay</string> <string name="autoplay_title">Autoplay</string>
<string name="show_next_and_similar_title">Show \'Next\' and \'Similar\' videos</string>
<string name="show_hold_to_append_title">Show \"Hold to append\" tip</string> <string name="show_hold_to_append_title">Show \"Hold to append\" tip</string>
<string name="show_hold_to_append_summary">Show tip when pressing the background or the popup button in video \"Details:\"</string> <string name="show_hold_to_append_summary">Show tip when pressing the background or the popup button in video \"Details:\"</string>
<string name="unsupported_url">Unsupported URL</string> <string name="unsupported_url">Unsupported URL</string>

View File

@ -72,6 +72,13 @@
android:title="@string/download_thumbnail_title" android:title="@string/download_thumbnail_title"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/show_comments_key"
android:summary="@string/show_comments_summary"
android:title="@string/show_comments_title"
app:iconSpaceReserved="false" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="true" android:defaultValue="true"
android:key="@string/show_next_video_key" android:key="@string/show_next_video_key"
@ -80,9 +87,9 @@
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="true" android:defaultValue="true"
android:key="@string/show_comments_key" android:key="@string/show_description_key"
android:summary="@string/show_comments_summary" android:summary="@string/show_description_summary"
android:title="@string/show_comments_title" android:title="@string/show_description_title"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreferenceCompat <SwitchPreferenceCompat