fix(android): LikeMediaCallback ReturnCount — extract toggle helper
android / Build + lint + test (push) Failing after 2m51s
android / Build + lint + test (push) Failing after 2m51s
detekt: onCustomCommand had 3 returns (unsupported / no-mediaItem / success), ReturnCount cap is 2. Pull the toggle path into a private launchToggleForCurrent helper so onCustomCommand is a single return (if/else picks the result code, one Future wrap) and the helper has at most 2 returns.
This commit is contained in:
@@ -52,16 +52,22 @@ class LikeMediaCallback(
|
||||
customCommand: SessionCommand,
|
||||
args: Bundle,
|
||||
): ListenableFuture<SessionResult> {
|
||||
if (customCommand.customAction != CMD_TOGGLE_LIKE) {
|
||||
return Futures.immediateFuture(SessionResult(SessionResult.RESULT_ERROR_NOT_SUPPORTED))
|
||||
val code = if (customCommand.customAction == CMD_TOGGLE_LIKE) {
|
||||
launchToggleForCurrent(session)
|
||||
} else {
|
||||
SessionResult.RESULT_ERROR_NOT_SUPPORTED
|
||||
}
|
||||
return Futures.immediateFuture(SessionResult(code))
|
||||
}
|
||||
|
||||
private fun launchToggleForCurrent(session: MediaSession): Int {
|
||||
val mediaId = session.player.currentMediaItem?.mediaId
|
||||
?: return Futures.immediateFuture(SessionResult(SessionResult.RESULT_INFO_SKIPPED))
|
||||
?: return SessionResult.RESULT_INFO_SKIPPED
|
||||
scope.launch {
|
||||
val current = likes.observeIsLiked(ENTITY_TRACK, mediaId).first()
|
||||
likes.toggleLike(ENTITY_TRACK, mediaId, !current)
|
||||
}
|
||||
return Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
|
||||
return SessionResult.RESULT_SUCCESS
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
Reference in New Issue
Block a user