Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement ability to ignore back-queue for main view #7273

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ public final class VideoDetailFragment
private boolean showComments;
private boolean showRelatedItems;
private boolean showDescription;

private boolean ignoreQueue;

Comment on lines +164 to +166
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename the variable and remove spaces

Suggested change
private boolean ignoreQueue;
private boolean ignoreBackstack;

private String selectedTabTag;
@AttrRes @NonNull final List<Integer> tabIcons = new ArrayList<>();
@StringRes @NonNull final List<Integer> tabContentDescriptions = new ArrayList<>();
Expand Down Expand Up @@ -288,6 +291,10 @@ public void onCreate(final Bundle savedInstanceState) {
showComments = prefs.getBoolean(getString(R.string.show_comments_key), true);
showRelatedItems = prefs.getBoolean(getString(R.string.show_next_video_key), true);
showDescription = prefs.getBoolean(getString(R.string.show_description_key), true);
ignoreQueue = prefs.getBoolean(
getString(R.string.enable_ignore_backstack_key),
DeviceUtils.isTv(activity)
);
Comment on lines +294 to +297
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the user changes preference while the fragment is open? You need to update this variable in the shared preference change listener.

selectedTabTag = prefs.getString(
getString(R.string.stream_info_selected_tab_key), COMMENTS_TAB_TAG);
prefs.registerOnSharedPreferenceChangeListener(this);
Expand Down Expand Up @@ -782,6 +789,11 @@ public boolean onBackPressed() {
return true;
}

// when queue should be ignored, directly skip checks and let MainActivity handle everything
if (ignoreQueue) {
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should also restoreDefaultOrientation()

}

// If we have something in history of played items we replay it here
if (isPlayerAvailable()
&& player.getPlayQueue() != null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.schabi.newpipe.settings;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference;
import androidx.preference.PreferenceManager;
import androidx.preference.SwitchPreferenceCompat;

import org.schabi.newpipe.DownloaderImpl;
import org.schabi.newpipe.R;
Expand All @@ -15,6 +19,7 @@
import org.schabi.newpipe.error.ReCaptchaActivity;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.InfoCache;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
Expand Down Expand Up @@ -54,6 +59,38 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
if (defaultPreferences.getString(getString(R.string.recaptcha_cookies_key), "").isEmpty()) {
clearCookiePref.setEnabled(false);
}

final String backstackPreferenceKey = getString(R.string.enable_ignore_backstack_key);
final SwitchPreferenceCompat backstackPref = findPreference(backstackPreferenceKey);
final Activity activity = this.getActivity();

if (activity != null) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);

final boolean retrievedValue = prefs.getBoolean(
getString(R.string.enable_ignore_backstack_key),
DeviceUtils.isTv(activity)
);

// Get the value stored. (Default does not matter)
// If the retrieved value matches the default value, use the default.
// If not, use the retrieved
// This works because now when we call setChecked, and save it,
// we either store the proper changed value, or the default value.
// However, if the default value is equal to the set-value, we don't actually
// change anything even if we "override" the value
// Drawback: As soon as the settings are opened, the value is set&saved.
// No "default" anymore.
// The default is applied exactly once, and then stored
boolean valueToSet = DeviceUtils.isTv(activity);
if (retrievedValue != valueToSet) {
valueToSet = retrievedValue;
}

if (backstackPref != null) {
backstackPref.setChecked(valueToSet);
}
}
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -755,4 +755,6 @@
<string name="feed_toggle_show_future_items">Show future items</string>
<string name="feed_toggle_hide_future_items">Hide future items</string>
<string name="sort">Sort</string>
<string name="enable_ignore_backstack_key">Ignore Playlist Backstack</string>
<string name="enable_ignore_backstack_title">Playlist Backstack</string>
</resources>
8 changes: 8 additions & 0 deletions app/src/main/res/xml/history_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
app:singleLineTitle="false"
app:iconSpaceReserved="false" />

<SwitchPreferenceCompat
android:key="@string/enable_ignore_backstack_key"
android:summary="@string/enable_ignore_backstack_key"
android:title="@string/enable_ignore_backstack_title"
app:singleLineTitle="false"
app:iconSpaceReserved="false" />


<PreferenceCategory
android:layout="@layout/settings_category_header_layout"
android:title="@string/settings_category_clear_data_title"
Expand Down