Repository navigation
Restrict duplicate video additions and implement DiffUtil to prevent list flickering and crashes during playlist pagination - #13977
Closed
Ayush32-ai wants to merge 3 commits into
Closed
Ayush32-ai wants to merge 3 commits into
Ayush32-ai wants to merge 3 commits into
Conversation
Contributor
|
Please link this PR to an existing issue you are assigned to. Assignees are expected to discuss the details of the PR beforehand. This PR will be closed if it is not linked to an issue. |
Member
|
Thank you for the PR. Please use our PR template, fill in the required information and ensure that your PR follows our contribution and AI guidelines. |
Author
What is it?
Description of the changes in your PRThis PR fixes duplicate videos being added to local playlists and improves how playlist items are updated.
Before/After Screenshots/Screen Record
Fixes the following issue(s)Relies on the following changes
Testing/QADevices
Steps for testing
APK for testingThe debug APK is available under the Checks tab of the PR, in the CI artifacts. Due diligence
|
|
Author
|
@TobiGr Please check the code and pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Preventing Duplicate Videos and Code Changes
To resolve the issue of duplicate videos being added to local playlists, I implemented strict duplicate addition restrictions in both the user interface and the database manager. In PlaylistAppendDialog.java, the onPlaylistSelected() method was modified to check playlist.getTimesStreamIsContained(); if the video already exists in the selected playlist, the append action is blocked immediately and a Toast notification (playlist_add_stream_duplicate_forbidden) informs the user that the video is already in the playlist. To handle edge cases where the same video is added with different start-time parameters (such as ?t=30s, &start=15, or #t=1m), I added a cleanTimingFromUrl() utility function in LocalPlaylistManager.kt that uses regular expressions to strip timing query parameters and hash fragments, reducing URLs to their canonical video identifiers. Updates to getPlaylistDuplicates() and appendToPlaylist() in LocalPlaylistManager.kt ensure that incoming streams are cleaned and filtered against existing playlist entries before database transactions, guaranteeing that duplicate videos cannot be inserted even with varied timestamp parameters. I validated this URL cleaning logic through unit tests in LocalPlaylistManagerDuplicateTest.kt and updated strings.xml with the new duplicate warning string.
DiffUtil Implementation, Created Files, and Crash Handling
To eliminate list flickering, UI stutter, and index-out-of-bounds crashes during playlist loading and pagination, I refactored the rendering logic in PlaylistFragment.java and LocalPlaylistFragment.java to fully adopt DiffUtil. Previously, every dataset update or pull-to-refresh cleared the adapter using clearStreamItemList() and invoked notifyDataSetChanged(), causing visual glitches and scroll position resets. By overriding startLoading, handleResult, and handleNextItems, data updates now run through infoListAdapter.updateItemsWithDiff() and itemListAdapter.updateItemsWithDiff(), smoothly inserting paginated items via targeted notifyItemRangeInserted() calls. To support this, I created InfoItemDiffCallback.kt and LocalItemDiffCallback.kt along with a comprehensive unit test suite in InfoItemDiffCallbackTest.kt. Furthermore, to prevent crashes caused by duplicate streams in the same playlist, I engineered precomputed occurrence indexing (oldOccurrenceIndices and newOccurrenceIndices) in InfoItemDiffCallback.kt. This ensures Myers’ diff algorithm identifies each stream by its sequence position rather than cross-matching identical URLs, completely avoiding spurious move operations, visual duplication, and array out-of-bounds exceptions when rendering large or paginated playlists.