Fixed the functionality, improved performance & general code cleanup
This commit is contained in:
parent
f5a1f915be
commit
8b6e110635
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,11 +34,26 @@
|
|||
tools:ignore="RtlHardcoded" />
|
||||
</RelativeLayout>
|
||||
|
||||
<org.schabi.newpipe.views.NewPipeTextView
|
||||
android:id="@+id/playlist_duplicate"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:layout_below="@+id/newPlaylist"
|
||||
android:text="@string/duplicate_in_playlist"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:textSize="15sp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:inputType="textMultiLine"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginBottom="@dimen/video_item_search_padding"
|
||||
android:visibility="gone" />
|
||||
|
||||
<View
|
||||
android:id="@+id/separator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_below="@+id/newPlaylist"
|
||||
android:layout_below="@+id/playlist_duplicate"
|
||||
android:layout_marginLeft="@dimen/video_item_search_padding"
|
||||
android:layout_marginRight="@dimen/video_item_search_padding"
|
||||
android:background="?attr/separator_color" />
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/itemRoot"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -22,17 +21,6 @@
|
|||
android:src="@drawable/placeholder_thumbnail_playlist"
|
||||
tools:ignore="RtlHardcoded" />
|
||||
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/checkmark2"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_alignBottom="@id/itemThumbnailView"
|
||||
android:layout_marginBottom="-1dp"
|
||||
android:src="@drawable/ic_done"
|
||||
android:visibility="gone"
|
||||
app:tint="#E81111" />
|
||||
|
||||
<org.schabi.newpipe.views.NewPipeTextView
|
||||
android:id="@+id/itemStreamCountView"
|
||||
android:layout_width="45dp"
|
||||
|
|
|
@ -432,6 +432,7 @@
|
|||
<string name="preferred_player_fetcher_notification_message">"Loading requested content"</string>
|
||||
<!-- Local Playlist -->
|
||||
<string name="create_playlist">New Playlist</string>
|
||||
<string name="duplicate_in_playlist">The playlists that are grayed out already contain this item.</string>
|
||||
<string name="rename_playlist">Rename</string>
|
||||
<string name="name">Name</string>
|
||||
<string name="add_to_playlist">Add to playlist</string>
|
||||
|
|
Loading…
Reference in New Issue