From ac15339911a86399903c9bd974d6632c2b3088b6 Mon Sep 17 00:00:00 2001 From: Jared Fantaye Date: Sat, 10 Dec 2022 13:15:49 +0100 Subject: [PATCH] Started working on a way to show that items are already in a playlist --- .../playlist/dao/PlaylistStreamDAO.java | 8 +++++ .../newpipe/local/LocalItemListAdapter.java | 11 +++++++ .../local/dialog/PlaylistAppendDialog.java | 32 ++++++++++++++++++- .../local/playlist/LocalPlaylistManager.java | 4 +++ .../res/layout/list_playlist_mini_item.xml | 12 +++++++ 5 files changed, 66 insertions(+), 1 deletion(-) 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 911baf7f3..a9719c9fa 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 @@ -59,6 +59,14 @@ public interface PlaylistStreamDAO extends BasicDAO { ) Flowable getDuplicates(long playlistId, String streamURL); + @Query("SELECT " + JOIN_PLAYLIST_ID + + " FROM " + STREAM_TABLE + + " LEFT JOIN " + PLAYLIST_STREAM_JOIN_TABLE + + " ON " + STREAM_ID + " = " + JOIN_STREAM_ID + + " WHERE " + STREAM_URL + " = :streamURL" + ) + Flowable> getDuplicatePlaylists(String streamURL); + @Query("SELECT COALESCE(MAX(" + JOIN_INDEX + "), -1)" + " FROM " + PLAYLIST_STREAM_JOIN_TABLE diff --git a/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java b/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java index 05e2fdac0..93ea12b97 100644 --- a/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java @@ -11,6 +11,7 @@ import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; import org.schabi.newpipe.database.LocalItem; +import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry; import org.schabi.newpipe.database.stream.model.StreamStateEntity; import org.schabi.newpipe.local.history.HistoryRecordManager; import org.schabi.newpipe.local.holder.LocalItemHolder; @@ -344,6 +345,16 @@ public class LocalItemListAdapter extends RecyclerView.Adapter { final List entities = getStreamEntities(); if (selectedItem instanceof PlaylistMetadataEntry && entities != null) { @@ -123,6 +125,35 @@ public final class PlaylistAppendDialog extends PlaylistDialog { playlistAdapter.clearStreamItemList(); playlistAdapter.addItems(playlists); playlistRecyclerView.setVisibility(View.VISIBLE); + + final LocalPlaylistManager playlistManager = + new LocalPlaylistManager(NewPipeDatabase.getInstance(requireContext())); + final List duplicateIds = playlistManager.getDuplicatePlaylist(getStreamEntities() + .get(0).getUrl()).blockingFirst(); + + final HashMap map = new HashMap<>(); + for (int i = 0; i < playlists.size(); i++) { + map.put(i, playlists.get(i).uid); + } + + playlistRecyclerView.postDelayed(new Runnable() { + @Override + public void run() { + if (playlistRecyclerView.getAdapter() == null) { + return; + } + final int count = playlistRecyclerView.getAdapter().getItemCount(); + System.out.println(" kasjdflkalk" + playlistRecyclerView.getAdapter() + .getItemId(0)); + for (int i = 0; i < count; i++) { + if (playlistRecyclerView.findViewHolderForAdapterPosition(i) != null + && duplicateIds.contains(playlistAdapter.getItemId(i))) { + playlistRecyclerView.findViewHolderForAdapterPosition(i).itemView + .findViewById(R.id.checkmark2).setVisibility(View.VISIBLE); + } + } + } + }, 1000); } } @@ -163,7 +194,6 @@ public final class PlaylistAppendDialog extends PlaylistDialog { @NonNull final LocalPlaylistManager manager, @NonNull final PlaylistMetadataEntry playlist, @NonNull final List 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, 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 807c3c051..d017eac6c 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 @@ -95,6 +95,10 @@ public class LocalPlaylistManager { return playlistStreamTable.getDuplicates(playlistId, streamURL); } + public Flowable> getDuplicatePlaylist(final String streamURL) { + return playlistStreamTable.getDuplicatePlaylists(streamURL); + } + public Single deletePlaylist(final long playlistId) { return Single.fromCallable(() -> playlistTable.deletePlaylist(playlistId)) .subscribeOn(Schedulers.io()); diff --git a/app/src/main/res/layout/list_playlist_mini_item.xml b/app/src/main/res/layout/list_playlist_mini_item.xml index a1f70144d..1b7065f23 100644 --- a/app/src/main/res/layout/list_playlist_mini_item.xml +++ b/app/src/main/res/layout/list_playlist_mini_item.xml @@ -1,5 +1,6 @@ + + +