diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index 315056f6c..8813f7d35 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -300,7 +300,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment playlist) -> { - remover.doInBackground(playlist); - return true; - } - ).observeOn(AndroidSchedulers.mainThread()) - .subscribe(playlist -> { - remover.onPostExecute(); - }, (@io.reactivex.annotations.NonNull Throwable throwable) -> { - onError(throwable); - }); + removeWatchedStreams(); break; default: return super.onOptionsItemSelected(item); @@ -378,6 +364,82 @@ public class LocalPlaylistFragment extends BaseLocalListFragment playlist) -> { + List localItems = new ArrayList<>(); + boolean thumbnailVideoRemoved = false; + Long removedItemCount = 0l; + + HistoryRecordManager recordManager = new HistoryRecordManager(getContext()); + Iterator it_history; + StreamHistoryEntry history_item; + + Iterator it_playlist = playlist.iterator(); + PlaylistStreamEntry playlist_item = null; + + boolean isNonDuplicate; + + while (it_playlist.hasNext()) { + playlist_item = it_playlist.next(); + + it_history = recordManager.getStreamHistory().blockingFirst().iterator(); + + isNonDuplicate = true; + while (it_history.hasNext()) { + history_item = it_history.next(); + if (history_item.streamId == playlist_item.streamId) { + isNonDuplicate = false; + break; + } + } + if (isNonDuplicate) { + localItems.add(playlist_item); + } else { + removedItemCount++; + if (playlistManager.getPlaylistThumbnail(playlistId).equals(playlist_item.thumbnailUrl)) { + thumbnailVideoRemoved = true; + } + } + } + return Flowable.just(localItems, removedItemCount, thumbnailVideoRemoved); + } + ) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe( + flow -> { + List localItems = (List) flow.blockingFirst(); + Boolean thumbnailVideoRemoved = (Boolean) flow.blockingLast(); + + itemListAdapter.clearStreamItemList(); + itemListAdapter.addItems(localItems); + localItems.clear(); + + if (thumbnailVideoRemoved) + updateThumbnailUrl(); + + int amountOfVideos = itemListAdapter.getItemsList().size(); + setVideoCount(amountOfVideos); + + saveChanges(); + hideLoading(); + + if (amountOfVideos == 0) + showEmptyState(); + }, (@io.reactivex.annotations.NonNull Throwable throwable) -> { + onError(throwable); + } + ); + } + @Override public void handleResult(@NonNull final List result) { super.handleResult(result); @@ -731,75 +793,5 @@ public class LocalPlaylistFragment extends BaseLocalListFragment localItems = new ArrayList<>(); - Long RemovedItemCount = 0l; - boolean thumbnailVideoRemoved = false; - - // Do this in the main thread - protected void onPreExecute() { - showLoading(); - } - - // Do not do this in the main thread - protected Long doInBackground(List playlist) { - - HistoryRecordManager recordManager = new HistoryRecordManager(getContext()); - Iterator it_history; - StreamHistoryEntry history_item; - - Iterator it_playlist = playlist.iterator(); - PlaylistStreamEntry playlist_item = null; - - boolean isNonDuplicate; - - while (it_playlist.hasNext()) { - playlist_item = it_playlist.next(); - - it_history = recordManager.getStreamHistory().blockingFirst().iterator(); - - isNonDuplicate = true; - while (it_history.hasNext()) { - history_item = it_history.next(); - if (history_item.streamId == playlist_item.streamId) { - isNonDuplicate = false; - break; - } - } - if (isNonDuplicate) { - localItems.add(playlist_item); - } - else - { - RemovedItemCount++; - if(playlistManager.getPlaylistThumbnail(playlistId).equals(playlist_item.thumbnailUrl)) - { - thumbnailVideoRemoved = true; - } - } - } - return this.RemovedItemCount; - } - - // Do this in the main thread - protected void onPostExecute() { - itemListAdapter.clearStreamItemList(); - itemListAdapter.addItems(localItems); - localItems.clear(); - - if (thumbnailVideoRemoved) - updateThumbnailUrl(); - - int amountOfVideos = itemListAdapter.getItemsList().size(); - setVideoCount(amountOfVideos); - - saveChanges(); - hideLoading(); - - if(amountOfVideos == 0) - showEmptyState(); - } - } }