Skip to content

Commit 2c7654a

Browse files
author
Yevhen Babiichuk (DustDFG)
committed
Covert newpipe/util/DependentPreferenceHelper to kotlin
1 parent 09a746d commit 2c7654a

2 files changed

Lines changed: 46 additions & 51 deletions

File tree

app/src/main/java/org/schabi/newpipe/util/DependentPreferenceHelper.java

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)