mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-02-02 20:29:15 +00:00
Use centralized CompositeDisposable instead of custom Disposable
Also do not show any dialog if the user is aready removing watched videos in a local playlist
This commit is contained in:
parent
73611004a0
commit
437b86d1a7
@ -89,12 +89,13 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
|
|
||||||
private PublishSubject<Long> debouncedSaveSignal;
|
private PublishSubject<Long> debouncedSaveSignal;
|
||||||
private CompositeDisposable disposables;
|
private CompositeDisposable disposables;
|
||||||
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;
|
||||||
/* Has the playlist been modified (e.g. items reordered or deleted) */
|
/* Has the playlist been modified (e.g. items reordered or deleted) */
|
||||||
private AtomicBoolean isModified;
|
private AtomicBoolean isModified;
|
||||||
|
/* Is the playlist currently being processed to remove watched videos */
|
||||||
|
private boolean isRemovingWatched = false;
|
||||||
|
|
||||||
public static LocalPlaylistFragment getInstance(final long playlistId, final String name) {
|
public static LocalPlaylistFragment getInstance(final long playlistId, final String name) {
|
||||||
LocalPlaylistFragment instance = new LocalPlaylistFragment();
|
LocalPlaylistFragment instance = new LocalPlaylistFragment();
|
||||||
@ -304,14 +305,9 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
disposables.dispose();
|
disposables.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (removeWatchedDisposable != null) {
|
|
||||||
removeWatchedDisposable.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
debouncedSaveSignal = null;
|
debouncedSaveSignal = null;
|
||||||
playlistManager = null;
|
playlistManager = null;
|
||||||
disposables = null;
|
disposables = null;
|
||||||
removeWatchedDisposable = null;
|
|
||||||
|
|
||||||
isLoadingComplete = null;
|
isLoadingComplete = null;
|
||||||
isModified = null;
|
isModified = null;
|
||||||
@ -362,18 +358,20 @@ 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_remove_watched:
|
case R.id.menu_item_remove_watched:
|
||||||
new AlertDialog.Builder(getActivity())
|
if (!isRemovingWatched) {
|
||||||
.setMessage(R.string.remove_watched_popup_warning)
|
new AlertDialog.Builder(requireContext())
|
||||||
.setTitle(R.string.remove_watched_popup_title)
|
.setMessage(R.string.remove_watched_popup_warning)
|
||||||
.setPositiveButton(R.string.yes,
|
.setTitle(R.string.remove_watched_popup_title)
|
||||||
(DialogInterface d, int id) -> removeWatchedStreams(false))
|
.setPositiveButton(R.string.yes,
|
||||||
.setNeutralButton(
|
(DialogInterface d, int id) -> removeWatchedStreams(false))
|
||||||
R.string.remove_watched_popup_yes_and_partially_watched_videos,
|
.setNeutralButton(
|
||||||
(DialogInterface d, int id) -> removeWatchedStreams(true))
|
R.string.remove_watched_popup_yes_and_partially_watched_videos,
|
||||||
.setNegativeButton(R.string.cancel,
|
(DialogInterface d, int id) -> removeWatchedStreams(true))
|
||||||
(DialogInterface d, int id) -> d.cancel())
|
.setNegativeButton(R.string.cancel,
|
||||||
.create()
|
(DialogInterface d, int id) -> d.cancel())
|
||||||
.show();
|
.create()
|
||||||
|
.show();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
@ -382,13 +380,13 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removeWatchedStreams(final boolean removePartiallyWatched) {
|
public void removeWatchedStreams(final boolean removePartiallyWatched) {
|
||||||
if (removeWatchedDisposable != null && !removeWatchedDisposable.isDisposed()) {
|
if (isRemovingWatched) {
|
||||||
// already running
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
isRemovingWatched = true;
|
||||||
showLoading();
|
showLoading();
|
||||||
|
|
||||||
removeWatchedDisposable = playlistManager.getPlaylistStreams(playlistId)
|
disposables.add(playlistManager.getPlaylistStreams(playlistId)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.map((List<PlaylistStreamEntry> playlist) -> {
|
.map((List<PlaylistStreamEntry> playlist) -> {
|
||||||
// Playlist data
|
// Playlist data
|
||||||
@ -468,13 +466,8 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
hideLoading();
|
hideLoading();
|
||||||
|
isRemovingWatched = false;
|
||||||
// If this is not done, 'removeWatchedDisposable', will never be disposed of.
|
}, this::onError));
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user