From 102975aeb3fabb18f2a87811d51aef463b30c5a0 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 29 Jan 2023 10:32:32 +0100 Subject: [PATCH] Improve handling playlist duplicate indicator --- .../local/dialog/PlaylistAppendDialog.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java b/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java index b45f6bd9c..5aeca06ed 100644 --- a/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java +++ b/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java @@ -4,6 +4,7 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; @@ -28,6 +29,7 @@ public final class PlaylistAppendDialog extends PlaylistDialog { private RecyclerView playlistRecyclerView; private LocalItemListAdapter playlistAdapter; + private TextView playlistDuplicateIndicator; private final CompositeDisposable playlistDisposables = new CompositeDisposable(); @@ -73,6 +75,8 @@ public final class PlaylistAppendDialog extends PlaylistDialog { playlistRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext())); playlistRecyclerView.setAdapter(playlistAdapter); + playlistDuplicateIndicator = view.findViewById(R.id.playlist_duplicate); + final View newPlaylistButton = view.findViewById(R.id.newPlaylist); newPlaylistButton.setOnClickListener(ignored -> openCreatePlaylistDialog()); @@ -120,23 +124,20 @@ public final class PlaylistAppendDialog extends PlaylistDialog { } private void onPlaylistsReceived(@NonNull final List playlists) { - if (playlistAdapter != null && playlistRecyclerView != null) { + if (playlistAdapter != null + && playlistRecyclerView != null + && playlistDuplicateIndicator != null) { playlistAdapter.clearStreamItemList(); playlistAdapter.addItems(playlists); playlistRecyclerView.setVisibility(View.VISIBLE); - setDuplicateIndicatorExplanation(playlists); + playlistDuplicateIndicator.setVisibility( + anyPlaylistContainsDuplicates(playlists) ? View.VISIBLE : View.GONE); } } - private void setDuplicateIndicatorExplanation(final List playlists) { - for (final PlaylistDuplicatesEntry entry : playlists) { - if (entry.timesStreamIsContained > 0) { - final View indicatorExplanation = getView() - .findViewById(R.id.playlist_duplicate); - indicatorExplanation.setVisibility(View.VISIBLE); - return; - } - } + private boolean anyPlaylistContainsDuplicates(final List playlists) { + return playlists.stream() + .anyMatch(playlist -> playlist.timesStreamIsContained > 0); } private void onPlaylistSelected(@NonNull final LocalPlaylistManager manager,