Fixed the functionality, improved performance & general code cleanup
This commit is contained in:
parent
f5a1f915be
commit
8b6e110635
6 changed files with 60 additions and 48 deletions
|
@ -57,7 +57,7 @@ public interface PlaylistStreamDAO extends BasicDAO<PlaylistStreamEntity> {
|
||||||
+ " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId "
|
+ " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId "
|
||||||
+ " AND " + STREAM_URL + " = :streamURL"
|
+ " AND " + STREAM_URL + " = :streamURL"
|
||||||
)
|
)
|
||||||
Flowable<Integer> getDuplicates(long playlistId, String streamURL);
|
Flowable<Integer> getDuplicateCount(long playlistId, String streamURL);
|
||||||
|
|
||||||
@Query("SELECT " + JOIN_PLAYLIST_ID
|
@Query("SELECT " + JOIN_PLAYLIST_ID
|
||||||
+ " FROM " + STREAM_TABLE
|
+ " FROM " + STREAM_TABLE
|
||||||
|
@ -67,7 +67,6 @@ public interface PlaylistStreamDAO extends BasicDAO<PlaylistStreamEntity> {
|
||||||
)
|
)
|
||||||
Flowable<List<Long>> getDuplicatePlaylists(String streamURL);
|
Flowable<List<Long>> getDuplicatePlaylists(String streamURL);
|
||||||
|
|
||||||
|
|
||||||
@Query("SELECT COALESCE(MAX(" + JOIN_INDEX + "), -1)"
|
@Query("SELECT COALESCE(MAX(" + JOIN_INDEX + "), -1)"
|
||||||
+ " FROM " + PLAYLIST_STREAM_JOIN_TABLE
|
+ " FROM " + PLAYLIST_STREAM_JOIN_TABLE
|
||||||
+ " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId")
|
+ " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId")
|
||||||
|
|
|
@ -16,7 +16,6 @@ import org.schabi.newpipe.NewPipeDatabase;
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
|
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
|
||||||
import org.schabi.newpipe.database.stream.model.StreamEntity;
|
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.LocalItemListAdapter;
|
||||||
import org.schabi.newpipe.local.playlist.LocalPlaylistManager;
|
import org.schabi.newpipe.local.playlist.LocalPlaylistManager;
|
||||||
|
|
||||||
|
@ -28,8 +27,12 @@ import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||||
public final class PlaylistAppendDialog extends PlaylistDialog {
|
public final class PlaylistAppendDialog extends PlaylistDialog {
|
||||||
private static final String TAG = PlaylistAppendDialog.class.getCanonicalName();
|
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 RecyclerView playlistRecyclerView;
|
||||||
private LocalItemListAdapter playlistAdapter;
|
private LocalItemListAdapter playlistAdapter;
|
||||||
|
private List<Long> duplicateIds;
|
||||||
|
|
||||||
private final CompositeDisposable playlistDisposables = new CompositeDisposable();
|
private final CompositeDisposable playlistDisposables = new CompositeDisposable();
|
||||||
|
|
||||||
|
@ -62,6 +65,9 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
|
||||||
final LocalPlaylistManager playlistManager =
|
final LocalPlaylistManager playlistManager =
|
||||||
new LocalPlaylistManager(NewPipeDatabase.getInstance(requireContext()));
|
new LocalPlaylistManager(NewPipeDatabase.getInstance(requireContext()));
|
||||||
|
|
||||||
|
duplicateIds = playlistManager.getDuplicatePlaylists(getStreamEntities().get(0).getUrl())
|
||||||
|
.blockingFirst();
|
||||||
|
|
||||||
playlistAdapter = new LocalItemListAdapter(getActivity());
|
playlistAdapter = new LocalItemListAdapter(getActivity());
|
||||||
playlistAdapter.setHasStableIds(true);
|
playlistAdapter.setHasStableIds(true);
|
||||||
playlistAdapter.setSelectedListener(selectedItem -> {
|
playlistAdapter.setSelectedListener(selectedItem -> {
|
||||||
|
@ -126,43 +132,43 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
|
||||||
playlistAdapter.addItems(playlists);
|
playlistAdapter.addItems(playlists);
|
||||||
playlistRecyclerView.setVisibility(View.VISIBLE);
|
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);
|
initDuplicateIndicators(playlistRecyclerView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DefaultItemListOnScrolledDownListener extends OnScrollBelowItemsListener {
|
|
||||||
@Override
|
|
||||||
public void onScrolledDown(final RecyclerView recyclerView) {
|
|
||||||
showDuplicateIndicators(recyclerView);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initDuplicateIndicators(@NonNull final RecyclerView view) {
|
public void initDuplicateIndicators(@NonNull final RecyclerView view) {
|
||||||
view.postDelayed(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
showDuplicateIndicators(view);
|
showDuplicateIndicators(view);
|
||||||
|
|
||||||
|
if (!duplicateIds.isEmpty()) {
|
||||||
|
final View indicatorExplanation = getView()
|
||||||
|
.findViewById(R.id.playlist_duplicate);
|
||||||
|
indicatorExplanation.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}, 50);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDuplicateIndicators(final RecyclerView view) {
|
public void showDuplicateIndicators(@NonNull final RecyclerView view) {
|
||||||
final LocalPlaylistManager playlistManager =
|
|
||||||
new LocalPlaylistManager(NewPipeDatabase.getInstance(requireContext()));
|
|
||||||
final List<Long> duplicateIds = playlistManager.getDuplicatePlaylist(getStreamEntities()
|
|
||||||
.get(0).getUrl()).blockingFirst();
|
|
||||||
|
|
||||||
if (view.getAdapter() == null) {
|
if (view.getAdapter() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int count = view.getAdapter().getItemCount();
|
final int count = view.getAdapter().getItemCount();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (view.findViewHolderForAdapterPosition(i) != null
|
|
||||||
&& duplicateIds.contains(playlistAdapter.getItemId(i))) {
|
final RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(i);
|
||||||
view.findViewHolderForAdapterPosition(i).itemView
|
if (viewHolder != null) {
|
||||||
.findViewById(R.id.checkmark2).setVisibility(View.VISIBLE);
|
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 PlaylistMetadataEntry playlist,
|
||||||
@NonNull final List<StreamEntity> streams) {
|
@NonNull final List<StreamEntity> streams) {
|
||||||
|
|
||||||
final int numOfDuplicates = manager.getPlaylistDuplicates(playlist.uid,
|
final int numberOfDuplicates = manager.getPlaylistDuplicateCount(playlist.uid,
|
||||||
streams.get(0).getUrl()).blockingFirst();
|
streams.get(0).getUrl()).blockingFirst();
|
||||||
if (numOfDuplicates > 0) {
|
if (numberOfDuplicates > 0) {
|
||||||
createDuplicateDialog(numOfDuplicates, manager, playlist, streams);
|
createDuplicateDialog(numberOfDuplicates, manager, playlist, streams);
|
||||||
} else {
|
} else {
|
||||||
addStreamToPlaylist(manager, playlist, streams);
|
addStreamToPlaylist(manager, playlist, streams);
|
||||||
}
|
}
|
||||||
|
@ -197,22 +203,24 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
|
||||||
playlistDisposables.add(manager.appendToPlaylist(playlist.uid, streams)
|
playlistDisposables.add(manager.appendToPlaylist(playlist.uid, streams)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(ignored -> successToast.show()));
|
.subscribe(ignored -> successToast.show()));
|
||||||
|
|
||||||
requireDialog().dismiss();
|
requireDialog().dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createDuplicateDialog(final int duplicates,
|
private void createDuplicateDialog(final int numberOfDuplicates,
|
||||||
@NonNull final LocalPlaylistManager manager,
|
@NonNull final LocalPlaylistManager manager,
|
||||||
@NonNull final PlaylistMetadataEntry playlist,
|
@NonNull final PlaylistMetadataEntry playlist,
|
||||||
@NonNull final List<StreamEntity> streams) {
|
@NonNull final List<StreamEntity> streams) {
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
|
||||||
builder.setTitle(R.string.duplicate_stream_in_playlist_title);
|
builder.setTitle(R.string.duplicate_stream_in_playlist_title);
|
||||||
builder.setMessage(getString(R.string.duplicate_stream_in_playlist_description,
|
builder.setMessage(getString(R.string.duplicate_stream_in_playlist_description,
|
||||||
duplicates));
|
numberOfDuplicates));
|
||||||
|
|
||||||
builder.setPositiveButton(android.R.string.yes, (dialog, i) -> {
|
builder.setPositiveButton(android.R.string.yes, (dialog, i) -> {
|
||||||
addStreamToPlaylist(manager, playlist, streams);
|
addStreamToPlaylist(manager, playlist, streams);
|
||||||
});
|
});
|
||||||
builder.setNeutralButton(R.string.cancel, null);
|
builder.setNeutralButton(R.string.cancel, null);
|
||||||
|
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,11 +91,12 @@ public class LocalPlaylistManager {
|
||||||
return playlistStreamTable.getOrderedStreamsOf(playlistId).subscribeOn(Schedulers.io());
|
return playlistStreamTable.getOrderedStreamsOf(playlistId).subscribeOn(Schedulers.io());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Flowable<Integer> getPlaylistDuplicates(final long playlistId, final String streamURL) {
|
public Flowable<Integer> getPlaylistDuplicateCount(final long playlistId,
|
||||||
return playlistStreamTable.getDuplicates(playlistId, streamURL);
|
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);
|
return playlistStreamTable.getDuplicatePlaylists(streamURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,26 @@
|
||||||
tools:ignore="RtlHardcoded" />
|
tools:ignore="RtlHardcoded" />
|
||||||
</RelativeLayout>
|
</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
|
<View
|
||||||
android:id="@+id/separator"
|
android:id="@+id/separator"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="1dp"
|
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_marginLeft="@dimen/video_item_search_padding"
|
||||||
android:layout_marginRight="@dimen/video_item_search_padding"
|
android:layout_marginRight="@dimen/video_item_search_padding"
|
||||||
android:background="?attr/separator_color" />
|
android:background="?attr/separator_color" />
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<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"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/itemRoot"
|
android:id="@+id/itemRoot"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -22,17 +21,6 @@
|
||||||
android:src="@drawable/placeholder_thumbnail_playlist"
|
android:src="@drawable/placeholder_thumbnail_playlist"
|
||||||
tools:ignore="RtlHardcoded" />
|
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
|
<org.schabi.newpipe.views.NewPipeTextView
|
||||||
android:id="@+id/itemStreamCountView"
|
android:id="@+id/itemStreamCountView"
|
||||||
android:layout_width="45dp"
|
android:layout_width="45dp"
|
||||||
|
|
|
@ -432,6 +432,7 @@
|
||||||
<string name="preferred_player_fetcher_notification_message">"Loading requested content"</string>
|
<string name="preferred_player_fetcher_notification_message">"Loading requested content"</string>
|
||||||
<!-- Local Playlist -->
|
<!-- Local Playlist -->
|
||||||
<string name="create_playlist">New Playlist</string>
|
<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="rename_playlist">Rename</string>
|
||||||
<string name="name">Name</string>
|
<string name="name">Name</string>
|
||||||
<string name="add_to_playlist">Add to playlist</string>
|
<string name="add_to_playlist">Add to playlist</string>
|
||||||
|
|
Loading…
Reference in a new issue