1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-22 16:10:31 +00:00

Use newInstance in PlaylistDialog

This commit is contained in:
GGAutomaton 2022-04-04 13:50:27 +08:00
parent 629b685f5a
commit 638f227b51
3 changed files with 29 additions and 11 deletions

View File

@ -33,8 +33,16 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
private final CompositeDisposable playlistDisposables = new CompositeDisposable();
public PlaylistAppendDialog(final List<StreamEntity> streamEntities) {
super(streamEntities);
/**
* Create a new instance of {@link PlaylistAppendDialog}.
*
* @param streamEntities a list of {@link StreamEntity} to be added to playlists
* @return a new instance of {@link PlaylistAppendDialog}
*/
public static PlaylistAppendDialog newInstance(final List<StreamEntity> streamEntities) {
final PlaylistAppendDialog dialog = new PlaylistAppendDialog();
dialog.setStreamEntities(streamEntities);
return dialog;
}
/*//////////////////////////////////////////////////////////////////////////
@ -103,13 +111,14 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
// Helper
//////////////////////////////////////////////////////////////////////////*/
/** Display create playlist dialog. */
public void openCreatePlaylistDialog() {
if (getStreamEntities() == null || !isAdded()) {
return;
}
final PlaylistCreationDialog playlistCreationDialog =
new PlaylistCreationDialog(getStreamEntities());
PlaylistCreationDialog.newInstance(getStreamEntities());
// Move the dismissListener to the new dialog.
playlistCreationDialog.setOnDismissListener(this.getOnDismissListener());
this.setOnDismissListener(null);

View File

@ -21,8 +21,17 @@ import java.util.List;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
public final class PlaylistCreationDialog extends PlaylistDialog {
public PlaylistCreationDialog(final List<StreamEntity> streamEntities) {
super(streamEntities);
/**
* Create a new instance of {@link PlaylistCreationDialog}.
*
* @param streamEntities a list of {@link StreamEntity} to be added to playlists
* @return a new instance of {@link PlaylistCreationDialog}
*/
public static PlaylistCreationDialog newInstance(final List<StreamEntity> streamEntities) {
final PlaylistCreationDialog dialog = new PlaylistCreationDialog();
dialog.setStreamEntities(streamEntities);
return dialog;
}
/*//////////////////////////////////////////////////////////////////////////

View File

@ -31,10 +31,6 @@ public abstract class PlaylistDialog extends DialogFragment implements StateSave
private org.schabi.newpipe.util.SavedState savedState;
public PlaylistDialog(final List<StreamEntity> streamEntities) {
this.streamEntities = streamEntities;
}
/*//////////////////////////////////////////////////////////////////////////
// LifeCycle
//////////////////////////////////////////////////////////////////////////*/
@ -120,6 +116,10 @@ public abstract class PlaylistDialog extends DialogFragment implements StateSave
this.onDismissListener = onDismissListener;
}
protected void setStreamEntities(final List<StreamEntity> streamEntities) {
this.streamEntities = streamEntities;
}
/*//////////////////////////////////////////////////////////////////////////
// Dialog creation
//////////////////////////////////////////////////////////////////////////*/
@ -143,8 +143,8 @@ public abstract class PlaylistDialog extends DialogFragment implements StateSave
.observeOn(AndroidSchedulers.mainThread())
.subscribe(hasPlaylists ->
onExec.accept(hasPlaylists
? new PlaylistAppendDialog(streamEntities)
: new PlaylistCreationDialog(streamEntities))
? PlaylistAppendDialog.newInstance(streamEntities)
: PlaylistCreationDialog.newInstance(streamEntities))
);
}
}