1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-25 09:30:32 +00:00

Optimised 'removeWatchedStreams'

Removed merge mistake
Reordered code
Refactored 'removeWatchedWorker' to 'removeWatchedDisposable'
This commit is contained in:
developer 2020-03-18 01:49:46 -05:00 committed by Stypox
parent 98fc88dec6
commit 0ac2865b74
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23

View File

@ -87,7 +87,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
private PublishSubject<Long> debouncedSaveSignal; private PublishSubject<Long> debouncedSaveSignal;
private CompositeDisposable disposables; private CompositeDisposable disposables;
private Disposable removeWatchedWorker; private Disposable removeWatchedDisposable;
/* Has the playlist been fully loaded from db */ /* Has the playlist been fully loaded from db */
private AtomicBoolean isLoadingComplete; private AtomicBoolean isLoadingComplete;
@ -300,12 +300,12 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
disposables.dispose(); disposables.dispose();
} }
if (removeWatchedWorker != null) removeWatchedWorker.dispose(); if (removeWatchedDisposable != null) removeWatchedDisposable.dispose();
removeWatchedWorker = null;
debouncedSaveSignal = null; debouncedSaveSignal = null;
playlistManager = null; playlistManager = null;
disposables = null; disposables = null;
removeWatchedDisposable = null;
isLoadingComplete = null; isLoadingComplete = null;
isModified = null; isModified = null;
@ -367,12 +367,12 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
public void removeWatchedStreams() { public void removeWatchedStreams() {
showLoading(); showLoading();
if (removeWatchedWorker != null) { if (removeWatchedDisposable != null) {
// In case this is called twice // In case this is called twice
removeWatchedWorker.dispose(); removeWatchedDisposable.dispose();
} }
removeWatchedWorker = Flowable.just(playlistManager.getPlaylistStreams(playlistId).blockingFirst()) removeWatchedDisposable = Flowable.just(playlistManager.getPlaylistStreams(playlistId).blockingFirst())
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.map((@NonNull List<PlaylistStreamEntry> playlist) -> { .map((@NonNull List<PlaylistStreamEntry> playlist) -> {
List<PlaylistStreamEntry> localItems = new ArrayList<>(); List<PlaylistStreamEntry> localItems = new ArrayList<>();
@ -380,36 +380,42 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
Long removedItemCount = 0l; Long removedItemCount = 0l;
HistoryRecordManager recordManager = new HistoryRecordManager(getContext()); HistoryRecordManager recordManager = new HistoryRecordManager(getContext());
Iterator<StreamHistoryEntry> it_history;
StreamHistoryEntry history_item;
Iterator<PlaylistStreamEntry> it_playlist = playlist.iterator(); Iterator<PlaylistStreamEntry> it_playlist = playlist.iterator();
PlaylistStreamEntry playlist_item = null; PlaylistStreamEntry playlist_item = null;
boolean isNonDuplicate; boolean isNonDuplicate;
while (it_playlist.hasNext()) { Iterator<StreamHistoryEntry> it_history = recordManager.getStreamHistory().blockingFirst().iterator();
ArrayList<Long> history_streamIds = new ArrayList<>();
while(it_history.hasNext())
{
history_streamIds.add(it_history.next().getStreamId());
}
while(it_playlist.hasNext())
{
playlist_item = it_playlist.next(); playlist_item = it_playlist.next();
it_history = recordManager.getStreamHistory().blockingFirst().iterator();
isNonDuplicate = true; isNonDuplicate = true;
while (it_history.hasNext()) {
history_item = it_history.next(); for (long history_id : history_streamIds) {
if (history_item.streamId == playlist_item.streamId) { if (history_id == playlist_item.getStreamId()) {
isNonDuplicate = false; isNonDuplicate = false;
break; break;
} }
} }
if (isNonDuplicate) { if (isNonDuplicate) {
localItems.add(playlist_item); localItems.add(playlist_item);
} else { } else {
removedItemCount++; removedItemCount++;
if (playlistManager.getPlaylistThumbnail(playlistId).equals(playlist_item.thumbnailUrl)) { if (!thumbnailVideoRemoved && playlistManager.getPlaylistThumbnail(playlistId).equals(playlist_item.getStreamEntity().getThumbnailUrl())) {
thumbnailVideoRemoved = true; thumbnailVideoRemoved = true;
} }
} }
} }
return Flowable.just(localItems, removedItemCount, thumbnailVideoRemoved); return Flowable.just(localItems, removedItemCount, thumbnailVideoRemoved);
} }
) )