Optimised 'removeWatchedStreams'
Removed merge mistake Reordered code Refactored 'removeWatchedWorker' to 'removeWatchedDisposable'
This commit is contained in:
parent
98fc88dec6
commit
0ac2865b74
1 changed files with 22 additions and 16 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue