diff --git a/app/src/main/java/org/schabi/newpipe/ExitActivity.kt b/app/src/main/java/org/schabi/newpipe/ExitActivity.kt index 854a07c43..cc9f448b7 100644 --- a/app/src/main/java/org/schabi/newpipe/ExitActivity.kt +++ b/app/src/main/java/org/schabi/newpipe/ExitActivity.kt @@ -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 diff --git a/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.kt b/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.kt index 33046c967..159791813 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.kt +++ b/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.kt @@ -54,7 +54,7 @@ object NewPipeTextViewHelper { selectedText: CharSequence? ) { if (!selectedText.isNullOrEmpty()) { - ShareUtils.shareText(textView.getContext(), "", selectedText.toString()) + ShareUtils.shareText(textView.context, "", selectedText.toString()) } } } diff --git a/app/src/main/java/org/schabi/newpipe/util/PeertubeHelper.kt b/app/src/main/java/org/schabi/newpipe/util/PeertubeHelper.kt index 3da7958d2..9cf3c1e73 100644 --- a/app/src/main/java/org/schabi/newpipe/util/PeertubeHelper.kt +++ b/app/src/main/java/org/schabi/newpipe/util/PeertubeHelper.kt @@ -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 { 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 } diff --git a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.kt b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.kt index 99cae0010..4239f43e0 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.kt +++ b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.kt @@ -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") + ) } }