mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 00:20:32 +00:00
Implemented a warning before adding duplicate to playlist.
This commit is contained in:
parent
262b3a2945
commit
fdfeac081a
@ -26,6 +26,7 @@ import static org.schabi.newpipe.database.playlist.model.PlaylistStreamEntity.PL
|
|||||||
import static org.schabi.newpipe.database.stream.model.StreamEntity.STREAM_ID;
|
import static org.schabi.newpipe.database.stream.model.StreamEntity.STREAM_ID;
|
||||||
import static org.schabi.newpipe.database.stream.model.StreamEntity.STREAM_TABLE;
|
import static org.schabi.newpipe.database.stream.model.StreamEntity.STREAM_TABLE;
|
||||||
import static org.schabi.newpipe.database.stream.model.StreamEntity.STREAM_THUMBNAIL_URL;
|
import static org.schabi.newpipe.database.stream.model.StreamEntity.STREAM_THUMBNAIL_URL;
|
||||||
|
import static org.schabi.newpipe.database.stream.model.StreamEntity.STREAM_URL;
|
||||||
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.JOIN_STREAM_ID_ALIAS;
|
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.JOIN_STREAM_ID_ALIAS;
|
||||||
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_PROGRESS_MILLIS;
|
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_PROGRESS_MILLIS;
|
||||||
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_STATE_TABLE;
|
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_STATE_TABLE;
|
||||||
@ -49,6 +50,16 @@ public interface PlaylistStreamDAO extends BasicDAO<PlaylistStreamEntity> {
|
|||||||
+ " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId")
|
+ " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId")
|
||||||
void deleteBatch(long playlistId);
|
void deleteBatch(long playlistId);
|
||||||
|
|
||||||
|
@Query("SELECT COALESCE(COUNT(*), 0)"
|
||||||
|
+ " FROM " + STREAM_TABLE
|
||||||
|
+ " LEFT JOIN " + PLAYLIST_STREAM_JOIN_TABLE
|
||||||
|
+ " ON " + STREAM_ID + " = " + JOIN_STREAM_ID
|
||||||
|
+ " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId "
|
||||||
|
+ " AND " + STREAM_URL + " = :streamURL"
|
||||||
|
)
|
||||||
|
Flowable<Integer> getDuplicates(long playlistId, String streamURL);
|
||||||
|
|
||||||
|
|
||||||
@Query("SELECT COALESCE(MAX(" + JOIN_INDEX + "), -1)"
|
@Query("SELECT COALESCE(MAX(" + JOIN_INDEX + "), -1)"
|
||||||
+ " FROM " + PLAYLIST_STREAM_JOIN_TABLE
|
+ " FROM " + PLAYLIST_STREAM_JOIN_TABLE
|
||||||
+ " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId")
|
+ " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId")
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.schabi.newpipe.local.dialog;
|
package org.schabi.newpipe.local.dialog;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -128,6 +129,19 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
|
|||||||
private void onPlaylistSelected(@NonNull final LocalPlaylistManager manager,
|
private void onPlaylistSelected(@NonNull final LocalPlaylistManager manager,
|
||||||
@NonNull final PlaylistMetadataEntry playlist,
|
@NonNull final PlaylistMetadataEntry playlist,
|
||||||
@NonNull final List<StreamEntity> streams) {
|
@NonNull final List<StreamEntity> streams) {
|
||||||
|
|
||||||
|
final int numOfDuplicates = manager.getPlaylistDuplicates(playlist.uid,
|
||||||
|
streams.get(0).getUrl()).blockingFirst();
|
||||||
|
if (numOfDuplicates > 0) {
|
||||||
|
createDuplicateDialog(numOfDuplicates, manager, playlist, streams);
|
||||||
|
} else {
|
||||||
|
addStreamToPlaylist(manager, playlist, streams);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addStreamToPlaylist(@NonNull final LocalPlaylistManager manager,
|
||||||
|
@NonNull final PlaylistMetadataEntry playlist,
|
||||||
|
@NonNull final List<StreamEntity> streams) {
|
||||||
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);
|
||||||
|
|
||||||
@ -142,7 +156,23 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
|
|||||||
playlistDisposables.add(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()));
|
||||||
|
|
||||||
requireDialog().dismiss();
|
requireDialog().dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createDuplicateDialog(final int duplicates,
|
||||||
|
@NonNull final LocalPlaylistManager manager,
|
||||||
|
@NonNull final PlaylistMetadataEntry playlist,
|
||||||
|
@NonNull final List<StreamEntity> streams) {
|
||||||
|
//TODO: change color
|
||||||
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
|
||||||
|
builder.setTitle(R.string.duplicate_stream_in_playlist_title);
|
||||||
|
builder.setMessage(getString(R.string.duplicate_stream_in_playlist_description,
|
||||||
|
duplicates));
|
||||||
|
|
||||||
|
builder.setPositiveButton(android.R.string.yes, (dialog, i) -> {
|
||||||
|
addStreamToPlaylist(manager, playlist, streams);
|
||||||
|
});
|
||||||
|
builder.setNeutralButton(R.string.cancel, null);
|
||||||
|
builder.create().show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,10 @@ public class LocalPlaylistManager {
|
|||||||
return playlistStreamTable.getOrderedStreamsOf(playlistId).subscribeOn(Schedulers.io());
|
return playlistStreamTable.getOrderedStreamsOf(playlistId).subscribeOn(Schedulers.io());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Flowable<Integer> getPlaylistDuplicates(final long playlistId, final String streamURL) {
|
||||||
|
return playlistStreamTable.getDuplicates(playlistId, streamURL);
|
||||||
|
}
|
||||||
|
|
||||||
public Single<Integer> deletePlaylist(final long playlistId) {
|
public Single<Integer> deletePlaylist(final long playlistId) {
|
||||||
return Single.fromCallable(() -> playlistTable.deletePlaylist(playlistId))
|
return Single.fromCallable(() -> playlistTable.deletePlaylist(playlistId))
|
||||||
.subscribeOn(Schedulers.io());
|
.subscribeOn(Schedulers.io());
|
||||||
|
@ -447,6 +447,9 @@
|
|||||||
<string name="playlist_add_stream_success">Playlisted</string>
|
<string name="playlist_add_stream_success">Playlisted</string>
|
||||||
<string name="playlist_thumbnail_change_success">Playlist thumbnail changed.</string>
|
<string name="playlist_thumbnail_change_success">Playlist thumbnail changed.</string>
|
||||||
<string name="playlist_no_uploader">Auto-generated (no uploader found)</string>
|
<string name="playlist_no_uploader">Auto-generated (no uploader found)</string>
|
||||||
|
<string name="duplicate_stream_in_playlist_title">Duplicated Video Found</string>
|
||||||
|
<string name="duplicate_stream_in_playlist_description">The playlist contains this stream
|
||||||
|
already %d time(s).\nDo you want to add it one more time?</string>
|
||||||
<!-- Players -->
|
<!-- Players -->
|
||||||
<string name="caption_none">No Captions</string>
|
<string name="caption_none">No Captions</string>
|
||||||
<string name="resize_fit">Fit</string>
|
<string name="resize_fit">Fit</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user