Skip to content

Conversation

@geekygecko
Copy link
Member

Description

There's an issue when rearranging the Up Next list and the Up Next sync that happens every five seconds. At the moment, while you are dragging, the sync can happen in the background, causing the UI to update incorrectly.

Fixes https://linear.app/a8c/issue/PCDROID-375/dragging-up-next-and-syncing-at-the-same-time

Testing Instructions

  1. Add lots to your Up Next
  2. Go to the Up Next page
  3. Drag and drop an episode
  4. Filter the logs by UpNextSync to see when the Up Next sync happens
  5. When it starts, drag and drop another episode
  6. ✅ Check that there are no background sync jobs running until the end

Screencast

After

Up.Next.Drag.After.mov

Before

Up.Next.Drag.Before.mov

Checklist

  • If this is a user-facing change, I have added an entry in CHANGELOG.md
  • Ensure the linter passes (./gradlew spotlessApply to automatically apply formatting/linting)
  • I have considered whether it makes sense to add tests for my changes
  • All strings that need to be localized are in modules/services/localization/src/main/res/values/strings.xml
  • Any jetpack compose components I added or changed are covered by compose previews
  • I have updated (or requested that someone edit) the spreadsheet to reflect any new or changed analytics.

I have tested any UI changes...

  • with different themes
  • with a landscape orientation
  • with the device set to have a large display and font size
  • for accessibility with TalkBack

@geekygecko geekygecko added this to the 8.3 milestone Dec 17, 2025
Copilot AI review requested due to automatic review settings December 17, 2025 09:00
@geekygecko geekygecko added [Type] Bug Not functioning as intended. [Area] Up Next Bug labels Dec 17, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a race condition where Up Next list rearrangement could be interrupted by background sync operations that occur every 5 seconds. The solution introduces user interaction tracking to skip sync operations during and shortly after user interactions like dragging to rearrange episodes.

Key Changes:

  • Migrated from RxJava to Kotlin Coroutines/Flow for Up Next sync scheduling
  • Added user interaction tracking with a 10-second grace period to prevent sync during drag operations
  • Converted blocking database operations to suspend functions for better coroutine integration

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
UpNextChangeDao.kt Converted findAllBlocking() to suspend findAll() function
UpNextSyncWorker.kt Updated to use the new suspend findAll() function
UpNextQueue.kt Added recordUpNextUserInteraction() interface method
UpNextQueueImpl.kt Migrated RxJava sync scheduling to Coroutines Flow; added user interaction tracking and 10-second grace period logic
PlaybackManager.kt Added pass-through method to record user interactions
PlayerViewModel.kt Added method to record user interactions from UI layer
UpNextFragment.kt Calls recordUpNextUserInteraction() on episode drag to prevent sync conflicts

Comment on lines 423 to 431
fun recentUserInteraction(): Boolean {
val now = System.currentTimeMillis()
val timeSinceInteraction = (now - lastUserInteractionTime).milliseconds
val recentInteraction = timeSinceInteraction < INTERACTION_GRACE_PERIOD
if (recentInteraction) {
Timber.i("Skipping sync - user interacted ${timeSinceInteraction.inWholeSeconds} secs ago")
}
return recentInteraction
}
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new user interaction tracking behavior lacks test coverage. Consider adding tests to verify that the sync is properly skipped during the grace period after user interaction and that the sync resumes after the grace period expires. This would help ensure the fix works correctly and prevent regressions.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added some tests.

@CookieyedCodes
Copy link

Their is also a bug where if you move episodes when stuff is being added to upnext, the new episodes won't be added if you end up moving a episode before they are added to upnext, something I've just noticed over the years

@geekygecko
Copy link
Member Author

@CookieyedCodes thanks for letting me know. I'm trying to address Up Next issues. Would the episodes be added by features like "Auto add to Up Next"? I have to figure out how to repeat the issue to make sure I can fix it properly.

@CookieyedCodes
Copy link

CookieyedCodes commented Dec 17, 2025

Yup it would be using auto add to upnext, this is certainly more relatable then my other issue

@geekygecko geekygecko marked this pull request as ready for review December 17, 2025 11:33
@geekygecko geekygecko requested a review from a team as a code owner December 17, 2025 11:33
@geekygecko geekygecko requested review from Copilot and sztomek and removed request for a team December 17, 2025 11:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Area] Up Next Bug [Type] Bug Not functioning as intended.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants