From f5a1f915becbbe2326fdeb0ccb96811d161774f6 Mon Sep 17 00:00:00 2001 From: Jared Fantaye Date: Sat, 10 Dec 2022 16:54:46 +0100 Subject: [PATCH] Continued working on a way to show that items are already in a playlist --- .../newpipe/local/LocalItemListAdapter.java | 2 +- .../local/dialog/PlaylistAppendDialog.java | 62 +++++++++++-------- 2 files changed, 37 insertions(+), 27 deletions(-) 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 93ea12b97..ea7bc290d 100644 --- a/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java @@ -347,7 +347,7 @@ public class LocalItemListAdapter extends RecyclerView.Adapter duplicateIds = playlistManager.getDuplicatePlaylist(getStreamEntities() - .get(0).getUrl()).blockingFirst(); + playlistRecyclerView.addOnScrollListener(new DefaultItemListOnScrolledDownListener()); + initDuplicateIndicators(playlistRecyclerView); + } + } - final HashMap map = new HashMap<>(); - for (int i = 0; i < playlists.size(); i++) { - map.put(i, playlists.get(i).uid); + public class DefaultItemListOnScrolledDownListener extends OnScrollBelowItemsListener { + @Override + public void onScrolledDown(final RecyclerView recyclerView) { + showDuplicateIndicators(recyclerView); + } + } + + public void initDuplicateIndicators(@NonNull final RecyclerView view) { + view.postDelayed(new Runnable() { + @Override + public void run() { + showDuplicateIndicators(view); } + }, 50); + } - 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); + public void showDuplicateIndicators(final RecyclerView view) { + final LocalPlaylistManager playlistManager = + new LocalPlaylistManager(NewPipeDatabase.getInstance(requireContext())); + final List duplicateIds = playlistManager.getDuplicatePlaylist(getStreamEntities() + .get(0).getUrl()).blockingFirst(); + + if (view.getAdapter() == null) { + return; + } + + final int count = view.getAdapter().getItemCount(); + for (int i = 0; i < count; i++) { + if (view.findViewHolderForAdapterPosition(i) != null + && duplicateIds.contains(playlistAdapter.getItemId(i))) { + view.findViewHolderForAdapterPosition(i).itemView + .findViewById(R.id.checkmark2).setVisibility(View.VISIBLE); + } } }