Skip to content

Commit 224a5d0

Browse files
committed
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>
1 parent c6fc94e commit 224a5d0

4 files changed

Lines changed: 15 additions & 23 deletions

File tree

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,19 @@ import android.app.Activity
1010
import android.content.Intent
1111
import android.os.Bundle
1212
import org.schabi.newpipe.util.NavigationHelper
13+
1314
class ExitActivity : Activity() {
1415
@SuppressLint("NewApi")
1516
override fun onCreate(savedInstanceState: Bundle?) {
1617
super.onCreate(savedInstanceState)
17-
1818
finishAndRemoveTask()
19-
2019
NavigationHelper.restartApp(this)
2120
}
2221

2322
companion object {
2423
@JvmStatic
2524
fun exitAndRemoveFromRecentApps(activity: Activity) {
2625
val intent = Intent(activity, ExitActivity::class.java)
27-
2826
intent.addFlags(
2927
Intent.FLAG_ACTIVITY_NEW_TASK
3028
or Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ object NewPipeTextViewHelper {
5454
selectedText: CharSequence?
5555
) {
5656
if (!selectedText.isNullOrEmpty()) {
57-
ShareUtils.shareText(textView.getContext(), "", selectedText.toString())
57+
ShareUtils.shareText(textView.context, "", selectedText.toString())
5858
}
5959
}
6060
}

app/src/main/java/org/schabi/newpipe/util/PeertubeHelper.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ import org.schabi.newpipe.extractor.ServiceList
1616
import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance
1717

1818
object PeertubeHelper {
19+
20+
@JvmStatic
21+
val currentInstance: PeertubeInstance
22+
get() = ServiceList.PeerTube.instance
23+
1924
@JvmStatic
2025
fun getInstanceList(context: Context): List<PeertubeInstance> {
2126
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
2227
val savedInstanceListKey = context.getString(R.string.peertube_instance_list_key)
2328
val savedJson = sharedPreferences.getString(savedInstanceListKey, null)
24-
if (savedJson == null) {
25-
return listOf(currentInstance)
26-
}
29+
?: return listOf(currentInstance)
2730

2831
return runCatching {
2932
JsonParser.`object`().from(savedJson).getArray("instances")
@@ -46,8 +49,4 @@ object PeertubeHelper {
4649
ServiceList.PeerTube.instance = instance
4750
return instance
4851
}
49-
50-
@JvmStatic
51-
val currentInstance: PeertubeInstance
52-
get() = ServiceList.PeerTube.instance
5352
}

app/src/main/java/org/schabi/newpipe/util/ServiceHelper.kt

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ import androidx.annotation.DrawableRes
1010
import androidx.annotation.StringRes
1111
import androidx.core.content.edit
1212
import androidx.preference.PreferenceManager
13-
import com.grack.nanojson.JsonObject
1413
import com.grack.nanojson.JsonParser
15-
import com.grack.nanojson.JsonParserException
1614
import java.util.concurrent.TimeUnit
1715
import org.schabi.newpipe.R
1816
import org.schabi.newpipe.extractor.NewPipe
1917
import org.schabi.newpipe.extractor.ServiceList
2018
import org.schabi.newpipe.extractor.StreamingService
21-
import org.schabi.newpipe.extractor.exceptions.ExtractionException
2219
import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance
2320
import org.schabi.newpipe.ktx.getStringSafe
2421

@@ -133,8 +130,8 @@ object ServiceHelper {
133130
}
134131

135132
private fun setSelectedServicePreferences(context: Context, serviceName: String?) {
136-
val sp = PreferenceManager.getDefaultSharedPreferences(context)
137-
sp.edit { putString(context.getString(R.string.current_service_key), serviceName) }
133+
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
134+
sharedPreferences.edit { putString(context.getString(R.string.current_service_key), serviceName) }
138135
}
139136

140137
@JvmStatic
@@ -152,17 +149,15 @@ object ServiceHelper {
152149
val json = sharedPreferences.getString(
153150
context.getString(R.string.peertube_selected_instance_key),
154151
null
155-
)
156-
if (null == json) {
157-
return
158-
}
152+
) ?: return
159153

160154
val jsonObject = runCatching { JsonParser.`object`().from(json) }
161155
.getOrElse { return@initService }
162156

163-
val name = jsonObject.getString("name")
164-
val url = jsonObject.getString("url")
165-
ServiceList.PeerTube.instance = PeertubeInstance(url, name)
157+
ServiceList.PeerTube.instance = PeertubeInstance(
158+
jsonObject.getString("url"),
159+
jsonObject.getString("name")
160+
)
166161
}
167162
}
168163

0 commit comments

Comments
 (0)