Implemented the "remove duplicates" feature.
This commit is contained in:
parent
eb3363d4dd
commit
135fc08212
|
@ -84,14 +84,22 @@ public interface PlaylistStreamDAO extends BasicDAO<PlaylistStreamEntity> {
|
||||||
+ " ORDER BY " + PLAYLIST_NAME + " COLLATE NOCASE ASC")
|
+ " ORDER BY " + PLAYLIST_NAME + " COLLATE NOCASE ASC")
|
||||||
Flowable<List<PlaylistMetadataEntry>> getPlaylistMetadata();
|
Flowable<List<PlaylistMetadataEntry>> getPlaylistMetadata();
|
||||||
|
|
||||||
|
@RewriteQueriesToDropUnusedColumns
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("DELETE FROM " + PLAYLIST_STREAM_JOIN_TABLE
|
@Query("SELECT *, MIN(" + JOIN_INDEX + ") FROM " + STREAM_TABLE + " INNER JOIN "
|
||||||
+ " WHERE " + JOIN_PLAYLIST_ID + "=:playlistId"
|
+ "(SELECT " + JOIN_STREAM_ID + "," + JOIN_INDEX
|
||||||
+ " AND " + JOIN_STREAM_ID + " IN ("
|
|
||||||
+ " SELECT " + JOIN_STREAM_ID
|
|
||||||
+ " FROM " + PLAYLIST_STREAM_JOIN_TABLE
|
+ " FROM " + PLAYLIST_STREAM_JOIN_TABLE
|
||||||
+ " WHERE " + JOIN_PLAYLIST_ID + "=:playlistId"
|
+ " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId)"
|
||||||
+ " GROUP BY " + JOIN_STREAM_ID
|
+ " ON " + STREAM_ID + " = " + JOIN_STREAM_ID
|
||||||
+ " HAVING COUNT(*) > 1 )" )
|
+ " LEFT JOIN "
|
||||||
Flowable<List<PlaylistMetadataEntry>> removeDuplicates(long playlistId);
|
+ "(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<List<PlaylistStreamEntry>> getStreamsWithoutDuplicates(long playlistId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -627,8 +627,8 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
||||||
private void openRemoveDuplicatesDialog() {
|
private void openRemoveDuplicatesDialog() {
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
|
||||||
|
|
||||||
builder.setTitle("R.string.duplicate_stream_in_playlist_title")
|
builder.setTitle(R.string.remove_duplicates_title)
|
||||||
.setMessage("test")
|
.setMessage(R.string.remove_duplicates_message)
|
||||||
.setPositiveButton(android.R.string.yes, (dialog, i) -> {
|
.setPositiveButton(android.R.string.yes, (dialog, i) -> {
|
||||||
removeDuplicatesInPlaylist();
|
removeDuplicatesInPlaylist();
|
||||||
})
|
})
|
||||||
|
@ -638,7 +638,20 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeDuplicatesInPlaylist() {
|
private void removeDuplicatesInPlaylist() {
|
||||||
|
final List<PlaylistStreamEntry> 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) {
|
private void deleteItem(final PlaylistStreamEntry item) {
|
||||||
|
|
|
@ -86,10 +86,9 @@ public class LocalPlaylistManager {
|
||||||
return playlistStreamTable.getPlaylistMetadata().subscribeOn(Schedulers.io());
|
return playlistStreamTable.getPlaylistMetadata().subscribeOn(Schedulers.io());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Flowable<List<PlaylistMetadataEntry>> removeDuplicateStreams() {
|
public Flowable<List<PlaylistStreamEntry>> getDistinctPlaylistStreams(final long playlistId) {
|
||||||
// TODO: Delete Duplicates and rebuild the index
|
return playlistStreamTable
|
||||||
// TODO: Rebuild the index
|
.getStreamsWithoutDuplicates(playlistId).subscribeOn(Schedulers.io());
|
||||||
return playlistStreamTable.getPlaylistMetadata().subscribeOn(Schedulers.io());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Flowable<List<PlaylistStreamEntry>> getPlaylistStreams(final long playlistId) {
|
public Flowable<List<PlaylistStreamEntry>> getPlaylistStreams(final long playlistId) {
|
||||||
|
|
|
@ -627,6 +627,8 @@
|
||||||
<string name="remove_watched">Remove watched</string>
|
<string name="remove_watched">Remove watched</string>
|
||||||
<string name="remove_watched_popup_title">Remove watched videos?</string>
|
<string name="remove_watched_popup_title">Remove watched videos?</string>
|
||||||
<string name="remove_duplicates">Remove duplicates</string>
|
<string name="remove_duplicates">Remove duplicates</string>
|
||||||
|
<string name="remove_duplicates_title">Remove duplicates?</string>
|
||||||
|
<string name="remove_duplicates_message">Do you want to remove all duplicate streams in this playlist?</string>
|
||||||
<string name="remove_watched_popup_warning">Videos that have been watched before and after being added to the playlist will be removed.
|
<string name="remove_watched_popup_warning">Videos that have been watched before and after being added to the playlist will be removed.
|
||||||
\nAre you sure\? This cannot be undone!</string>
|
\nAre you sure\? This cannot be undone!</string>
|
||||||
<string name="remove_watched_popup_yes_and_partially_watched_videos">Yes, and partially watched videos</string>
|
<string name="remove_watched_popup_yes_and_partially_watched_videos">Yes, and partially watched videos</string>
|
||||||
|
|
Loading…
Reference in New Issue