Removed redundant code

reorganized code
This commit is contained in:
Grady Clark 2020-04-16 12:58:16 -05:00
parent 1d0c3de65f
commit db335d5cec
No known key found for this signature in database
GPG Key ID: F7AFAC4616D2FF5E
2 changed files with 25 additions and 21 deletions

View File

@ -362,18 +362,18 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item_removeWatched:
android.app.AlertDialog.Builder builder =
new android.app.AlertDialog.Builder(getActivity());
builder.setMessage(R.string.remove_watched_popup_warning)
new AlertDialog.Builder(getActivity())
.setMessage(R.string.remove_watched_popup_warning)
.setTitle(R.string.remove_watched_popup_title)
.setPositiveButton(R.string.remove_watched_popup_yes,
.setPositiveButton(R.string.yes,
(DialogInterface d, int id) -> removeWatchedStreams(false))
.setNeutralButton(
R.string.remove_watched_popup_yes_and_partially_watched_videos,
(DialogInterface d, int id) -> removeWatchedStreams(true))
.setNegativeButton(R.string.remove_watched_popup_cancel,
(DialogInterface d, int id) -> d.cancel());
builder.create().show();
.setNegativeButton(R.string.cancel,
(DialogInterface d, int id) -> d.cancel())
.create()
.show();
break;
default:
return super.onOptionsItemSelected(item);
@ -388,22 +388,23 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
}
showLoading();
removeWatchedDisposable = Flowable.just(Flowable.just(removePartiallyWatched,
playlistManager.getPlaylistStreams(playlistId).blockingFirst()))
removeWatchedDisposable = playlistManager.getPlaylistStreams(playlistId)
.subscribeOn(Schedulers.io())
.map(flow -> {
boolean localRemovePartiallyWatched = (boolean) flow.blockingFirst();
List<PlaylistStreamEntry> playlist
= (List<PlaylistStreamEntry>) flow.blockingLast();
HistoryRecordManager recordManager = new HistoryRecordManager(getContext());
.map((List<PlaylistStreamEntry> playlist) -> {
//Playlist data
Iterator<PlaylistStreamEntry> playlistIter = playlist.iterator();
//History data
HistoryRecordManager recordManager = new HistoryRecordManager(getContext());
Iterator<StreamHistoryEntry> historyIter = recordManager
.getStreamHistorySortedById().blockingFirst().iterator();
List<PlaylistStreamEntry> notWatchedItems = new ArrayList<>();
Iterator<StreamStateEntity> streamStatesIter = null;
//Remove Watched, Functionality data
List<PlaylistStreamEntry> notWatchedItems = new ArrayList<>();
boolean thumbnailVideoRemoved = false;
if (!localRemovePartiallyWatched) {
if (!removePartiallyWatched) {
streamStatesIter = recordManager.loadLocalStreamStateBatch(playlist)
.blockingGet().iterator();
}
@ -414,7 +415,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
historyStreamIds.add(historyIter.next().getStreamId());
}
if (localRemovePartiallyWatched) {
if (removePartiallyWatched) {
while (playlistIter.hasNext()) {
PlaylistStreamEntry playlistItem = playlistIter.next();
int indexInHistory = Collections.binarySearch(historyStreamIds,
@ -429,13 +430,12 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
}
}
} else {
boolean hasState = false;
while (playlistIter.hasNext()) {
PlaylistStreamEntry playlistItem = playlistIter.next();
int indexInHistory = Collections.binarySearch(historyStreamIds,
playlistItem.getStreamId());
hasState = streamStatesIter.next() != null;
boolean hasState = streamStatesIter.next() != null;
if (indexInHistory < 0 || hasState) {
notWatchedItems.add(playlistItem);
} else if (!thumbnailVideoRemoved
@ -470,6 +470,12 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
}
hideLoading();
//If this is not done, 'removeWatchedDisposable', will never be disposed of.
//Why: Because using the 'removePartiallyWatched' in this functions parms,
// prevents it from disposing. Exact reason for this behavior is unknown
removeWatchedDisposable.dispose();
removeWatchedDisposable = null;
}, this::onError);
}

View File

@ -604,8 +604,6 @@
<string name="remove_watched">Remove watched</string>
<string name="remove_watched_popup_title">Remove watched videos?</string>
<string name="remove_watched_popup_warning">"Videos that have been watched\nbefore and after being added to the playlist will be removed.\nAre you sure? This cannot be undone!</string>
<string name="remove_watched_popup_yes">Yes</string>
<string name="remove_watched_popup_cancel">Cancel</string>
<string name="remove_watched_popup_yes_and_partially_watched_videos">Yes, and partially watched videos</string>
<string name="new_seek_duration_toast">Due to ExoPlayer constraints the seek duration was set to %d seconds</string>
<!-- Time duration plurals -->