From 3576e241c0f105bded995c73fd93177037aa89ac Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 3 Jun 2026 23:37:30 -0400 Subject: [PATCH] fix(android): split playPlaylistShuffled to satisfy detekt ReturnCount --- .../playlists/data/PlaylistPlayback.kt | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/android/app/src/main/java/com/fabledsword/minstrel/playlists/data/PlaylistPlayback.kt b/android/app/src/main/java/com/fabledsword/minstrel/playlists/data/PlaylistPlayback.kt index 4f920d5e..5a54aebf 100644 --- a/android/app/src/main/java/com/fabledsword/minstrel/playlists/data/PlaylistPlayback.kt +++ b/android/app/src/main/java/com/fabledsword/minstrel/playlists/data/PlaylistPlayback.kt @@ -29,25 +29,7 @@ suspend fun playPlaylistShuffled( player: PlayerController, onMessage: (String) -> Unit, ) { - val detail = try { - withTimeout(PLAYLIST_FETCH_TIMEOUT_MS) { - if (playlist.refreshable && playlist.systemVariant != null) { - repository.systemShuffle(playlist.systemVariant) - } else { - repository.refreshDetail(playlist.id) - } - } - } catch ( - @Suppress("SwallowedException") _: TimeoutCancellationException, - ) { - onMessage("Couldn't load playlist - check your connection") - return - } catch ( - @Suppress("TooGenericExceptionCaught") e: Throwable, - ) { - onMessage("Couldn't load playlist: ${ErrorCopy.fromThrowable(e)}") - return - } + val detail = fetchPlaylistDetail(playlist, repository, onMessage) ?: return val tracks = detail.tracks.toPlayableTrackRefs() if (tracks.isEmpty()) { onMessage("Mix isn't ready yet - try again in a moment") @@ -63,3 +45,27 @@ suspend fun playPlaylistShuffled( val ordered = if (playlist.isSystem) tracks.shuffled() else tracks player.setQueue(ordered, initialIndex = 0, source = source) } + +private suspend fun fetchPlaylistDetail( + playlist: PlaylistRef, + repository: PlaylistsRepository, + onMessage: (String) -> Unit, +): PlaylistDetailRef? = try { + withTimeout(PLAYLIST_FETCH_TIMEOUT_MS) { + if (playlist.refreshable && playlist.systemVariant != null) { + repository.systemShuffle(playlist.systemVariant) + } else { + repository.refreshDetail(playlist.id) + } + } +} catch ( + @Suppress("SwallowedException") _: TimeoutCancellationException, +) { + onMessage("Couldn't load playlist - check your connection") + null +} catch ( + @Suppress("TooGenericExceptionCaught") e: Throwable, +) { + onMessage("Couldn't load playlist: ${ErrorCopy.fromThrowable(e)}") + null +}