Remove from playlist only upon selecting the option and not afterwards.

This commit is contained in:
Isira Seneviratne 2022-08-07 13:40:10 +05:30
parent f9443f7421
commit 6399e39507
1 changed files with 9 additions and 6 deletions

View File

@ -394,12 +394,14 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
showLoading(); showLoading();
final var recordManager = new HistoryRecordManager(getContext()); 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 // already sorted by ^ getStreamHistorySortedById(), binary search can be used
.map(historyList -> historyList.stream().map(StreamHistoryEntry::getStreamId) .map(historyList -> historyList.stream().map(StreamHistoryEntry::getStreamId)
.collect(Collectors.toList())); .collect(Collectors.toList()));
final var streamsFlowable = playlistManager.getPlaylistStreams(playlistId) final var streamsMaybe = playlistManager.getPlaylistStreams(playlistId)
.zipWith(historyIdsFlowable, (playlist, historyStreamIds) -> { .firstElement()
.zipWith(historyIdsMaybe, (playlist, historyStreamIds) -> {
// Remove Watched, Functionality data // Remove Watched, Functionality data
final List<PlaylistStreamEntry> notWatchedItems = new ArrayList<>(); final List<PlaylistStreamEntry> notWatchedItems = new ArrayList<>();
boolean thumbnailVideoRemoved = false; boolean thumbnailVideoRemoved = false;
@ -418,8 +420,8 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
} }
} }
} else { } else {
final var streamStates = recordManager.loadLocalStreamStateBatch(playlist) final var streamStates = recordManager
.blockingGet(); .loadLocalStreamStateBatch(playlist).blockingGet();
for (int i = 0; i < playlist.size(); i++) { for (int i = 0; i < playlist.size(); i++) {
final var playlistItem = playlist.get(i); final var playlistItem = playlist.get(i);
@ -442,7 +444,8 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
return new Pair<>(notWatchedItems, thumbnailVideoRemoved); return new Pair<>(notWatchedItems, thumbnailVideoRemoved);
}); });
disposables.add(streamsFlowable.subscribeOn(Schedulers.io())
disposables.add(streamsMaybe.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(flow -> { .subscribe(flow -> {
final List<PlaylistStreamEntry> notWatchedItems = flow.first; final List<PlaylistStreamEntry> notWatchedItems = flow.first;