1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2026-02-11 04:30:15 +00:00

Minor improvements

- Use early return in case of nulls
- Use better variable names
- Remove non-required newlines, imports and add missing ones

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2026-02-10 16:32:53 +08:00
parent c6fc94e7bd
commit 224a5d0cb9
4 changed files with 15 additions and 23 deletions

View File

@@ -10,13 +10,12 @@ import android.app.Activity
import android.content.Intent
import android.os.Bundle
import org.schabi.newpipe.util.NavigationHelper
class ExitActivity : Activity() {
@SuppressLint("NewApi")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
finishAndRemoveTask()
NavigationHelper.restartApp(this)
}
@@ -24,7 +23,6 @@ class ExitActivity : Activity() {
@JvmStatic
fun exitAndRemoveFromRecentApps(activity: Activity) {
val intent = Intent(activity, ExitActivity::class.java)
intent.addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK
or Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS

View File

@@ -54,7 +54,7 @@ object NewPipeTextViewHelper {
selectedText: CharSequence?
) {
if (!selectedText.isNullOrEmpty()) {
ShareUtils.shareText(textView.getContext(), "", selectedText.toString())
ShareUtils.shareText(textView.context, "", selectedText.toString())
}
}
}

View File

@@ -16,14 +16,17 @@ import org.schabi.newpipe.extractor.ServiceList
import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance
object PeertubeHelper {
@JvmStatic
val currentInstance: PeertubeInstance
get() = ServiceList.PeerTube.instance
@JvmStatic
fun getInstanceList(context: Context): List<PeertubeInstance> {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
val savedInstanceListKey = context.getString(R.string.peertube_instance_list_key)
val savedJson = sharedPreferences.getString(savedInstanceListKey, null)
if (savedJson == null) {
return listOf(currentInstance)
}
?: return listOf(currentInstance)
return runCatching {
JsonParser.`object`().from(savedJson).getArray("instances")
@@ -46,8 +49,4 @@ object PeertubeHelper {
ServiceList.PeerTube.instance = instance
return instance
}
@JvmStatic
val currentInstance: PeertubeInstance
get() = ServiceList.PeerTube.instance
}

View File

@@ -10,15 +10,12 @@ import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import com.grack.nanojson.JsonObject
import com.grack.nanojson.JsonParser
import com.grack.nanojson.JsonParserException
import java.util.concurrent.TimeUnit
import org.schabi.newpipe.R
import org.schabi.newpipe.extractor.NewPipe
import org.schabi.newpipe.extractor.ServiceList
import org.schabi.newpipe.extractor.StreamingService
import org.schabi.newpipe.extractor.exceptions.ExtractionException
import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance
import org.schabi.newpipe.ktx.getStringSafe
@@ -133,8 +130,8 @@ object ServiceHelper {
}
private fun setSelectedServicePreferences(context: Context, serviceName: String?) {
val sp = PreferenceManager.getDefaultSharedPreferences(context)
sp.edit { putString(context.getString(R.string.current_service_key), serviceName) }
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
sharedPreferences.edit { putString(context.getString(R.string.current_service_key), serviceName) }
}
@JvmStatic
@@ -152,17 +149,15 @@ object ServiceHelper {
val json = sharedPreferences.getString(
context.getString(R.string.peertube_selected_instance_key),
null
)
if (null == json) {
return
}
) ?: return
val jsonObject = runCatching { JsonParser.`object`().from(json) }
.getOrElse { return@initService }
val name = jsonObject.getString("name")
val url = jsonObject.getString("url")
ServiceList.PeerTube.instance = PeertubeInstance(url, name)
ServiceList.PeerTube.instance = PeertubeInstance(
jsonObject.getString("url"),
jsonObject.getString("name")
)
}
}