Continued working on a way to show that items are already in a playlist
This commit is contained in:
parent
ac15339911
commit
f5a1f915be
2 changed files with 37 additions and 27 deletions
|
@ -347,7 +347,7 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
|
||||
@Override
|
||||
public long getItemId(final int position) {
|
||||
final LocalItem item = localItems.get(0);
|
||||
final LocalItem item = localItems.get(position);
|
||||
if (item != null && item.getLocalItemType() == LocalItem.LocalItemType.
|
||||
PLAYLIST_LOCAL_ITEM) {
|
||||
return ((PlaylistMetadataEntry) item).uid;
|
||||
|
|
|
@ -16,10 +16,10 @@ import org.schabi.newpipe.NewPipeDatabase;
|
|||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
|
||||
import org.schabi.newpipe.database.stream.model.StreamEntity;
|
||||
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
|
||||
import org.schabi.newpipe.local.LocalItemListAdapter;
|
||||
import org.schabi.newpipe.local.playlist.LocalPlaylistManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
|
@ -126,36 +126,46 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
|
|||
playlistAdapter.addItems(playlists);
|
||||
playlistRecyclerView.setVisibility(View.VISIBLE);
|
||||
|
||||
playlistRecyclerView.addOnScrollListener(new DefaultItemListOnScrolledDownListener());
|
||||
initDuplicateIndicators(playlistRecyclerView);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void showDuplicateIndicators(final RecyclerView view) {
|
||||
final LocalPlaylistManager playlistManager =
|
||||
new LocalPlaylistManager(NewPipeDatabase.getInstance(requireContext()));
|
||||
final List<Long> duplicateIds = playlistManager.getDuplicatePlaylist(getStreamEntities()
|
||||
.get(0).getUrl()).blockingFirst();
|
||||
|
||||
final HashMap<Integer, Long> 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) {
|
||||
if (view.getAdapter() == null) {
|
||||
return;
|
||||
}
|
||||
final int count = playlistRecyclerView.getAdapter().getItemCount();
|
||||
System.out.println(" kasjdflkalk" + playlistRecyclerView.getAdapter()
|
||||
.getItemId(0));
|
||||
|
||||
final int count = view.getAdapter().getItemCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (playlistRecyclerView.findViewHolderForAdapterPosition(i) != null
|
||||
if (view.findViewHolderForAdapterPosition(i) != null
|
||||
&& duplicateIds.contains(playlistAdapter.getItemId(i))) {
|
||||
playlistRecyclerView.findViewHolderForAdapterPosition(i).itemView
|
||||
view.findViewHolderForAdapterPosition(i).itemView
|
||||
.findViewById(R.id.checkmark2).setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
private void onPlaylistSelected(@NonNull final LocalPlaylistManager manager,
|
||||
@NonNull final PlaylistMetadataEntry playlist,
|
||||
|
|
Loading…
Reference in a new issue