Skip to content

Commit

Permalink
Fix new detekt warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxr1998 committed Jan 26, 2025
1 parent 373fe95 commit 2e6e83e
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/java/org/jellyfin/mobile/setup/ConnectionHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")

Expand Down Expand Up @@ -62,21 +62,26 @@ 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()) {
append("\n\n")
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()
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/jellyfin/mobile/utils/SystemUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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())

Expand Down

0 comments on commit 2e6e83e

Please sign in to comment.