Skip to content

Commit ac15339

Browse files
Jared234Stypox
authored andcommitted
Started working on a way to show that items are already in a playlist
1 parent fdfeac0 commit ac15339

5 files changed

Lines changed: 66 additions & 1 deletion

File tree

app/src/main/java/org/schabi/newpipe/database/playlist/dao/PlaylistStreamDAO.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ default Flowable<List<PlaylistStreamEntity>> listByService(final int serviceId)
5959
)
6060
Flowable<Integer> getDuplicates(long playlistId, String streamURL);
6161

62+
@Query("SELECT " + JOIN_PLAYLIST_ID
63+
+ " FROM " + STREAM_TABLE
64+
+ " LEFT JOIN " + PLAYLIST_STREAM_JOIN_TABLE
65+
+ " ON " + STREAM_ID + " = " + JOIN_STREAM_ID
66+
+ " WHERE " + STREAM_URL + " = :streamURL"
67+
)
68+
Flowable<List<Long>> getDuplicatePlaylists(String streamURL);
69+
6270

6371
@Query("SELECT COALESCE(MAX(" + JOIN_INDEX + "), -1)"
6472
+ " FROM " + PLAYLIST_STREAM_JOIN_TABLE

app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import androidx.recyclerview.widget.RecyclerView;
1212

1313
import org.schabi.newpipe.database.LocalItem;
14+
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
1415
import org.schabi.newpipe.database.stream.model.StreamStateEntity;
1516
import org.schabi.newpipe.local.history.HistoryRecordManager;
1617
import org.schabi.newpipe.local.holder.LocalItemHolder;
@@ -344,6 +345,16 @@ public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, fina
344345
}
345346
}
346347

348+
@Override
349+
public long getItemId(final int position) {
350+
final LocalItem item = localItems.get(0);
351+
if (item != null && item.getLocalItemType() == LocalItem.LocalItemType.
352+
PLAYLIST_LOCAL_ITEM) {
353+
return ((PlaylistMetadataEntry) item).uid;
354+
}
355+
return super.getItemId(position);
356+
}
357+
347358
public GridLayoutManager.SpanSizeLookup getSpanSizeLookup(final int spanCount) {
348359
return new GridLayoutManager.SpanSizeLookup() {
349360
@Override

app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.schabi.newpipe.local.LocalItemListAdapter;
2020
import org.schabi.newpipe.local.playlist.LocalPlaylistManager;
2121

22+
import java.util.HashMap;
2223
import java.util.List;
2324

2425
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
@@ -62,6 +63,7 @@ public void onViewCreated(@NonNull final View view, @Nullable final Bundle saved
6263
new LocalPlaylistManager(NewPipeDatabase.getInstance(requireContext()));
6364

6465
playlistAdapter = new LocalItemListAdapter(getActivity());
66+
playlistAdapter.setHasStableIds(true);
6567
playlistAdapter.setSelectedListener(selectedItem -> {
6668
final List<StreamEntity> entities = getStreamEntities();
6769
if (selectedItem instanceof PlaylistMetadataEntry && entities != null) {
@@ -123,6 +125,35 @@ private void onPlaylistsReceived(@NonNull final List<PlaylistMetadataEntry> play
123125
playlistAdapter.clearStreamItemList();
124126
playlistAdapter.addItems(playlists);
125127
playlistRecyclerView.setVisibility(View.VISIBLE);
128+
129+
final LocalPlaylistManager playlistManager =
130+
new LocalPlaylistManager(NewPipeDatabase.getInstance(requireContext()));
131+
final List<Long> duplicateIds = playlistManager.getDuplicatePlaylist(getStreamEntities()
132+
.get(0).getUrl()).blockingFirst();
133+
134+
final HashMap<Integer, Long> map = new HashMap<>();
135+
for (int i = 0; i < playlists.size(); i++) {
136+
map.put(i, playlists.get(i).uid);
137+
}
138+
139+
playlistRecyclerView.postDelayed(new Runnable() {
140+
@Override
141+
public void run() {
142+
if (playlistRecyclerView.getAdapter() == null) {
143+
return;
144+
}
145+
final int count = playlistRecyclerView.getAdapter().getItemCount();
146+
System.out.println(" kasjdflkalk" + playlistRecyclerView.getAdapter()
147+
.getItemId(0));
148+
for (int i = 0; i < count; i++) {
149+
if (playlistRecyclerView.findViewHolderForAdapterPosition(i) != null
150+
&& duplicateIds.contains(playlistAdapter.getItemId(i))) {
151+
playlistRecyclerView.findViewHolderForAdapterPosition(i).itemView
152+
.findViewById(R.id.checkmark2).setVisibility(View.VISIBLE);
153+
}
154+
}
155+
}
156+
}, 1000);
126157
}
127158
}
128159

@@ -163,7 +194,6 @@ private void createDuplicateDialog(final int duplicates,
163194
@NonNull final LocalPlaylistManager manager,
164195
@NonNull final PlaylistMetadataEntry playlist,
165196
@NonNull final List<StreamEntity> streams) {
166-
//TODO: change color
167197
final AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
168198
builder.setTitle(R.string.duplicate_stream_in_playlist_title);
169199
builder.setMessage(getString(R.string.duplicate_stream_in_playlist_description,

app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public Flowable<Integer> getPlaylistDuplicates(final long playlistId, final Stri
9595
return playlistStreamTable.getDuplicates(playlistId, streamURL);
9696
}
9797

98+
public Flowable<List<Long>> getDuplicatePlaylist(final String streamURL) {
99+
return playlistStreamTable.getDuplicatePlaylists(streamURL);
100+
}
101+
98102
public Single<Integer> deletePlaylist(final long playlistId) {
99103
return Single.fromCallable(() -> playlistTable.deletePlaylist(playlistId))
100104
.subscribeOn(Schedulers.io());

app/src/main/res/layout/list_playlist_mini_item.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
34
xmlns:tools="http://schemas.android.com/tools"
45
android:id="@+id/itemRoot"
56
android:layout_width="match_parent"
@@ -21,6 +22,17 @@
2122
android:src="@drawable/placeholder_thumbnail_playlist"
2223
tools:ignore="RtlHardcoded" />
2324

25+
26+
<ImageView
27+
android:id="@+id/checkmark2"
28+
android:layout_width="20dp"
29+
android:layout_height="20dp"
30+
android:layout_alignBottom="@id/itemThumbnailView"
31+
android:layout_marginBottom="-1dp"
32+
android:src="@drawable/ic_done"
33+
android:visibility="gone"
34+
app:tint="#E81111" />
35+
2436
<org.schabi.newpipe.views.NewPipeTextView
2537
android:id="@+id/itemStreamCountView"
2638
android:layout_width="45dp"

0 commit comments

Comments
 (0)