From 00fc5217f549bfd3d13f09fb8ddfc1afacbae0fe Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 14 Aug 2019 12:54:17 +0200 Subject: [PATCH] Fix potential disposable leak in PlaylistAppendDialog --- .../local/dialog/PlaylistAppendDialog.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java b/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java index 204d52e69..a72254df1 100644 --- a/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java +++ b/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java @@ -28,6 +28,7 @@ import java.util.Collections; import java.util.List; import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; public final class PlaylistAppendDialog extends PlaylistDialog { @@ -36,7 +37,7 @@ public final class PlaylistAppendDialog extends PlaylistDialog { private RecyclerView playlistRecyclerView; private LocalItemListAdapter playlistAdapter; - private Disposable playlistReactor; + private CompositeDisposable playlistDisposables = new CompositeDisposable(); public static PlaylistAppendDialog fromStreamInfo(final StreamInfo info) { PlaylistAppendDialog dialog = new PlaylistAppendDialog(); @@ -99,9 +100,9 @@ public final class PlaylistAppendDialog extends PlaylistDialog { final View newPlaylistButton = view.findViewById(R.id.newPlaylist); newPlaylistButton.setOnClickListener(ignored -> openCreatePlaylistDialog()); - playlistReactor = playlistManager.getPlaylists() + playlistDisposables.add(playlistManager.getPlaylists() .observeOn(AndroidSchedulers.mainThread()) - .subscribe(this::onPlaylistsReceived); + .subscribe(this::onPlaylistsReceived)); } /*////////////////////////////////////////////////////////////////////////// @@ -111,12 +112,12 @@ public final class PlaylistAppendDialog extends PlaylistDialog { @Override public void onDestroyView() { super.onDestroyView(); - if (playlistReactor != null) playlistReactor.dispose(); + playlistDisposables.dispose(); if (playlistAdapter != null) { playlistAdapter.unsetSelectedListener(); } - playlistReactor = null; + playlistDisposables.clear(); playlistRecyclerView = null; playlistAdapter = null; } @@ -150,13 +151,12 @@ public final class PlaylistAppendDialog extends PlaylistDialog { @NonNull List streams) { if (getStreams() == null) return; - @SuppressLint("ShowToast") final Toast successToast = Toast.makeText(getContext(), R.string.playlist_add_stream_success, Toast.LENGTH_SHORT); - manager.appendToPlaylist(playlist.uid, streams) + playlistDisposables.add(manager.appendToPlaylist(playlist.uid, streams) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(ignored -> successToast.show()); + .subscribe(ignored -> successToast.show())); getDialog().dismiss(); }