Skip to content

Commit e6e0be7

Browse files
authored
Merge pull request #13026 from dustdfg/kotlin_merged2
Convert a bunch of files to kotlin
2 parents 13186c0 + 224a5d0 commit e6e0be7

16 files changed

Lines changed: 564 additions & 646 deletions

app/src/main/java/org/schabi/newpipe/ExitActivity.java

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2016-2026 NewPipe contributors <https://newpipe.net>
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*/
5+
6+
package org.schabi.newpipe
7+
8+
import android.annotation.SuppressLint
9+
import android.app.Activity
10+
import android.content.Intent
11+
import android.os.Bundle
12+
import org.schabi.newpipe.util.NavigationHelper
13+
14+
class ExitActivity : Activity() {
15+
@SuppressLint("NewApi")
16+
override fun onCreate(savedInstanceState: Bundle?) {
17+
super.onCreate(savedInstanceState)
18+
finishAndRemoveTask()
19+
NavigationHelper.restartApp(this)
20+
}
21+
22+
companion object {
23+
@JvmStatic
24+
fun exitAndRemoveFromRecentApps(activity: Activity) {
25+
val intent = Intent(activity, ExitActivity::class.java)
26+
intent.addFlags(
27+
Intent.FLAG_ACTIVITY_NEW_TASK
28+
or Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
29+
or Intent.FLAG_ACTIVITY_CLEAR_TASK
30+
or Intent.FLAG_ACTIVITY_NO_ANIMATION
31+
)
32+
33+
activity.startActivity(intent)
34+
}
35+
}
36+
}

app/src/main/java/org/schabi/newpipe/settings/export/PreferencesObjectInputStream.java

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024-2026 NewPipe contributors <https://newpipe.net>
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*/
5+
6+
package org.schabi.newpipe.settings.export
7+
8+
import java.io.IOException
9+
import java.io.InputStream
10+
import java.io.ObjectInputStream
11+
import java.io.ObjectStreamClass
12+
13+
/**
14+
* An [ObjectInputStream] that only allows preferences-related types to be deserialized, to
15+
* prevent injections. The only allowed types are: all primitive types, all boxed primitive types,
16+
* null, strings. HashMap, HashSet and arrays of previously defined types are also allowed. Sources:
17+
* [cmu.edu](https://wiki.sei.cmu.edu/confluence/display/java/SER00-J.+Enable+serialization+compatibility+during+class+evolution) * ,
18+
* [OWASP cheatsheet](https://cheatsheetseries.owasp.org/cheatsheets/Deserialization_Cheat_Sheet.html#harden-your-own-javaioobjectinputstream) * ,
19+
* [Apache's `ValidatingObjectInputStream`](https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/serialization/ValidatingObjectInputStream.html#line-118) *
20+
*/
21+
class PreferencesObjectInputStream(stream: InputStream) : ObjectInputStream(stream) {
22+
@Throws(ClassNotFoundException::class, IOException::class)
23+
override fun resolveClass(desc: ObjectStreamClass): Class<*> {
24+
if (desc.name in CLASS_WHITELIST) {
25+
return super.resolveClass(desc)
26+
} else {
27+
throw ClassNotFoundException("Class not allowed: $desc.name")
28+
}
29+
}
30+
31+
companion object {
32+
/**
33+
* Primitive types, strings and other built-in types do not pass through resolveClass() but
34+
* instead have a custom encoding; see
35+
* [
36+
* official docs](https://docs.oracle.com/javase/6/docs/platform/serialization/spec/protocol.html#10152).
37+
*/
38+
private val CLASS_WHITELIST = setOf<String>(
39+
"java.lang.Boolean",
40+
"java.lang.Byte",
41+
"java.lang.Character",
42+
"java.lang.Short",
43+
"java.lang.Integer",
44+
"java.lang.Long",
45+
"java.lang.Float",
46+
"java.lang.Double",
47+
"java.lang.Void",
48+
"java.util.HashMap",
49+
"java.util.HashSet"
50+
)
51+
}
52+
}

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+
}

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

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)