Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UI audio queue order when shuffling #4322

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.jellyfin.sdk.api.client.ApiClient
import org.jellyfin.sdk.model.api.BaseItemDto
import org.jellyfin.sdk.model.api.MediaType
import kotlin.math.max

@Suppress("TooManyFunctions")
class RewriteMediaManager(
Expand Down Expand Up @@ -136,25 +135,23 @@
}.launchIn(this)

playbackManager.queue.entry.onEach { updateAdapter() }.launchIn(this)
playbackManager.state.playbackOrder.onEach { updateAdapter() }.launchIn(this)
}

private fun updateAdapter() {
// Get all items as BaseRowItem
val items = queueSupplier
.items
// Map to audio queue items
.mapIndexed { index, item ->
AudioQueueBaseRowItem(item).apply {
playing = playbackManager.queue.entryIndex.value == index
}
}
// Remove items before currently playing item
.drop(max(0, playbackManager.queue.entryIndex.value))
val currentItem = playbackManager.queue.entry.value?.baseItem?.let(::AudioQueueBaseRowItem)?.apply {
playing = true
}
// It's safe to run this blocking as all items are prefetched via the [BaseItemQueueSupplier]
val upcomingItems = runBlocking { playbackManager.queue.peekNext(100) }

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
.mapIndexedNotNull { index, item -> item.baseItem?.let(::AudioQueueBaseRowItem) }

val items = listOfNotNull(currentItem) + upcomingItems

// Update item row
currentAudioQueue.replaceAll(
items,
areItemsTheSame = { old, new -> (old as? AudioQueueBaseRowItem)?.baseItem == (new as? AudioQueueBaseRowItem)?.baseItem },
areItemsTheSame = { old, new -> (old as? AudioQueueBaseRowItem)?.baseItem?.id == (new as? AudioQueueBaseRowItem)?.baseItem?.id },
// The equals functions for BaseRowItem only compare by id
areContentsTheSame = { _, _ -> false },
)
Expand Down
Loading