Skip to content

Commit 8c5f13a

Browse files
committed
ktlint: Fix function-signature violations
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
1 parent eb97366 commit 8c5f13a

10 files changed

Lines changed: 110 additions & 128 deletions

File tree

.editorconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ ktlint_standard_chain-method-continuation = disabled
1515
ktlint_standard_class-signature = disabled
1616
ktlint_standard_function-expression-body = disabled
1717
ktlint_standard_function-literal = disabled
18-
ktlint_standard_function-signature = disabled
1918
ktlint_standard_max-line-length = disabled
2019
ktlint_standard_mixed-condition-operators = disabled
2120
ktlint_standard_package-name = disabled

app/src/androidTest/java/org/schabi/newpipe/testUtil/TrampolineSchedulerRule.kt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,20 @@ class TrampolineSchedulerRule : TestRule {
1717

1818
private val scheduler = Schedulers.trampoline()
1919

20-
override fun apply(base: Statement, description: Description): Statement =
21-
object : Statement() {
22-
override fun evaluate() {
23-
try {
24-
RxJavaPlugins.setComputationSchedulerHandler { scheduler }
25-
RxJavaPlugins.setIoSchedulerHandler { scheduler }
26-
RxJavaPlugins.setNewThreadSchedulerHandler { scheduler }
27-
RxJavaPlugins.setSingleSchedulerHandler { scheduler }
28-
RxAndroidPlugins.setInitMainThreadSchedulerHandler { scheduler }
20+
override fun apply(base: Statement, description: Description): Statement = object : Statement() {
21+
override fun evaluate() {
22+
try {
23+
RxJavaPlugins.setComputationSchedulerHandler { scheduler }
24+
RxJavaPlugins.setIoSchedulerHandler { scheduler }
25+
RxJavaPlugins.setNewThreadSchedulerHandler { scheduler }
26+
RxJavaPlugins.setSingleSchedulerHandler { scheduler }
27+
RxAndroidPlugins.setInitMainThreadSchedulerHandler { scheduler }
2928

30-
base.evaluate()
31-
} finally {
32-
RxJavaPlugins.reset()
33-
RxAndroidPlugins.reset()
34-
}
29+
base.evaluate()
30+
} finally {
31+
RxJavaPlugins.reset()
32+
RxAndroidPlugins.reset()
3533
}
3634
}
35+
}
3736
}

app/src/androidTest/java/org/schabi/newpipe/util/StreamItemAdapterTest.kt

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -248,39 +248,37 @@ class StreamItemAdapterTest {
248248
* @return a list of video streams, in which their video only property mirrors the provided
249249
* [videoOnly] vararg.
250250
*/
251-
private fun getVideoStreams(vararg videoOnly: Boolean) =
252-
StreamItemAdapter.StreamInfoWrapper(
253-
videoOnly.map {
254-
VideoStream.Builder()
255-
.setId(Stream.ID_UNKNOWN)
256-
.setContent("https://example.com", true)
257-
.setMediaFormat(MediaFormat.MPEG_4)
258-
.setResolution("720p")
259-
.setIsVideoOnly(it)
260-
.build()
261-
},
262-
context
263-
)
251+
private fun getVideoStreams(vararg videoOnly: Boolean) = StreamInfoWrapper(
252+
videoOnly.map {
253+
VideoStream.Builder()
254+
.setId(Stream.ID_UNKNOWN)
255+
.setContent("https://example.com", true)
256+
.setMediaFormat(MediaFormat.MPEG_4)
257+
.setResolution("720p")
258+
.setIsVideoOnly(it)
259+
.build()
260+
},
261+
context
262+
)
264263

265264
/**
266265
* @return a list of audio streams, containing valid and null elements mirroring the provided
267266
* [shouldBeValid] vararg.
268267
*/
269-
private fun getAudioStreams(vararg shouldBeValid: Boolean) =
270-
getSecondaryStreamsFromList(
271-
shouldBeValid.map {
272-
if (it) {
273-
AudioStream.Builder()
274-
.setId(Stream.ID_UNKNOWN)
275-
.setContent("https://example.com", true)
276-
.setMediaFormat(MediaFormat.OPUS)
277-
.setAverageBitrate(192)
278-
.build()
279-
} else {
280-
null
281-
}
268+
private fun getAudioStreams(vararg shouldBeValid: Boolean) = getSecondaryStreamsFromList(
269+
shouldBeValid.map {
270+
if (it) {
271+
AudioStream.Builder()
272+
.setId(Stream.ID_UNKNOWN)
273+
.setContent("https://example.com", true)
274+
.setMediaFormat(MediaFormat.OPUS)
275+
.setAverageBitrate(192)
276+
.build()
277+
} else {
278+
null
282279
}
283-
)
280+
}
281+
)
284282

285283
private fun getIncompleteAudioStreams(size: Int): List<AudioStream> {
286284
val list = ArrayList<AudioStream>(size)
@@ -325,18 +323,17 @@ class StreamItemAdapterTest {
325323
/**
326324
* Helper function that builds a secondary stream list.
327325
*/
328-
private fun <T : Stream> getSecondaryStreamsFromList(streams: List<T?>) =
329-
SparseArrayCompat<SecondaryStreamHelper<T>?>(streams.size).apply {
330-
streams.forEachIndexed { index, stream ->
331-
val secondaryStreamHelper: SecondaryStreamHelper<T>? = stream?.let {
332-
SecondaryStreamHelper(
333-
StreamItemAdapter.StreamInfoWrapper(streams, context),
334-
it
335-
)
336-
}
337-
put(index, secondaryStreamHelper)
326+
private fun <T : Stream> getSecondaryStreamsFromList(streams: List<T?>) = SparseArrayCompat<SecondaryStreamHelper<T>?>(streams.size).apply {
327+
streams.forEachIndexed { index, stream ->
328+
val secondaryStreamHelper: SecondaryStreamHelper<T>? = stream?.let {
329+
SecondaryStreamHelper(
330+
StreamItemAdapter.StreamInfoWrapper(streams, context),
331+
it
332+
)
338333
}
334+
put(index, secondaryStreamHelper)
339335
}
336+
}
340337

341338
private fun getResponse(headers: Map<String, String>): Response {
342339
val listHeaders = HashMap<String, List<String>>()

app/src/main/java/org/schabi/newpipe/database/history/model/StreamHistoryEntry.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,15 @@ data class StreamHistoryEntry(
3030
accessDate.isEqual(other.accessDate)
3131
}
3232

33-
fun toStreamInfoItem(): StreamInfoItem =
34-
StreamInfoItem(
35-
streamEntity.serviceId,
36-
streamEntity.url,
37-
streamEntity.title,
38-
streamEntity.streamType
39-
).apply {
40-
duration = streamEntity.duration
41-
uploaderName = streamEntity.uploader
42-
uploaderUrl = streamEntity.uploaderUrl
43-
thumbnails = ImageStrategy.dbUrlToImageList(streamEntity.thumbnailUrl)
44-
}
33+
fun toStreamInfoItem(): StreamInfoItem = StreamInfoItem(
34+
streamEntity.serviceId,
35+
streamEntity.url,
36+
streamEntity.title,
37+
streamEntity.streamType
38+
).apply {
39+
duration = streamEntity.duration
40+
uploaderName = streamEntity.uploader
41+
uploaderUrl = streamEntity.uploaderUrl
42+
thumbnails = ImageStrategy.dbUrlToImageList(streamEntity.thumbnailUrl)
43+
}
4544
}

app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,14 @@ class ErrorInfo private constructor(
160160

161161
const val SERVICE_NONE = "<unknown_service>"
162162

163-
private fun getServiceName(serviceId: Int?) =
164-
// not using getNameOfServiceById since we want to accept a nullable serviceId and we
163+
private fun getServiceName(serviceId: Int?) = // not using getNameOfServiceById since we want to accept a nullable serviceId and we
165164
// want to default to SERVICE_NONE
166165
ServiceList.all().firstOrNull { it.serviceId == serviceId }?.serviceInfo?.name
167166
?: SERVICE_NONE
168167

169168
fun throwableToStringList(throwable: Throwable) = arrayOf(throwable.stackTraceToString())
170169

171-
fun throwableListToStringList(throwableList: List<Throwable>) =
172-
throwableList.map { it.stackTraceToString() }.toTypedArray()
170+
fun throwableListToStringList(throwableList: List<Throwable>) = throwableList.map { it.stackTraceToString() }.toTypedArray()
173171

174172
fun getMessage(
175173
throwable: Throwable?,

app/src/main/java/org/schabi/newpipe/local/feed/FeedViewModel.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,14 @@ class FeedViewModel(
151151
fun getShowFutureItemsFromPreferences() = getShowFutureItemsFromPreferences(application)
152152

153153
companion object {
154-
private fun getShowPlayedItemsFromPreferences(context: Context) =
155-
PreferenceManager.getDefaultSharedPreferences(context)
156-
.getBoolean(context.getString(R.string.feed_show_watched_items_key), true)
154+
private fun getShowPlayedItemsFromPreferences(context: Context) = PreferenceManager.getDefaultSharedPreferences(context)
155+
.getBoolean(context.getString(R.string.feed_show_watched_items_key), true)
157156

158-
private fun getShowPartiallyPlayedItemsFromPreferences(context: Context) =
159-
PreferenceManager.getDefaultSharedPreferences(context)
160-
.getBoolean(context.getString(R.string.feed_show_partially_watched_items_key), true)
157+
private fun getShowPartiallyPlayedItemsFromPreferences(context: Context) = PreferenceManager.getDefaultSharedPreferences(context)
158+
.getBoolean(context.getString(R.string.feed_show_partially_watched_items_key), true)
161159

162-
private fun getShowFutureItemsFromPreferences(context: Context) =
163-
PreferenceManager.getDefaultSharedPreferences(context)
164-
.getBoolean(context.getString(R.string.feed_show_future_items_key), true)
160+
private fun getShowFutureItemsFromPreferences(context: Context) = PreferenceManager.getDefaultSharedPreferences(context)
161+
.getBoolean(context.getString(R.string.feed_show_future_items_key), true)
165162

166163
fun getFactory(context: Context, groupId: Long) = viewModelFactory {
167164
initializer {

app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ class NotificationWorker(
9595
private val TAG = NotificationWorker::class.java.simpleName
9696
private const val WORK_TAG = App.PACKAGE_NAME + "_streams_notifications"
9797

98-
private fun areNotificationsEnabled(context: Context) =
99-
NotificationHelper.areNewStreamsNotificationsEnabled(context) &&
100-
NotificationHelper.areNotificationsEnabledOnDevice(context)
98+
private fun areNotificationsEnabled(context: Context) = NotificationHelper.areNewStreamsNotificationsEnabled(context) &&
99+
NotificationHelper.areNotificationsEnabledOnDevice(context)
101100

102101
/**
103102
* Schedules a task for the [NotificationWorker]

app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,18 @@ class SubscriptionManager(context: Context) {
7070
return listEntities
7171
}
7272

73-
fun updateChannelInfo(info: ChannelInfo): Completable =
74-
subscriptionTable.getSubscription(info.serviceId, info.url)
75-
.flatMapCompletable {
76-
Completable.fromRunnable {
77-
it.apply {
78-
name = info.name
79-
avatarUrl = ImageStrategy.imageListToDbUrl(info.avatars)
80-
description = info.description
81-
subscriberCount = info.subscriberCount
82-
}
83-
subscriptionTable.update(it)
73+
fun updateChannelInfo(info: ChannelInfo): Completable = subscriptionTable.getSubscription(info.serviceId, info.url)
74+
.flatMapCompletable {
75+
Completable.fromRunnable {
76+
it.apply {
77+
name = info.name
78+
avatarUrl = ImageStrategy.imageListToDbUrl(info.avatars)
79+
description = info.description
80+
subscriberCount = info.subscriberCount
8481
}
82+
subscriptionTable.update(it)
8583
}
84+
}
8685

8786
fun updateNotificationMode(serviceId: Int, url: String, @NotificationMode mode: Int): Completable {
8887
return subscriptionTable().getSubscription(serviceId, url)

app/src/main/java/org/schabi/newpipe/player/mediabrowser/PackageValidator.kt

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,10 @@ internal class PackageValidator(context: Context) {
173173
*/
174174
@Suppress("deprecation")
175175
@SuppressLint("PackageManagerGetSignatures")
176-
private fun getPackageInfo(callingPackage: String): PackageInfo? =
177-
packageManager.getPackageInfo(
178-
callingPackage,
179-
PackageManager.GET_SIGNATURES or PackageManager.GET_PERMISSIONS
180-
)
176+
private fun getPackageInfo(callingPackage: String): PackageInfo? = packageManager.getPackageInfo(
177+
callingPackage,
178+
PackageManager.GET_SIGNATURES or PackageManager.GET_PERMISSIONS
179+
)
181180

182181
/**
183182
* Gets the signature of a given package's [PackageInfo].
@@ -189,23 +188,21 @@ internal class PackageValidator(context: Context) {
189188
* returns `null` as the signature.
190189
*/
191190
@Suppress("deprecation")
192-
private fun getSignature(packageInfo: PackageInfo): String? =
193-
if (packageInfo.signatures == null || packageInfo.signatures!!.size != 1) {
194-
// Security best practices dictate that an app should be signed with exactly one (1)
195-
// signature. Because of this, if there are multiple signatures, reject it.
196-
null
197-
} else {
198-
val certificate = packageInfo.signatures!![0].toByteArray()
199-
getSignatureSha256(certificate)
200-
}
191+
private fun getSignature(packageInfo: PackageInfo): String? = if (packageInfo.signatures == null || packageInfo.signatures!!.size != 1) {
192+
// Security best practices dictate that an app should be signed with exactly one (1)
193+
// signature. Because of this, if there are multiple signatures, reject it.
194+
null
195+
} else {
196+
val certificate = packageInfo.signatures!![0].toByteArray()
197+
getSignatureSha256(certificate)
198+
}
201199

202200
/**
203201
* Finds the Android platform signing key signature. This key is never null.
204202
*/
205-
private fun getSystemSignature(): String =
206-
getPackageInfo(ANDROID_PLATFORM)?.let { platformInfo ->
207-
getSignature(platformInfo)
208-
} ?: throw IllegalStateException("Platform signature not found")
203+
private fun getSystemSignature(): String = getPackageInfo(ANDROID_PLATFORM)?.let { platformInfo ->
204+
getSignature(platformInfo)
205+
} ?: throw IllegalStateException("Platform signature not found")
209206

210207
/**
211208
* Creates a SHA-256 signature given a certificate byte array.

app/src/main/java/org/schabi/newpipe/util/potoken/PoTokenWebView.kt

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,15 @@ class PoTokenWebView private constructor(
179179
//endregion
180180

181181
//region Obtaining poTokens
182-
override fun generatePoToken(identifier: String): Single<String> =
183-
Single.create { emitter ->
184-
if (BuildConfig.DEBUG) {
185-
Log.d(TAG, "generatePoToken() called with identifier $identifier")
186-
}
187-
runOnMainThread(emitter) {
188-
addPoTokenEmitter(identifier, emitter)
189-
val u8Identifier = stringToU8(identifier)
190-
webView.evaluateJavascript(
191-
"""try {
182+
override fun generatePoToken(identifier: String): Single<String> = Single.create { emitter ->
183+
if (BuildConfig.DEBUG) {
184+
Log.d(TAG, "generatePoToken() called with identifier $identifier")
185+
}
186+
runOnMainThread(emitter) {
187+
addPoTokenEmitter(identifier, emitter)
188+
val u8Identifier = stringToU8(identifier)
189+
webView.evaluateJavascript(
190+
"""try {
192191
identifier = "$identifier"
193192
u8Identifier = $u8Identifier
194193
poTokenU8 = obtainPoToken(webPoSignalOutput, integrityToken, u8Identifier)
@@ -201,9 +200,9 @@ class PoTokenWebView private constructor(
201200
} catch (error) {
202201
$JS_INTERFACE.onObtainPoTokenError(identifier, error + "\n" + error.stack)
203202
}"""
204-
) {}
205-
}
203+
) {}
206204
}
205+
}
207206

208207
/**
209208
* Called by the JavaScript snippet from [generatePoToken] when an error occurs in calling the
@@ -373,14 +372,13 @@ class PoTokenWebView private constructor(
373372
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.3"
374373
private const val JS_INTERFACE = "PoTokenWebView"
375374

376-
override fun newPoTokenGenerator(context: Context): Single<PoTokenGenerator> =
377-
Single.create { emitter ->
378-
runOnMainThread(emitter) {
379-
val potWv = PoTokenWebView(context, emitter)
380-
potWv.loadHtmlAndObtainBotguard(context)
381-
emitter.setDisposable(potWv.disposables)
382-
}
375+
override fun newPoTokenGenerator(context: Context): Single<PoTokenGenerator> = Single.create { emitter ->
376+
runOnMainThread(emitter) {
377+
val potWv = PoTokenWebView(context, emitter)
378+
potWv.loadHtmlAndObtainBotguard(context)
379+
emitter.setDisposable(potWv.disposables)
383380
}
381+
}
384382

385383
/**
386384
* Runs [runnable] on the main thread using `Handler(Looper.getMainLooper()).post()`, and

0 commit comments

Comments
 (0)