Fix potential disposable leak in PlaylistAppendDialog
This commit is contained in:
parent
04e725bb50
commit
00fc5217f5
1 changed files with 8 additions and 8 deletions
|
@ -28,6 +28,7 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
|
|
||||||
public final class PlaylistAppendDialog extends PlaylistDialog {
|
public final class PlaylistAppendDialog extends PlaylistDialog {
|
||||||
|
@ -36,7 +37,7 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
|
||||||
private RecyclerView playlistRecyclerView;
|
private RecyclerView playlistRecyclerView;
|
||||||
private LocalItemListAdapter playlistAdapter;
|
private LocalItemListAdapter playlistAdapter;
|
||||||
|
|
||||||
private Disposable playlistReactor;
|
private CompositeDisposable playlistDisposables = new CompositeDisposable();
|
||||||
|
|
||||||
public static PlaylistAppendDialog fromStreamInfo(final StreamInfo info) {
|
public static PlaylistAppendDialog fromStreamInfo(final StreamInfo info) {
|
||||||
PlaylistAppendDialog dialog = new PlaylistAppendDialog();
|
PlaylistAppendDialog dialog = new PlaylistAppendDialog();
|
||||||
|
@ -99,9 +100,9 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
|
||||||
final View newPlaylistButton = view.findViewById(R.id.newPlaylist);
|
final View newPlaylistButton = view.findViewById(R.id.newPlaylist);
|
||||||
newPlaylistButton.setOnClickListener(ignored -> openCreatePlaylistDialog());
|
newPlaylistButton.setOnClickListener(ignored -> openCreatePlaylistDialog());
|
||||||
|
|
||||||
playlistReactor = playlistManager.getPlaylists()
|
playlistDisposables.add(playlistManager.getPlaylists()
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(this::onPlaylistsReceived);
|
.subscribe(this::onPlaylistsReceived));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -111,12 +112,12 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
if (playlistReactor != null) playlistReactor.dispose();
|
playlistDisposables.dispose();
|
||||||
if (playlistAdapter != null) {
|
if (playlistAdapter != null) {
|
||||||
playlistAdapter.unsetSelectedListener();
|
playlistAdapter.unsetSelectedListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
playlistReactor = null;
|
playlistDisposables.clear();
|
||||||
playlistRecyclerView = null;
|
playlistRecyclerView = null;
|
||||||
playlistAdapter = null;
|
playlistAdapter = null;
|
||||||
}
|
}
|
||||||
|
@ -150,13 +151,12 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
|
||||||
@NonNull List<StreamEntity> streams) {
|
@NonNull List<StreamEntity> streams) {
|
||||||
if (getStreams() == null) return;
|
if (getStreams() == null) return;
|
||||||
|
|
||||||
@SuppressLint("ShowToast")
|
|
||||||
final Toast successToast = Toast.makeText(getContext(),
|
final Toast successToast = Toast.makeText(getContext(),
|
||||||
R.string.playlist_add_stream_success, Toast.LENGTH_SHORT);
|
R.string.playlist_add_stream_success, Toast.LENGTH_SHORT);
|
||||||
|
|
||||||
manager.appendToPlaylist(playlist.uid, streams)
|
playlistDisposables.add(manager.appendToPlaylist(playlist.uid, streams)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(ignored -> successToast.show());
|
.subscribe(ignored -> successToast.show()));
|
||||||
|
|
||||||
getDialog().dismiss();
|
getDialog().dismiss();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue