diff --git a/app/src/main/java/org/schabi/newpipe/database/playlist/dao/PlaylistStreamDAO.java b/app/src/main/java/org/schabi/newpipe/database/playlist/dao/PlaylistStreamDAO.java index 594df5c25..015a77002 100644 --- a/app/src/main/java/org/schabi/newpipe/database/playlist/dao/PlaylistStreamDAO.java +++ b/app/src/main/java/org/schabi/newpipe/database/playlist/dao/PlaylistStreamDAO.java @@ -84,14 +84,22 @@ public interface PlaylistStreamDAO extends BasicDAO { + " ORDER BY " + PLAYLIST_NAME + " COLLATE NOCASE ASC") Flowable> getPlaylistMetadata(); + @RewriteQueriesToDropUnusedColumns @Transaction - @Query("DELETE FROM " + PLAYLIST_STREAM_JOIN_TABLE - + " WHERE " + JOIN_PLAYLIST_ID + "=:playlistId" - + " AND " + JOIN_STREAM_ID + " IN (" - + " SELECT " + JOIN_STREAM_ID + @Query("SELECT *, MIN(" + JOIN_INDEX + ") FROM " + STREAM_TABLE + " INNER JOIN " + + "(SELECT " + JOIN_STREAM_ID + "," + JOIN_INDEX + " FROM " + PLAYLIST_STREAM_JOIN_TABLE - + " WHERE " + JOIN_PLAYLIST_ID + "=:playlistId" - + " GROUP BY " + JOIN_STREAM_ID - + " HAVING COUNT(*) > 1 )" ) - Flowable> removeDuplicates(long playlistId); + + " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId)" + + " ON " + STREAM_ID + " = " + JOIN_STREAM_ID + + " LEFT JOIN " + + "(SELECT " + JOIN_STREAM_ID + " AS " + JOIN_STREAM_ID_ALIAS + ", " + + STREAM_PROGRESS_MILLIS + + " FROM " + STREAM_STATE_TABLE + " )" + + " ON " + STREAM_ID + " = " + JOIN_STREAM_ID_ALIAS + + " GROUP BY " + STREAM_ID + + " ORDER BY " + JOIN_INDEX + " ASC") + Flowable> getStreamsWithoutDuplicates(long playlistId); + + + } diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index a5fb67576..9881a0a20 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -627,8 +627,8 @@ public class LocalPlaylistFragment extends BaseLocalListFragment { removeDuplicatesInPlaylist(); }) @@ -638,7 +638,20 @@ public class LocalPlaylistFragment extends BaseLocalListFragment itemsToKeep = playlistManager + .getDistinctPlaylistStreams(playlistId).blockingFirst(); + itemListAdapter.clearStreamItemList(); + itemListAdapter.addItems(itemsToKeep); + saveChanges(); + + final long videoCount = itemListAdapter.getItemsList().size(); + setVideoCount(videoCount); + if (videoCount == 0) { + showEmptyState(); + } + //TODO: Do we have to show loading? + //hideLoading(); } private void deleteItem(final PlaylistStreamEntry item) { diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistManager.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistManager.java index 0752ab49d..f397be0df 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistManager.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistManager.java @@ -86,10 +86,9 @@ public class LocalPlaylistManager { return playlistStreamTable.getPlaylistMetadata().subscribeOn(Schedulers.io()); } - public Flowable> removeDuplicateStreams() { - // TODO: Delete Duplicates and rebuild the index - // TODO: Rebuild the index - return playlistStreamTable.getPlaylistMetadata().subscribeOn(Schedulers.io()); + public Flowable> getDistinctPlaylistStreams(final long playlistId) { + return playlistStreamTable + .getStreamsWithoutDuplicates(playlistId).subscribeOn(Schedulers.io()); } public Flowable> getPlaylistStreams(final long playlistId) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5d8ddb692..cdde2e5ee 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -627,6 +627,8 @@ Remove watched Remove watched videos? Remove duplicates + Remove duplicates? + Do you want to remove all duplicate streams in this playlist? Videos that have been watched before and after being added to the playlist will be removed. \nAre you sure\? This cannot be undone! Yes, and partially watched videos