mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-25 01:20:34 +00:00
Removed redundant code
reorganized code
This commit is contained in:
parent
1d0c3de65f
commit
db335d5cec
@ -362,18 +362,18 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.menu_item_removeWatched:
|
case R.id.menu_item_removeWatched:
|
||||||
android.app.AlertDialog.Builder builder =
|
new AlertDialog.Builder(getActivity())
|
||||||
new android.app.AlertDialog.Builder(getActivity());
|
.setMessage(R.string.remove_watched_popup_warning)
|
||||||
builder.setMessage(R.string.remove_watched_popup_warning)
|
|
||||||
.setTitle(R.string.remove_watched_popup_title)
|
.setTitle(R.string.remove_watched_popup_title)
|
||||||
.setPositiveButton(R.string.remove_watched_popup_yes,
|
.setPositiveButton(R.string.yes,
|
||||||
(DialogInterface d, int id) -> removeWatchedStreams(false))
|
(DialogInterface d, int id) -> removeWatchedStreams(false))
|
||||||
.setNeutralButton(
|
.setNeutralButton(
|
||||||
R.string.remove_watched_popup_yes_and_partially_watched_videos,
|
R.string.remove_watched_popup_yes_and_partially_watched_videos,
|
||||||
(DialogInterface d, int id) -> removeWatchedStreams(true))
|
(DialogInterface d, int id) -> removeWatchedStreams(true))
|
||||||
.setNegativeButton(R.string.remove_watched_popup_cancel,
|
.setNegativeButton(R.string.cancel,
|
||||||
(DialogInterface d, int id) -> d.cancel());
|
(DialogInterface d, int id) -> d.cancel())
|
||||||
builder.create().show();
|
.create()
|
||||||
|
.show();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
@ -388,22 +388,23 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
}
|
}
|
||||||
showLoading();
|
showLoading();
|
||||||
|
|
||||||
removeWatchedDisposable = Flowable.just(Flowable.just(removePartiallyWatched,
|
removeWatchedDisposable = playlistManager.getPlaylistStreams(playlistId)
|
||||||
playlistManager.getPlaylistStreams(playlistId).blockingFirst()))
|
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.map(flow -> {
|
.map((List<PlaylistStreamEntry> playlist) -> {
|
||||||
boolean localRemovePartiallyWatched = (boolean) flow.blockingFirst();
|
//Playlist data
|
||||||
List<PlaylistStreamEntry> playlist
|
|
||||||
= (List<PlaylistStreamEntry>) flow.blockingLast();
|
|
||||||
HistoryRecordManager recordManager = new HistoryRecordManager(getContext());
|
|
||||||
Iterator<PlaylistStreamEntry> playlistIter = playlist.iterator();
|
Iterator<PlaylistStreamEntry> playlistIter = playlist.iterator();
|
||||||
|
|
||||||
|
//History data
|
||||||
|
HistoryRecordManager recordManager = new HistoryRecordManager(getContext());
|
||||||
Iterator<StreamHistoryEntry> historyIter = recordManager
|
Iterator<StreamHistoryEntry> historyIter = recordManager
|
||||||
.getStreamHistorySortedById().blockingFirst().iterator();
|
.getStreamHistorySortedById().blockingFirst().iterator();
|
||||||
List<PlaylistStreamEntry> notWatchedItems = new ArrayList<>();
|
|
||||||
Iterator<StreamStateEntity> streamStatesIter = null;
|
Iterator<StreamStateEntity> streamStatesIter = null;
|
||||||
|
|
||||||
|
//Remove Watched, Functionality data
|
||||||
|
List<PlaylistStreamEntry> notWatchedItems = new ArrayList<>();
|
||||||
boolean thumbnailVideoRemoved = false;
|
boolean thumbnailVideoRemoved = false;
|
||||||
|
|
||||||
if (!localRemovePartiallyWatched) {
|
if (!removePartiallyWatched) {
|
||||||
streamStatesIter = recordManager.loadLocalStreamStateBatch(playlist)
|
streamStatesIter = recordManager.loadLocalStreamStateBatch(playlist)
|
||||||
.blockingGet().iterator();
|
.blockingGet().iterator();
|
||||||
}
|
}
|
||||||
@ -414,7 +415,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
historyStreamIds.add(historyIter.next().getStreamId());
|
historyStreamIds.add(historyIter.next().getStreamId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (localRemovePartiallyWatched) {
|
if (removePartiallyWatched) {
|
||||||
while (playlistIter.hasNext()) {
|
while (playlistIter.hasNext()) {
|
||||||
PlaylistStreamEntry playlistItem = playlistIter.next();
|
PlaylistStreamEntry playlistItem = playlistIter.next();
|
||||||
int indexInHistory = Collections.binarySearch(historyStreamIds,
|
int indexInHistory = Collections.binarySearch(historyStreamIds,
|
||||||
@ -429,13 +430,12 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
boolean hasState = false;
|
|
||||||
while (playlistIter.hasNext()) {
|
while (playlistIter.hasNext()) {
|
||||||
PlaylistStreamEntry playlistItem = playlistIter.next();
|
PlaylistStreamEntry playlistItem = playlistIter.next();
|
||||||
int indexInHistory = Collections.binarySearch(historyStreamIds,
|
int indexInHistory = Collections.binarySearch(historyStreamIds,
|
||||||
playlistItem.getStreamId());
|
playlistItem.getStreamId());
|
||||||
|
|
||||||
hasState = streamStatesIter.next() != null;
|
boolean hasState = streamStatesIter.next() != null;
|
||||||
if (indexInHistory < 0 || hasState) {
|
if (indexInHistory < 0 || hasState) {
|
||||||
notWatchedItems.add(playlistItem);
|
notWatchedItems.add(playlistItem);
|
||||||
} else if (!thumbnailVideoRemoved
|
} else if (!thumbnailVideoRemoved
|
||||||
@ -470,6 +470,12 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
hideLoading();
|
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);
|
}, this::onError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,8 +604,6 @@
|
|||||||
<string name="remove_watched">Remove watched</string>
|
<string name="remove_watched">Remove watched</string>
|
||||||
<string name="remove_watched_popup_title">Remove watched videos?</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_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="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>
|
<string name="new_seek_duration_toast">Due to ExoPlayer constraints the seek duration was set to %d seconds</string>
|
||||||
<!-- Time duration plurals -->
|
<!-- Time duration plurals -->
|
||||||
|
Loading…
Reference in New Issue
Block a user