Skip to content

Commit eb3363d

Browse files
committed
Created the first draft.
1 parent 1bb166a commit eb3363d

5 files changed

Lines changed: 44 additions & 0 deletions

File tree

app/src/main/java/org/schabi/newpipe/database/playlist/dao/PlaylistStreamDAO.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,15 @@ default Flowable<List<PlaylistStreamEntity>> listByService(final int serviceId)
8383
+ " GROUP BY " + JOIN_PLAYLIST_ID
8484
+ " ORDER BY " + PLAYLIST_NAME + " COLLATE NOCASE ASC")
8585
Flowable<List<PlaylistMetadataEntry>> getPlaylistMetadata();
86+
87+
@Transaction
88+
@Query("DELETE FROM " + PLAYLIST_STREAM_JOIN_TABLE
89+
+ " WHERE " + JOIN_PLAYLIST_ID + "=:playlistId"
90+
+ " AND " + JOIN_STREAM_ID + " IN ("
91+
+ " SELECT " + JOIN_STREAM_ID
92+
+ " FROM " + PLAYLIST_STREAM_JOIN_TABLE
93+
+ " WHERE " + JOIN_PLAYLIST_ID + "=:playlistId"
94+
+ " GROUP BY " + JOIN_STREAM_ID
95+
+ " HAVING COUNT(*) > 1 )" )
96+
Flowable<List<PlaylistMetadataEntry>> removeDuplicates(long playlistId);
8697
}

app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ public boolean onOptionsItemSelected(final MenuItem item) {
367367
.create()
368368
.show();
369369
}
370+
} else if (item.getItemId() == R.id.menu_item_remove_duplicates) {
371+
openRemoveDuplicatesDialog();
370372
} else {
371373
return super.onOptionsItemSelected(item);
372374
}
@@ -621,6 +623,24 @@ private void updateThumbnailUrl() {
621623
changeThumbnailUrl(newThumbnailUrl);
622624
}
623625

626+
627+
private void openRemoveDuplicatesDialog() {
628+
final AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
629+
630+
builder.setTitle("R.string.duplicate_stream_in_playlist_title")
631+
.setMessage("test")
632+
.setPositiveButton(android.R.string.yes, (dialog, i) -> {
633+
removeDuplicatesInPlaylist();
634+
})
635+
.setNeutralButton(R.string.cancel, null);
636+
637+
builder.create().show();
638+
}
639+
640+
private void removeDuplicatesInPlaylist() {
641+
642+
}
643+
624644
private void deleteItem(final PlaylistStreamEntry item) {
625645
if (itemListAdapter == null) {
626646
return;

app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ public Flowable<List<PlaylistMetadataEntry>> getPlaylists() {
8686
return playlistStreamTable.getPlaylistMetadata().subscribeOn(Schedulers.io());
8787
}
8888

89+
public Flowable<List<PlaylistMetadataEntry>> removeDuplicateStreams() {
90+
// TODO: Delete Duplicates and rebuild the index
91+
// TODO: Rebuild the index
92+
return playlistStreamTable.getPlaylistMetadata().subscribeOn(Schedulers.io());
93+
}
94+
8995
public Flowable<List<PlaylistStreamEntry>> getPlaylistStreams(final long playlistId) {
9096
return playlistStreamTable.getOrderedStreamsOf(playlistId).subscribeOn(Schedulers.io());
9197
}

app/src/main/res/menu/menu_local_playlist.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@
1212
android:id="@+id/menu_item_rename_playlist"
1313
android:title="@string/rename_playlist"
1414
app:showAsAction="never" />
15+
1516
<item
1617
android:id="@+id/menu_item_remove_watched"
1718
android:title="@string/remove_watched"
1819
app:showAsAction="never" />
20+
21+
<item
22+
android:id="@+id/menu_item_remove_duplicates"
23+
android:title="@string/remove_duplicates"
24+
app:showAsAction="never" />
1925
</menu>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@
626626
<string name="systems_language">System default</string>
627627
<string name="remove_watched">Remove watched</string>
628628
<string name="remove_watched_popup_title">Remove watched videos?</string>
629+
<string name="remove_duplicates">Remove duplicates</string>
629630
<string name="remove_watched_popup_warning">Videos that have been watched before and after being added to the playlist will be removed.
630631
\nAre you sure\? This cannot be undone!</string>
631632
<string name="remove_watched_popup_yes_and_partially_watched_videos">Yes, and partially watched videos</string>

0 commit comments

Comments
 (0)