|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2023-2026 NewPipe contributors <https://newpipe.net> |
| 3 | + * SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +package org.schabi.newpipe.util |
| 7 | + |
| 8 | +import android.content.Context |
| 9 | +import androidx.preference.PreferenceManager |
| 10 | +import org.schabi.newpipe.R |
| 11 | + |
| 12 | +/** |
| 13 | + * For preferences with dependencies and multiple use case, |
| 14 | + * this class can be used to reduce the lines of code. |
| 15 | + */ |
| 16 | +object DependentPreferenceHelper { |
| 17 | + /** |
| 18 | + * Option `Resume playback` depends on `Watch history`, this method can be used to retrieve if |
| 19 | + * `Resume playback` and its dependencies are all enabled. |
| 20 | + * |
| 21 | + * @param context the Android context |
| 22 | + * @return returns true if `Resume playback` and `Watch history` are both enabled |
| 23 | + */ |
| 24 | + @JvmStatic |
| 25 | + fun getResumePlaybackEnabled(context: Context): Boolean { |
| 26 | + val prefs = PreferenceManager.getDefaultSharedPreferences(context) |
| 27 | + |
| 28 | + return prefs.getBoolean(context.getString(R.string.enable_watch_history_key), true) && |
| 29 | + prefs.getBoolean(context.getString(R.string.enable_playback_resume_key), true) |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Option `Position in lists` depends on `Watch history`, this method can be used to retrieve if |
| 34 | + * `Position in lists` and its dependencies are all enabled. |
| 35 | + * |
| 36 | + * @param context the Android context |
| 37 | + * @return returns true if `Positions in lists` and `Watch history` are both enabled |
| 38 | + */ |
| 39 | + @JvmStatic |
| 40 | + fun getPositionsInListsEnabled(context: Context): Boolean { |
| 41 | + val prefs = PreferenceManager.getDefaultSharedPreferences(context) |
| 42 | + |
| 43 | + return prefs.getBoolean(context.getString(R.string.enable_watch_history_key), true) && |
| 44 | + prefs.getBoolean(context.getString(R.string.enable_playback_state_lists_key), true) |
| 45 | + } |
| 46 | +} |
0 commit comments