From 1500565f6456ca10b8f67f566f33923e88b2c479 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 27 Jan 2025 01:06:17 +0100 Subject: [PATCH] Update detekt to v1.23.7 (#1094) * Update detekt to v1.23.7 * Fix detekt config deprecation * Update ForbiddenComment detekt rule configuration * Fix new detekt warnings --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Maxr1998 --- .editorconfig | 2 ++ app/build.gradle.kts | 2 +- .../jellyfin/mobile/player/TrackSelectionHelper.kt | 12 ++++++++++-- .../jellyfin/mobile/player/audio/MediaService.kt | 3 ++- .../player/deviceprofile/DeviceProfileBuilder.kt | 4 +++- .../org/jellyfin/mobile/setup/ConnectionHelper.kt | 13 +++++++++---- .../java/org/jellyfin/mobile/utils/SystemUtils.kt | 4 ++-- .../mobile/webapp/JellyfinWebViewClient.kt | 14 +++++++++++--- .../jellyfin/mobile/webapp/RemotePlayerService.kt | 10 ++++++---- detekt.yml | 2 +- gradle/libs.versions.toml | 2 +- 11 files changed, 48 insertions(+), 20 deletions(-) diff --git a/.editorconfig b/.editorconfig index 105c76b65..cf5339b57 100644 --- a/.editorconfig +++ b/.editorconfig @@ -17,7 +17,9 @@ trim_trailing_whitespace = true ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL ij_kotlin_allow_trailing_comma = true ij_kotlin_allow_trailing_comma_on_call_site = true +ij_kotlin_blank_lines_around_block_when_branches = 0 ij_kotlin_line_break_after_multiline_when_entry = false +ij_kotlin_indent_before_arrow_on_new_line = false ij_kotlin_name_count_to_use_star_import = 999 ij_kotlin_name_count_to_use_star_import_for_members = 999 ij_kotlin_packages_to_use_import_on_demand = diff --git a/app/build.gradle.kts b/app/build.gradle.kts index cc5b5896a..55542b0b3 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -15,7 +15,7 @@ plugins { detekt { buildUponDefaultConfig = true allRules = false - config = files("${rootProject.projectDir}/detekt.yml") + config.setFrom("${rootProject.projectDir}/detekt.yml") autoCorrect = true } diff --git a/app/src/main/java/org/jellyfin/mobile/player/TrackSelectionHelper.kt b/app/src/main/java/org/jellyfin/mobile/player/TrackSelectionHelper.kt index cd4d2c923..11e5be847 100644 --- a/app/src/main/java/org/jellyfin/mobile/player/TrackSelectionHelper.kt +++ b/app/src/main/java/org/jellyfin/mobile/player/TrackSelectionHelper.kt @@ -55,7 +55,11 @@ class TrackSelectionHelper( * @see selectPlayerAudioTrack */ @Suppress("ReturnCount") - private fun selectPlayerAudioTrack(mediaSource: JellyfinMediaSource, audioStream: MediaStream, initial: Boolean): Boolean { + private fun selectPlayerAudioTrack( + mediaSource: JellyfinMediaSource, + audioStream: MediaStream, + initial: Boolean, + ): Boolean { if (mediaSource.playMethod == PlayMethod.TRANSCODE) { // Transcoding does not require explicit audio selection return true @@ -113,7 +117,11 @@ class TrackSelectionHelper( * @see selectSubtitleTrack */ @Suppress("ReturnCount") - private fun selectSubtitleTrack(mediaSource: JellyfinMediaSource, subtitleStream: MediaStream?, initial: Boolean): Boolean { + private fun selectSubtitleTrack( + mediaSource: JellyfinMediaSource, + subtitleStream: MediaStream?, + initial: Boolean, + ): Boolean { when { // Fast-pass: Skip execution on subsequent calls with the same selection !initial && subtitleStream === mediaSource.selectedSubtitleStream -> return true diff --git a/app/src/main/java/org/jellyfin/mobile/player/audio/MediaService.kt b/app/src/main/java/org/jellyfin/mobile/player/audio/MediaService.kt index 98401c2ef..cf8361cfb 100644 --- a/app/src/main/java/org/jellyfin/mobile/player/audio/MediaService.kt +++ b/app/src/main/java/org/jellyfin/mobile/player/audio/MediaService.kt @@ -102,7 +102,8 @@ class MediaService : MediaBrowserServiceCompat() { apiClientController.loadSavedServerUser() } - val sessionActivityPendingIntent = packageManager?.getLaunchIntentForPackage(packageName)?.let { sessionIntent -> + val packageLaunchIntent = packageManager?.getLaunchIntentForPackage(packageName) + val sessionActivityPendingIntent = packageLaunchIntent?.let { sessionIntent -> PendingIntent.getActivity(this, 0, sessionIntent, Constants.PENDING_INTENT_FLAGS) } diff --git a/app/src/main/java/org/jellyfin/mobile/player/deviceprofile/DeviceProfileBuilder.kt b/app/src/main/java/org/jellyfin/mobile/player/deviceprofile/DeviceProfileBuilder.kt index 3d911a570..7a3f390d0 100644 --- a/app/src/main/java/org/jellyfin/mobile/player/deviceprofile/DeviceProfileBuilder.kt +++ b/app/src/main/java/org/jellyfin/mobile/player/deviceprofile/DeviceProfileBuilder.kt @@ -277,7 +277,9 @@ class DeviceProfileBuilder( private val EXO_EMBEDDED_SUBTITLES = arrayOf("dvbsub", "pgssub", "srt", "subrip", "ttml") private val EXO_EXTERNAL_SUBTITLES = arrayOf("srt", "subrip", "ttml", "vtt", "webvtt") private val SUBTITLES_SSA = arrayOf("ssa", "ass") - private val EXTERNAL_PLAYER_SUBTITLES = arrayOf("ass", "dvbsub", "pgssub", "srt", "srt", "ssa", "subrip", "subrip", "ttml", "ttml", "vtt", "webvtt") + private val EXTERNAL_PLAYER_SUBTITLES = arrayOf( + "ass", "dvbsub", "pgssub", "srt", "srt", "ssa", "subrip", "subrip", "ttml", "ttml", "vtt", "webvtt", + ) /** * Taken from Jellyfin Web: diff --git a/app/src/main/java/org/jellyfin/mobile/setup/ConnectionHelper.kt b/app/src/main/java/org/jellyfin/mobile/setup/ConnectionHelper.kt index 77a74b0f3..6ffb57b7d 100644 --- a/app/src/main/java/org/jellyfin/mobile/setup/ConnectionHelper.kt +++ b/app/src/main/java/org/jellyfin/mobile/setup/ConnectionHelper.kt @@ -3,7 +3,6 @@ package org.jellyfin.mobile.setup import android.content.Context import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.flowOn import org.jellyfin.mobile.R import org.jellyfin.mobile.ui.state.CheckUrlState @@ -18,6 +17,7 @@ class ConnectionHelper( private val context: Context, private val jellyfin: Jellyfin, ) { + @Suppress("LongMethod") suspend fun checkServerUrl(enteredUrl: String): CheckUrlState { Timber.i("checkServerUrlAndConnection $enteredUrl") @@ -62,13 +62,16 @@ class ConnectionHelper( val count = badServers.size val (unreachableServers, incompatibleServers) = badServers.partition { result -> result.systemInfo.getOrNull() == null } - StringBuilder(context.resources.getQuantityString(R.plurals.connection_error_prefix, count, count)).apply { + StringBuilder().apply { + append(context.resources.getQuantityString(R.plurals.connection_error_prefix, count, count)) if (unreachableServers.isNotEmpty()) { append("\n\n") append(context.getString(R.string.connection_error_unable_to_reach_sever)) append(":\n") append( - unreachableServers.joinToString(separator = "\n") { result -> "\u00b7 ${result.address}" }, + unreachableServers.joinToString(separator = "\n") { result -> + "\u00b7 ${result.address}" + }, ) } if (incompatibleServers.isNotEmpty()) { @@ -76,7 +79,9 @@ class ConnectionHelper( append(context.getString(R.string.connection_error_unsupported_version_or_product)) append(":\n") append( - incompatibleServers.joinToString(separator = "\n") { result -> "\u00b7 ${result.address}" }, + incompatibleServers.joinToString(separator = "\n") { result -> + "\u00b7 ${result.address}" + }, ) } }.toString() diff --git a/app/src/main/java/org/jellyfin/mobile/utils/SystemUtils.kt b/app/src/main/java/org/jellyfin/mobile/utils/SystemUtils.kt index ee450d47a..d577f98e5 100644 --- a/app/src/main/java/org/jellyfin/mobile/utils/SystemUtils.kt +++ b/app/src/main/java/org/jellyfin/mobile/utils/SystemUtils.kt @@ -33,6 +33,7 @@ import timber.log.Timber import java.io.File import kotlin.coroutines.resume import kotlin.coroutines.suspendCoroutine +import kotlin.time.Duration.Companion.minutes fun WebViewFragment.requestNoBatteryOptimizations(rootView: CoordinatorLayout) { if (AndroidVersion.isAtLeastM) { @@ -64,8 +65,7 @@ suspend fun MainActivity.requestDownload(uri: Uri, title: String, filename: Stri // Storage permission for downloads isn't necessary from Android 10 onwards if (!AndroidVersion.isAtLeastQ) { - @Suppress("MagicNumber") - val granted = withTimeout(2 * 60 * 1000 /* 2 minutes */) { + val granted = withTimeout(2.minutes.inWholeMilliseconds) { suspendCoroutine { continuation -> requestPermission(WRITE_EXTERNAL_STORAGE) { requestPermissionsResult -> continuation.resume(requestPermissionsResult[WRITE_EXTERNAL_STORAGE] == PERMISSION_GRANTED) diff --git a/app/src/main/java/org/jellyfin/mobile/webapp/JellyfinWebViewClient.kt b/app/src/main/java/org/jellyfin/mobile/webapp/JellyfinWebViewClient.kt index 1cea01d46..9d5512aea 100644 --- a/app/src/main/java/org/jellyfin/mobile/webapp/JellyfinWebViewClient.kt +++ b/app/src/main/java/org/jellyfin/mobile/webapp/JellyfinWebViewClient.kt @@ -52,7 +52,9 @@ abstract class JellyfinWebViewClient( path.endsWith(Constants.SESSION_CAPABILITIES_PATH) -> { coroutineScope.launch { val credentials = suspendCoroutine { continuation -> - webView.evaluateJavascript("JSON.parse(window.localStorage.getItem('jellyfin_credentials'))") { result -> + webView.evaluateJavascript( + "JSON.parse(window.localStorage.getItem('jellyfin_credentials'))", + ) { result -> try { continuation.resume(JSONObject(result)) } catch (e: JSONException) { @@ -90,8 +92,14 @@ abstract class JellyfinWebViewClient( request: WebResourceRequest, error: WebResourceErrorCompat, ) { - val description = if (WebViewFeature.isFeatureSupported(WebViewFeature.WEB_RESOURCE_ERROR_GET_DESCRIPTION)) error.description else null - val errorCode = if (WebViewFeature.isFeatureSupported(WebViewFeature.WEB_RESOURCE_ERROR_GET_CODE)) error.errorCode else ERROR_UNKNOWN + val description = when { + WebViewFeature.isFeatureSupported(WebViewFeature.WEB_RESOURCE_ERROR_GET_DESCRIPTION) -> error.description + else -> null + } + val errorCode = when { + WebViewFeature.isFeatureSupported(WebViewFeature.WEB_RESOURCE_ERROR_GET_CODE) -> error.errorCode + else -> ERROR_UNKNOWN + } Timber.e("Received WebView error %d at %s: %s", errorCode, request.url.toString(), description) // Abort on some specific error codes or when the request url matches the server url diff --git a/app/src/main/java/org/jellyfin/mobile/webapp/RemotePlayerService.kt b/app/src/main/java/org/jellyfin/mobile/webapp/RemotePlayerService.kt index f156aee82..0e8002dcb 100644 --- a/app/src/main/java/org/jellyfin/mobile/webapp/RemotePlayerService.kt +++ b/app/src/main/java/org/jellyfin/mobile/webapp/RemotePlayerService.kt @@ -64,6 +64,7 @@ import org.jellyfin.mobile.utils.createMediaNotificationChannel import org.jellyfin.mobile.utils.setPlaybackState import org.koin.android.ext.android.inject import kotlin.coroutines.CoroutineContext +import kotlin.time.Duration.Companion.hours class RemotePlayerService : Service(), CoroutineScope { @@ -157,8 +158,7 @@ class RemotePlayerService : Service(), CoroutineScope { private fun startWakelock() { if (!wakeLock.isHeld) { - @Suppress("MagicNumber") - wakeLock.acquire(4 * 60 * 60 * 1000L /* 4 hours */) + wakeLock.acquire(4.hours.inWholeMilliseconds) } } @@ -277,8 +277,10 @@ class RemotePlayerService : Service(), CoroutineScope { } } setStyle(style) - setVisibility(Notification.VISIBILITY_PUBLIC) // Privacy value for lock screen - setOngoing(!isPaused && !appPreferences.musicNotificationAlwaysDismissible) // Swipe to dismiss if paused + // Privacy value for lock screen + setVisibility(Notification.VISIBILITY_PUBLIC) + // Swipe to dismiss if paused + setOngoing(!isPaused && !appPreferences.musicNotificationAlwaysDismissible) setDeleteIntent(createDeleteIntent()) setContentIntent(createContentIntent()) diff --git a/detekt.yml b/detekt.yml index 11619b840..88cc98631 100644 --- a/detekt.yml +++ b/detekt.yml @@ -52,7 +52,7 @@ performance: style: ForbiddenComment: # Allow TODOs - values: [ 'FIXME:', 'STOPSHIP:' ] + comments: [ 'FIXME:', 'STOPSHIP:' ] LoopWithTooManyJumpStatements: maxJumpCount: 2 MaxLineLength: diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 912c11568..db3500ab8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ android-plugin = "8.8.0" kotlin = "2.1.0" kotlin-ksp = "2.1.0-1.0.29" -detekt = "1.22.0" +detekt = "1.23.7" android-junit5 = "1.11.3.0" # KotlinX