mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 15:23:00 +00:00 
			
		
		
		
	Fixed the functionality, improved performance & general code cleanup
This commit is contained in:
		| @@ -57,7 +57,7 @@ public interface PlaylistStreamDAO extends BasicDAO<PlaylistStreamEntity> { | ||||
|             + " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId " | ||||
|             + " AND " + STREAM_URL + " = :streamURL" | ||||
|     ) | ||||
|     Flowable<Integer> getDuplicates(long playlistId, String streamURL); | ||||
|     Flowable<Integer> getDuplicateCount(long playlistId, String streamURL); | ||||
|  | ||||
|     @Query("SELECT " + JOIN_PLAYLIST_ID | ||||
|             + " FROM " + STREAM_TABLE | ||||
| @@ -67,7 +67,6 @@ public interface PlaylistStreamDAO extends BasicDAO<PlaylistStreamEntity> { | ||||
|     ) | ||||
|     Flowable<List<Long>> getDuplicatePlaylists(String streamURL); | ||||
|  | ||||
|  | ||||
|     @Query("SELECT COALESCE(MAX(" + JOIN_INDEX + "), -1)" | ||||
|             + " FROM " + PLAYLIST_STREAM_JOIN_TABLE | ||||
|             + " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId") | ||||
|   | ||||
| @@ -16,7 +16,6 @@ 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; | ||||
|  | ||||
| @@ -28,8 +27,12 @@ import io.reactivex.rxjava3.disposables.CompositeDisposable; | ||||
| public final class PlaylistAppendDialog extends PlaylistDialog { | ||||
|     private static final String TAG = PlaylistAppendDialog.class.getCanonicalName(); | ||||
|  | ||||
|     private static final float DEFAULT_ALPHA = 1f; | ||||
|     private static final float GRAYED_OUT_ALPHA = 0.3f; | ||||
|  | ||||
|     private RecyclerView playlistRecyclerView; | ||||
|     private LocalItemListAdapter playlistAdapter; | ||||
|     private List<Long> duplicateIds; | ||||
|  | ||||
|     private final CompositeDisposable playlistDisposables = new CompositeDisposable(); | ||||
|  | ||||
| @@ -62,6 +65,9 @@ public final class PlaylistAppendDialog extends PlaylistDialog { | ||||
|         final LocalPlaylistManager playlistManager = | ||||
|                 new LocalPlaylistManager(NewPipeDatabase.getInstance(requireContext())); | ||||
|  | ||||
|         duplicateIds = playlistManager.getDuplicatePlaylists(getStreamEntities().get(0).getUrl()) | ||||
|                 .blockingFirst(); | ||||
|  | ||||
|         playlistAdapter = new LocalItemListAdapter(getActivity()); | ||||
|         playlistAdapter.setHasStableIds(true); | ||||
|         playlistAdapter.setSelectedListener(selectedItem -> { | ||||
| @@ -126,43 +132,43 @@ public final class PlaylistAppendDialog extends PlaylistDialog { | ||||
|             playlistAdapter.addItems(playlists); | ||||
|             playlistRecyclerView.setVisibility(View.VISIBLE); | ||||
|  | ||||
|             playlistRecyclerView.addOnScrollListener(new DefaultItemListOnScrolledDownListener()); | ||||
|             playlistRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { | ||||
|                 @Override | ||||
|                 public void onScrolled(@NonNull final RecyclerView recyclerView, final int dx, | ||||
|                                        final int dy) { | ||||
|                     showDuplicateIndicators(recyclerView); | ||||
|                 } | ||||
|             }); | ||||
|             initDuplicateIndicators(playlistRecyclerView); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public class DefaultItemListOnScrolledDownListener extends OnScrollBelowItemsListener { | ||||
|         @Override | ||||
|         public void onScrolledDown(final RecyclerView recyclerView) { | ||||
|             showDuplicateIndicators(recyclerView); | ||||
|     public void initDuplicateIndicators(@NonNull final RecyclerView view) { | ||||
|         showDuplicateIndicators(view); | ||||
|  | ||||
|         if (!duplicateIds.isEmpty()) { | ||||
|             final View indicatorExplanation = getView() | ||||
|                     .findViewById(R.id.playlist_duplicate); | ||||
|             indicatorExplanation.setVisibility(View.VISIBLE); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     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(); | ||||
|  | ||||
|     public void showDuplicateIndicators(@NonNull final RecyclerView view) { | ||||
|         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); | ||||
|  | ||||
|             final RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(i); | ||||
|             if (viewHolder != null) { | ||||
|                 if (duplicateIds.contains(view.getAdapter().getItemId(i))) { | ||||
|                     viewHolder.itemView.setAlpha(GRAYED_OUT_ALPHA); | ||||
|                 } else { | ||||
|                     viewHolder.itemView.setAlpha(DEFAULT_ALPHA); | ||||
|                 } | ||||
|  | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| @@ -171,10 +177,10 @@ public final class PlaylistAppendDialog extends PlaylistDialog { | ||||
|                                     @NonNull final PlaylistMetadataEntry playlist, | ||||
|                                     @NonNull final List<StreamEntity> streams) { | ||||
|  | ||||
|         final int numOfDuplicates = manager.getPlaylistDuplicates(playlist.uid, | ||||
|         final int numberOfDuplicates = manager.getPlaylistDuplicateCount(playlist.uid, | ||||
|                         streams.get(0).getUrl()).blockingFirst(); | ||||
|         if (numOfDuplicates > 0) { | ||||
|             createDuplicateDialog(numOfDuplicates, manager, playlist, streams); | ||||
|         if (numberOfDuplicates > 0) { | ||||
|             createDuplicateDialog(numberOfDuplicates, manager, playlist, streams); | ||||
|         } else { | ||||
|             addStreamToPlaylist(manager, playlist, streams); | ||||
|         } | ||||
| @@ -197,22 +203,24 @@ public final class PlaylistAppendDialog extends PlaylistDialog { | ||||
|         playlistDisposables.add(manager.appendToPlaylist(playlist.uid, streams) | ||||
|                 .observeOn(AndroidSchedulers.mainThread()) | ||||
|                 .subscribe(ignored -> successToast.show())); | ||||
|  | ||||
|         requireDialog().dismiss(); | ||||
|     } | ||||
|  | ||||
|     private void createDuplicateDialog(final int duplicates, | ||||
|     private void createDuplicateDialog(final int numberOfDuplicates, | ||||
|                                        @NonNull final LocalPlaylistManager manager, | ||||
|                                        @NonNull final PlaylistMetadataEntry playlist, | ||||
|                                        @NonNull final List<StreamEntity> streams) { | ||||
|         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, | ||||
|                 duplicates)); | ||||
|                 numberOfDuplicates)); | ||||
|  | ||||
|         builder.setPositiveButton(android.R.string.yes, (dialog, i) -> { | ||||
|             addStreamToPlaylist(manager, playlist, streams); | ||||
|         }); | ||||
|         builder.setNeutralButton(R.string.cancel, null); | ||||
|  | ||||
|         builder.create().show(); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -91,11 +91,12 @@ public class LocalPlaylistManager { | ||||
|         return playlistStreamTable.getOrderedStreamsOf(playlistId).subscribeOn(Schedulers.io()); | ||||
|     } | ||||
|  | ||||
|     public Flowable<Integer> getPlaylistDuplicates(final long playlistId, final String streamURL) { | ||||
|         return playlistStreamTable.getDuplicates(playlistId, streamURL); | ||||
|     public Flowable<Integer> getPlaylistDuplicateCount(final long playlistId, | ||||
|                                                        final String streamURL) { | ||||
|         return playlistStreamTable.getDuplicateCount(playlistId, streamURL); | ||||
|     } | ||||
|  | ||||
|     public Flowable<List<Long>> getDuplicatePlaylist(final String streamURL) { | ||||
|     public Flowable<List<Long>> getDuplicatePlaylists(final String streamURL) { | ||||
|         return playlistStreamTable.getDuplicatePlaylists(streamURL); | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jared Fantaye
					Jared Fantaye