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:
parent
a379e46eb2
commit
99f26cc7ff
4 changed files with 15 additions and 23 deletions
|
|
@ -10,13 +10,12 @@ import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import org.schabi.newpipe.util.NavigationHelper
|
import org.schabi.newpipe.util.NavigationHelper
|
||||||
|
|
||||||
class ExitActivity : Activity() {
|
class ExitActivity : Activity() {
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
finishAndRemoveTask()
|
finishAndRemoveTask()
|
||||||
|
|
||||||
NavigationHelper.restartApp(this)
|
NavigationHelper.restartApp(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,7 +23,6 @@ class ExitActivity : Activity() {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun exitAndRemoveFromRecentApps(activity: Activity) {
|
fun exitAndRemoveFromRecentApps(activity: Activity) {
|
||||||
val intent = Intent(activity, ExitActivity::class.java)
|
val intent = Intent(activity, ExitActivity::class.java)
|
||||||
|
|
||||||
intent.addFlags(
|
intent.addFlags(
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
or Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
|
or Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ object NewPipeTextViewHelper {
|
||||||
selectedText: CharSequence?
|
selectedText: CharSequence?
|
||||||
) {
|
) {
|
||||||
if (!selectedText.isNullOrEmpty()) {
|
if (!selectedText.isNullOrEmpty()) {
|
||||||
ShareUtils.shareText(textView.getContext(), "", selectedText.toString())
|
ShareUtils.shareText(textView.context, "", selectedText.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,17 @@ import org.schabi.newpipe.extractor.ServiceList
|
||||||
import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance
|
import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance
|
||||||
|
|
||||||
object PeertubeHelper {
|
object PeertubeHelper {
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
val currentInstance: PeertubeInstance
|
||||||
|
get() = ServiceList.PeerTube.instance
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getInstanceList(context: Context): List<PeertubeInstance> {
|
fun getInstanceList(context: Context): List<PeertubeInstance> {
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
val savedInstanceListKey = context.getString(R.string.peertube_instance_list_key)
|
val savedInstanceListKey = context.getString(R.string.peertube_instance_list_key)
|
||||||
val savedJson = sharedPreferences.getString(savedInstanceListKey, null)
|
val savedJson = sharedPreferences.getString(savedInstanceListKey, null)
|
||||||
if (savedJson == null) {
|
?: return listOf(currentInstance)
|
||||||
return listOf(currentInstance)
|
|
||||||
}
|
|
||||||
|
|
||||||
return runCatching {
|
return runCatching {
|
||||||
JsonParser.`object`().from(savedJson).getArray("instances")
|
JsonParser.`object`().from(savedJson).getArray("instances")
|
||||||
|
|
@ -46,8 +49,4 @@ object PeertubeHelper {
|
||||||
ServiceList.PeerTube.instance = instance
|
ServiceList.PeerTube.instance = instance
|
||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
val currentInstance: PeertubeInstance
|
|
||||||
get() = ServiceList.PeerTube.instance
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,15 +10,12 @@ import androidx.annotation.DrawableRes
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.grack.nanojson.JsonObject
|
|
||||||
import com.grack.nanojson.JsonParser
|
import com.grack.nanojson.JsonParser
|
||||||
import com.grack.nanojson.JsonParserException
|
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.extractor.NewPipe
|
import org.schabi.newpipe.extractor.NewPipe
|
||||||
import org.schabi.newpipe.extractor.ServiceList
|
import org.schabi.newpipe.extractor.ServiceList
|
||||||
import org.schabi.newpipe.extractor.StreamingService
|
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.extractor.services.peertube.PeertubeInstance
|
||||||
import org.schabi.newpipe.ktx.getStringSafe
|
import org.schabi.newpipe.ktx.getStringSafe
|
||||||
|
|
||||||
|
|
@ -133,8 +130,8 @@ object ServiceHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setSelectedServicePreferences(context: Context, serviceName: String?) {
|
private fun setSelectedServicePreferences(context: Context, serviceName: String?) {
|
||||||
val sp = PreferenceManager.getDefaultSharedPreferences(context)
|
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
sp.edit { putString(context.getString(R.string.current_service_key), serviceName) }
|
sharedPreferences.edit { putString(context.getString(R.string.current_service_key), serviceName) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
|
@ -152,17 +149,15 @@ object ServiceHelper {
|
||||||
val json = sharedPreferences.getString(
|
val json = sharedPreferences.getString(
|
||||||
context.getString(R.string.peertube_selected_instance_key),
|
context.getString(R.string.peertube_selected_instance_key),
|
||||||
null
|
null
|
||||||
)
|
) ?: return
|
||||||
if (null == json) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val jsonObject = runCatching { JsonParser.`object`().from(json) }
|
val jsonObject = runCatching { JsonParser.`object`().from(json) }
|
||||||
.getOrElse { return@initService }
|
.getOrElse { return@initService }
|
||||||
|
|
||||||
val name = jsonObject.getString("name")
|
ServiceList.PeerTube.instance = PeertubeInstance(
|
||||||
val url = jsonObject.getString("url")
|
jsonObject.getString("url"),
|
||||||
ServiceList.PeerTube.instance = PeertubeInstance(url, name)
|
jsonObject.getString("name")
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue