mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2025-10-06 03:50:22 +02:00
Started working on a way to show that items are already in a playlist
This commit is contained in:
parent
fdfeac081a
commit
ac15339911
5 changed files with 66 additions and 1 deletions
|
@ -59,6 +59,14 @@ public interface PlaylistStreamDAO extends BasicDAO<PlaylistStreamEntity> {
|
|||
)
|
||||
Flowable<Integer> 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<List<Long>> getDuplicatePlaylists(String streamURL);
|
||||
|
||||
|
||||
@Query("SELECT COALESCE(MAX(" + JOIN_INDEX + "), -1)"
|
||||
+ " FROM " + PLAYLIST_STREAM_JOIN_TABLE
|
||||
|
|
|
@ -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<RecyclerView.View
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(final int position) {
|
||||
final LocalItem item = localItems.get(0);
|
||||
if (item != null && item.getLocalItemType() == LocalItem.LocalItemType.
|
||||
PLAYLIST_LOCAL_ITEM) {
|
||||
return ((PlaylistMetadataEntry) item).uid;
|
||||
}
|
||||
return super.getItemId(position);
|
||||
}
|
||||
|
||||
public GridLayoutManager.SpanSizeLookup getSpanSizeLookup(final int spanCount) {
|
||||
return new GridLayoutManager.SpanSizeLookup() {
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.schabi.newpipe.database.stream.model.StreamEntity;
|
|||
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;
|
||||
|
@ -62,6 +63,7 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
|
|||
new LocalPlaylistManager(NewPipeDatabase.getInstance(requireContext()));
|
||||
|
||||
playlistAdapter = new LocalItemListAdapter(getActivity());
|
||||
playlistAdapter.setHasStableIds(true);
|
||||
playlistAdapter.setSelectedListener(selectedItem -> {
|
||||
final List<StreamEntity> 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<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) {
|
||||
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<StreamEntity> 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,
|
||||
|
|
|
@ -95,6 +95,10 @@ public class LocalPlaylistManager {
|
|||
return playlistStreamTable.getDuplicates(playlistId, streamURL);
|
||||
}
|
||||
|
||||
public Flowable<List<Long>> getDuplicatePlaylist(final String streamURL) {
|
||||
return playlistStreamTable.getDuplicatePlaylists(streamURL);
|
||||
}
|
||||
|
||||
public Single<Integer> deletePlaylist(final long playlistId) {
|
||||
return Single.fromCallable(() -> playlistTable.deletePlaylist(playlistId))
|
||||
.subscribeOn(Schedulers.io());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue