From 73611004a0484fce5f6be54654d8107294e53543 Mon Sep 17 00:00:00 2001 From: Grady Clark <50427197+GradyClark@users.noreply.github.com> Date: Tue, 21 Apr 2020 01:57:23 -0500 Subject: [PATCH] Code cleanup, and best practices --- .../local/playlist/LocalPlaylistFragment.java | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) 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 462bffb4e..3ec9ae216 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 @@ -392,32 +392,27 @@ public class LocalPlaylistFragment extends BaseLocalListFragment playlist) -> { // Playlist data - Iterator playlistIter = playlist.iterator(); + final Iterator playlistIter = playlist.iterator(); // History data - HistoryRecordManager recordManager = new HistoryRecordManager(getContext()); - Iterator historyIter = recordManager + final HistoryRecordManager recordManager + = new HistoryRecordManager(getContext()); + final Iterator historyIter = recordManager .getStreamHistorySortedById().blockingFirst().iterator(); - Iterator streamStatesIter = null; // Remove Watched, Functionality data - List notWatchedItems = new ArrayList<>(); + final List notWatchedItems = new ArrayList<>(); boolean thumbnailVideoRemoved = false; - if (!removePartiallyWatched) { - streamStatesIter = recordManager.loadLocalStreamStateBatch(playlist) - .blockingGet().iterator(); - } - // already sorted by ^ getStreamHistorySortedById(), binary search can be used - ArrayList historyStreamIds = new ArrayList<>(); + final ArrayList historyStreamIds = new ArrayList<>(); while (historyIter.hasNext()) { historyStreamIds.add(historyIter.next().getStreamId()); } if (removePartiallyWatched) { while (playlistIter.hasNext()) { - PlaylistStreamEntry playlistItem = playlistIter.next(); + final PlaylistStreamEntry playlistItem = playlistIter.next(); int indexInHistory = Collections.binarySearch(historyStreamIds, playlistItem.getStreamId()); @@ -430,12 +425,15 @@ public class LocalPlaylistFragment extends BaseLocalListFragment streamStatesIter = recordManager + .loadLocalStreamStateBatch(playlist).blockingGet().iterator(); + while (playlistIter.hasNext()) { PlaylistStreamEntry playlistItem = playlistIter.next(); - int indexInHistory = Collections.binarySearch(historyStreamIds, + final int indexInHistory = Collections.binarySearch(historyStreamIds, playlistItem.getStreamId()); - boolean hasState = streamStatesIter.next() != null; + final boolean hasState = streamStatesIter.next() != null; if (indexInHistory < 0 || hasState) { notWatchedItems.add(playlistItem); } else if (!thumbnailVideoRemoved @@ -450,9 +448,9 @@ public class LocalPlaylistFragment extends BaseLocalListFragment { - List notWatchedItems = + final List notWatchedItems = (List) flow.blockingFirst(); - boolean thumbnailVideoRemoved = (Boolean) flow.blockingLast(); + final boolean thumbnailVideoRemoved = (Boolean) flow.blockingLast(); itemListAdapter.clearStreamItemList(); itemListAdapter.addItems(notWatchedItems); @@ -463,7 +461,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment