Skip to content

Commit

Permalink
Remove from playlist only upon selecting the option and not afterwards.
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Aug 7, 2022
1 parent dd60611 commit f9017c8
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,14 @@ public void removeWatchedStreams(final boolean removePartiallyWatched) {
showLoading();

final var recordManager = new HistoryRecordManager(getContext());
final var historyIdsFlowable = recordManager.getStreamHistorySortedById()
final var historyIdsMaybe = recordManager.getStreamHistorySortedById()
.firstElement()
// already sorted by ^ getStreamHistorySortedById(), binary search can be used
.map(historyList -> historyList.stream().map(StreamHistoryEntry::getStreamId)
.collect(Collectors.toList()));
final var streamsFlowable = playlistManager.getPlaylistStreams(playlistId)
.zipWith(historyIdsFlowable, (playlist, historyStreamIds) -> {
final var streamsMaybe = playlistManager.getPlaylistStreams(playlistId)
.firstElement()
.zipWith(historyIdsMaybe, (playlist, historyStreamIds) -> {
// Remove Watched, Functionality data
final List<PlaylistStreamEntry> notWatchedItems = new ArrayList<>();
boolean thumbnailVideoRemoved = false;
Expand All @@ -418,8 +420,8 @@ public void removeWatchedStreams(final boolean removePartiallyWatched) {
}
}
} else {
final var streamStates = recordManager.loadLocalStreamStateBatch(playlist)
.blockingGet();
final var streamStates = recordManager
.loadLocalStreamStateBatch(playlist).blockingGet();

for (int i = 0; i < playlist.size(); i++) {
final var playlistItem = playlist.get(i);
Expand All @@ -442,7 +444,8 @@ public void removeWatchedStreams(final boolean removePartiallyWatched) {

return new Pair<>(notWatchedItems, thumbnailVideoRemoved);
});
disposables.add(streamsFlowable.subscribeOn(Schedulers.io())

disposables.add(streamsMaybe.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(flow -> {
final List<PlaylistStreamEntry> notWatchedItems = flow.first;
Expand Down

0 comments on commit f9017c8

Please sign in to comment.