Fix PlaylistAppendDialog showing when no local playlists exist
This commit is contained in:
parent
5214bfe8cb
commit
2680d41a3d
|
@ -33,4 +33,7 @@ public abstract class PlaylistDAO implements BasicDAO<PlaylistEntity> {
|
|||
|
||||
@Query("DELETE FROM " + PLAYLIST_TABLE + " WHERE " + PLAYLIST_ID + " = :playlistId")
|
||||
public abstract int deletePlaylist(long playlistId);
|
||||
|
||||
@Query("SELECT COUNT(*) FROM " + PLAYLIST_TABLE)
|
||||
public abstract Flowable<Long> getCount();
|
||||
}
|
||||
|
|
|
@ -80,6 +80,7 @@ import org.schabi.newpipe.fragments.EmptyFragment;
|
|||
import org.schabi.newpipe.fragments.list.comments.CommentsFragment;
|
||||
import org.schabi.newpipe.fragments.list.videos.RelatedVideosFragment;
|
||||
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
|
||||
import org.schabi.newpipe.local.dialog.PlaylistCreationDialog;
|
||||
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||
import org.schabi.newpipe.player.BasePlayer;
|
||||
import org.schabi.newpipe.player.MainPlayer;
|
||||
|
@ -482,8 +483,14 @@ public class VideoDetailFragment
|
|||
break;
|
||||
case R.id.detail_controls_playlist_append:
|
||||
if (getFM() != null && currentInfo != null) {
|
||||
PlaylistAppendDialog.fromStreamInfo(currentInfo)
|
||||
.show(getFM(), TAG);
|
||||
|
||||
final PlaylistAppendDialog d = PlaylistAppendDialog.fromStreamInfo(currentInfo);
|
||||
disposables.add(
|
||||
PlaylistAppendDialog.checkPlaylists(getContext(),
|
||||
() -> d.show(getFM(), TAG),
|
||||
() -> PlaylistCreationDialog.newInstance(d).show(getFM(), TAG)
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
case R.id.detail_controls_download:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.schabi.newpipe.local.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -29,6 +30,7 @@ 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 {
|
||||
private static final String TAG = PlaylistAppendDialog.class.getCanonicalName();
|
||||
|
@ -38,6 +40,27 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
|
|||
|
||||
private CompositeDisposable playlistDisposables = new CompositeDisposable();
|
||||
|
||||
public static Disposable checkPlaylists(
|
||||
final Context context, final Invoker onSuccess, final Invoker onFailed
|
||||
) {
|
||||
final LocalPlaylistManager playlistManager =
|
||||
new LocalPlaylistManager(NewPipeDatabase.getInstance(context));
|
||||
|
||||
return playlistManager.hasPlaylists()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(hasPlaylists -> {
|
||||
if (hasPlaylists) {
|
||||
onSuccess.invoke();
|
||||
} else {
|
||||
onFailed.invoke();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public interface Invoker {
|
||||
void invoke();
|
||||
}
|
||||
|
||||
public static PlaylistAppendDialog fromStreamInfo(final StreamInfo info) {
|
||||
final PlaylistAppendDialog dialog = new PlaylistAppendDialog();
|
||||
dialog.setInfo(Collections.singletonList(new StreamEntity(info)));
|
||||
|
@ -136,11 +159,6 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
|
|||
}
|
||||
|
||||
private void onPlaylistsReceived(@NonNull final List<PlaylistMetadataEntry> playlists) {
|
||||
if (playlists.isEmpty()) {
|
||||
openCreatePlaylistDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
if (playlistAdapter != null && playlistRecyclerView != null) {
|
||||
playlistAdapter.clearStreamItemList();
|
||||
playlistAdapter.addItems(playlists);
|
||||
|
|
|
@ -26,6 +26,12 @@ public final class PlaylistCreationDialog extends PlaylistDialog {
|
|||
return dialog;
|
||||
}
|
||||
|
||||
public static PlaylistCreationDialog newInstance(final PlaylistAppendDialog appendDialog) {
|
||||
final PlaylistCreationDialog dialog = new PlaylistCreationDialog();
|
||||
dialog.setInfo(appendDialog.getStreams());
|
||||
return dialog;
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
// Dialog
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
|
|
@ -126,4 +126,10 @@ public class LocalPlaylistManager {
|
|||
}).subscribeOn(Schedulers.io());
|
||||
}
|
||||
|
||||
public Maybe<Boolean> hasPlaylists() {
|
||||
return playlistTable.getCount()
|
||||
.firstElement()
|
||||
.map(count -> count > 0)
|
||||
.subscribeOn(Schedulers.io());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.schabi.newpipe.extractor.StreamingService;
|
|||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
|
||||
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
|
||||
import org.schabi.newpipe.local.dialog.PlaylistCreationDialog;
|
||||
import org.schabi.newpipe.player.event.PlayerEventListener;
|
||||
import org.schabi.newpipe.player.helper.PlaybackParameterDialog;
|
||||
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
||||
|
@ -571,8 +572,13 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
private void openPlaylistAppendDialog(final List<PlayQueueItem> playlist) {
|
||||
PlaylistAppendDialog.fromPlayQueueItems(playlist)
|
||||
.show(getSupportFragmentManager(), getTag());
|
||||
final PlaylistAppendDialog d = PlaylistAppendDialog.fromPlayQueueItems(playlist);
|
||||
|
||||
PlaylistAppendDialog.checkPlaylists(getApplicationContext(),
|
||||
() -> d.show(getSupportFragmentManager(), getTag()),
|
||||
() -> PlaylistCreationDialog.newInstance(d)
|
||||
.show(getSupportFragmentManager(), getTag()
|
||||
));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -7,6 +7,7 @@ import androidx.fragment.app.Fragment;
|
|||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
|
||||
import org.schabi.newpipe.local.dialog.PlaylistCreationDialog;
|
||||
import org.schabi.newpipe.player.MainPlayer;
|
||||
import org.schabi.newpipe.player.helper.PlayerHolder;
|
||||
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
||||
|
@ -58,8 +59,14 @@ public enum StreamDialogEntry {
|
|||
|
||||
append_playlist(R.string.append_playlist, (fragment, item) -> {
|
||||
if (fragment.getFragmentManager() != null) {
|
||||
PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item))
|
||||
.show(fragment.getFragmentManager(), "StreamDialogEntry@append_playlist");
|
||||
final PlaylistAppendDialog d = PlaylistAppendDialog
|
||||
.fromStreamInfoItems(Collections.singletonList(item));
|
||||
|
||||
PlaylistAppendDialog.checkPlaylists(fragment.getContext(),
|
||||
() -> d.show(fragment.getFragmentManager(), "StreamDialogEntry@append_playlist"),
|
||||
() -> PlaylistCreationDialog.newInstance(d)
|
||||
.show(fragment.getFragmentManager(), "StreamDialogEntry@create_playlist")
|
||||
);
|
||||
}
|
||||
}),
|
||||
|
||||
|
|
Loading…
Reference in New Issue