Skip to content

Fix/shuffle queue anchored algorithm#1036

Merged
theovilardo merged 3 commits intomasterfrom
fix/shuffle-queue-anchored-algorithm
Feb 11, 2026
Merged

Fix/shuffle queue anchored algorithm#1036
theovilardo merged 3 commits intomasterfrom
fix/shuffle-queue-anchored-algorithm

Conversation

@theovilardo
Copy link
Copy Markdown
Owner

No description provided.

This commit introduces a suspendable shuffle implementation to prevent UI freezes when shuffling very large music queues (e.g., 10,000+ songs). The work is offloaded to the `Default` dispatcher to keep the main thread responsive.

- **Coroutine-based Shuffle:**
    - Adds `QueueUtils.buildAnchoredShuffleQueueSuspending`, a new cooperative shuffling function that `yield()`s periodically during its operation. This prevents blocking the calling coroutine for too long.
    - Moves heavy shuffle computations in `PlayerViewModel` and `PlaybackStateHolder` to a background thread using `withContext(Dispatchers.Default)`.

- **Shuffle Logic Refinements:**
    - Adjusts the logic in `PlaybackStateHolder` to correctly identify the currently playing song's ID and index to anchor it properly during shuffling.
    - Ensures that playback is resumed if it was active before the shuffle operation, as replacing the queue can sometimes pause the player.
    - Lowers the `SHUFFLE_YIELD_BATCH` size for more frequent yielding, improving cooperativeness.

- **Testing:**
    - Adds `QueueUtilsTest` to validate the new suspendable shuffle logic, ensuring it handles large lists without losing items and yields correctly to allow sibling coroutines to run.
    - Adds new testing dependencies (`JUnit 5`, `MockK`, `Turbine`, `Truth`) to the Gradle configuration and enables `useJUnitPlatform()` for unit tests.
    - Comments out existing, outdated test files (`MusicDaoTest`, `MusicRepositoryImplTest`, `PlayerViewModelTest`) that are being replaced by the new testing infrastructure.
- Remove deprecated implementation plans for Beta 5.1 and 5.2.
- Delete local optimization reports and performance analysis documents.
- Remove architectural analysis of `PlayerViewModel`.
- Delete detailed scan logic implementation and verification guides.
- **UI Components**:
    - Replace `AbsoluteSmoothCornerShape` with standard `RoundedCornerShape` in `EnhancedSongListItem` and `QueueBottomSheet` for item and album containers.
    - Comment out legacy smooth corner shape implementations.
    - Temporarily disable explicit shape application on the queue surface.

- **Interaction**:
    - Update `SwipeToDismissBoxState` positional threshold from 0.28f to 0.18f in the queue list for more sensitive dismissal triggers.
@theovilardo theovilardo merged commit 3447dce into master Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant