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 bf84c732545..c2ce14d428f 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 @@ -161,6 +161,9 @@ public final class VideoDetailFragment private boolean showComments; private boolean showRelatedItems; private boolean showDescription; + + private boolean ignoreQueue; + private String selectedTabTag; @AttrRes @NonNull final List tabIcons = new ArrayList<>(); @StringRes @NonNull final List tabContentDescriptions = new ArrayList<>(); @@ -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) + ); selectedTabTag = prefs.getString( getString(R.string.stream_info_selected_tab_key), COMMENTS_TAB_TAG); prefs.registerOnSharedPreferenceChangeListener(this); @@ -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; + } + // If we have something in history of played items we replay it here if (isPlayerAvailable() && player.getPlayQueue() != null diff --git a/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java index 86e651e2bd0..43f753b538c 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java @@ -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; @@ -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; @@ -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 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3fa37155a96..c9560a1b880 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -755,4 +755,6 @@ Show future items Hide future items Sort + Ignore Playlist Backstack + Playlist Backstack \ No newline at end of file diff --git a/app/src/main/res/xml/history_settings.xml b/app/src/main/res/xml/history_settings.xml index b6126b10a73..27939dab4ae 100644 --- a/app/src/main/res/xml/history_settings.xml +++ b/app/src/main/res/xml/history_settings.xml @@ -37,6 +37,14 @@ app:singleLineTitle="false" app:iconSpaceReserved="false" /> + + +