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 removing only fully watched videos from playlist #8259

Merged
merged 7 commits into from
May 5, 2022
Merged
Changes from 2 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 @@ -414,14 +414,21 @@ public void removeWatchedStreams(final boolean removePartiallyWatched) {
} else {
final Iterator<StreamStateEntity> streamStatesIter = recordManager
.loadLocalStreamStateBatch(playlist).blockingGet().iterator();

while (playlistIter.hasNext()) {
Stypox marked this conversation as resolved.
Show resolved Hide resolved
final PlaylistStreamEntry playlistItem = playlistIter.next();
final int indexInHistory = Collections.binarySearch(historyStreamIds,
playlistItem.getStreamId());

final boolean hasState = streamStatesIter.next() != null;
if (indexInHistory < 0 || hasState) {
final StreamStateEntity streamStateEntity = streamStatesIter.next();
final long duration = playlistItem.toStreamInfoItem().getDuration();
boolean isFinished = false;
if (streamStateEntity != null) {
isFinished = streamStateEntity.isFinished(duration);
}
final boolean isNotWatchedItem = (streamStateEntity != null
&& !isFinished);
if (indexInHistory < 0) {
notWatchedItems.add(playlistItem);
} else if (isNotWatchedItem) {
notWatchedItems.add(playlistItem);
Copy link
Member

Choose a reason for hiding this comment

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

The logic was difficult to understand, this is clearer in my opinion (also keep the newline)

Suggested change
final StreamStateEntity streamStateEntity = streamStatesIter.next();
final long duration = playlistItem.toStreamInfoItem().getDuration();
boolean isFinished = false;
if (streamStateEntity != null) {
isFinished = streamStateEntity.isFinished(duration);
}
final boolean isNotWatchedItem = (streamStateEntity != null
&& !isFinished);
if (indexInHistory < 0) {
notWatchedItems.add(playlistItem);
} else if (isNotWatchedItem) {
notWatchedItems.add(playlistItem);
final StreamStateEntity streamStateEntity = streamStatesIter.next();
final long duration = playlistItem.toStreamInfoItem().getDuration();
if (indexInHistory < 0 || (streamStateEntity != null && streamStateEntity.isFinished(duration))) {
notWatchedItems.add(playlistItem);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is indexInHistory < 0 || (streamStateEntity != null && !streamStateEntity.isFinished(duration)), there should be
a "!" before streamStateEntity.isFinished(duration)

Copy link
Member

Choose a reason for hiding this comment

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

Ooops, yes, you are right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I have modified it.

} else if (!thumbnailVideoRemoved
&& playlistManager.getPlaylistThumbnail(playlistId)
Expand Down