Fixed some bugs and improved code quality
This commit is contained in:
parent
10a5741f36
commit
bf1ebf8733
3 changed files with 51 additions and 28 deletions
|
@ -25,6 +25,7 @@ import static org.schabi.newpipe.database.playlist.model.PlaylistStreamEntity.JO
|
|||
import static org.schabi.newpipe.database.playlist.model.PlaylistStreamEntity.PLAYLIST_STREAM_JOIN_TABLE;
|
||||
import static org.schabi.newpipe.database.stream.model.StreamEntity.STREAM_ID;
|
||||
import static org.schabi.newpipe.database.stream.model.StreamEntity.STREAM_TABLE;
|
||||
import static org.schabi.newpipe.database.stream.model.StreamEntity.STREAM_THUMBNAIL_URL;
|
||||
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.JOIN_STREAM_ID_ALIAS;
|
||||
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_PROGRESS_MILLIS;
|
||||
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_STATE_TABLE;
|
||||
|
@ -53,6 +54,15 @@ public interface PlaylistStreamDAO extends BasicDAO<PlaylistStreamEntity> {
|
|||
+ " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId")
|
||||
Flowable<Integer> getMaximumIndexOf(long playlistId);
|
||||
|
||||
@Query("SELECT CASE WHEN COUNT(*) != 0 then " + STREAM_THUMBNAIL_URL + " ELSE :defaultUrl END"
|
||||
+ " FROM " + STREAM_TABLE
|
||||
+ " LEFT JOIN " + PLAYLIST_STREAM_JOIN_TABLE
|
||||
+ " ON " + STREAM_ID + " = " + JOIN_STREAM_ID
|
||||
+ " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId "
|
||||
+ " LIMIT 1"
|
||||
)
|
||||
Flowable<String> getAutomaticThumbnailUrl(long playlistId, String defaultUrl);
|
||||
|
||||
@RewriteQueriesToDropUnusedColumns
|
||||
@Transaction
|
||||
@Query("SELECT * FROM " + STREAM_TABLE + " INNER JOIN "
|
||||
|
|
|
@ -259,11 +259,42 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
|||
}
|
||||
|
||||
private void showLocalDialog(final PlaylistMetadataEntry selectedItem) {
|
||||
final String rename = getString(R.string.rename);
|
||||
final String delete = getString(R.string.delete);
|
||||
final String unsetThumbnail = getString(R.string.unset_playlist_thumbnail);
|
||||
final boolean isPlaylistThumbnailSet = localPlaylistManager
|
||||
.getIsPlaylistThumbnailSet(selectedItem.uid);
|
||||
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
|
||||
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getContext(),
|
||||
final ArrayAdapter<String> arrayAdapter = getLocalDialogArrayAdapter(isPlaylistThumbnailSet,
|
||||
unsetThumbnail);
|
||||
arrayAdapter.addAll(rename, delete, unsetThumbnail);
|
||||
|
||||
final DialogInterface.OnClickListener action = (dialog, index) -> {
|
||||
if (index == arrayAdapter.getPosition(rename)) {
|
||||
showRenameDialog(selectedItem);
|
||||
} else if (index == arrayAdapter.getPosition(delete)) {
|
||||
showDeleteDialog(selectedItem.name, localPlaylistManager
|
||||
.deletePlaylist(selectedItem.uid));
|
||||
dialog.dismiss();
|
||||
} else if (isPlaylistThumbnailSet) {
|
||||
final String thumbnail_url = localPlaylistManager
|
||||
.getAutomaticPlaylistThumbnail(selectedItem.uid);
|
||||
localPlaylistManager.changePlaylistThumbnail(selectedItem.uid, thumbnail_url, false)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe();
|
||||
}
|
||||
};
|
||||
|
||||
builder.setAdapter(arrayAdapter, action)
|
||||
.create()
|
||||
.show();
|
||||
}
|
||||
|
||||
private ArrayAdapter<String> getLocalDialogArrayAdapter(final boolean isPlaylistThumbnailSet,
|
||||
final String unsetThumbnail) {
|
||||
return new ArrayAdapter<>(getContext(),
|
||||
android.R.layout.simple_list_item_1) {
|
||||
@Override
|
||||
public View getView(final int position, final View convertView,
|
||||
|
@ -271,7 +302,8 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
|||
final View v = super.getView(position, convertView, parent);
|
||||
final TextView textView = v.findViewById(android.R.id.text1);
|
||||
|
||||
if (!isPlaylistThumbnailSet && position == 2) {
|
||||
// If the PlaylistThumbnail is not set permanently, the unset option is disabled.
|
||||
if (!isPlaylistThumbnailSet && textView.getText().equals(unsetThumbnail)) {
|
||||
textView.setEnabled(false);
|
||||
return v;
|
||||
}
|
||||
|
@ -280,32 +312,6 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
|||
return v;
|
||||
}
|
||||
};
|
||||
arrayAdapter.addAll(getString(R.string.rename), getString(R.string.delete),
|
||||
getString(R.string.unset_playlist_thumbnail));
|
||||
|
||||
// Rename = 0; Delete = 1; Unset Thumbnail = 2
|
||||
final DialogInterface.OnClickListener action = (dialog, index) -> {
|
||||
switch (index) {
|
||||
case 0: showRenameDialog(selectedItem);
|
||||
break;
|
||||
case 1:
|
||||
showDeleteDialog(selectedItem.name,
|
||||
localPlaylistManager.deletePlaylist(selectedItem.uid));
|
||||
dialog.dismiss();
|
||||
break;
|
||||
case 2:
|
||||
if (isPlaylistThumbnailSet) {
|
||||
final String ur = "drawable://" + R.drawable.placeholder_thumbnail_playlist;
|
||||
localPlaylistManager.changePlaylistThumbnail(selectedItem.uid, ur,
|
||||
false).observeOn(AndroidSchedulers.mainThread()).subscribe();
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
builder.setAdapter(arrayAdapter, action)
|
||||
.create()
|
||||
.show();
|
||||
}
|
||||
|
||||
private void showRenameDialog(final PlaylistMetadataEntry selectedItem) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.schabi.newpipe.local.playlist;
|
|||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.database.AppDatabase;
|
||||
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
|
||||
import org.schabi.newpipe.database.playlist.PlaylistStreamEntry;
|
||||
|
@ -113,12 +114,18 @@ public class LocalPlaylistManager {
|
|||
return playlistTable.getPlaylist(playlistId).blockingFirst().get(0).getIsThumbnailSet();
|
||||
}
|
||||
|
||||
public String getAutomaticPlaylistThumbnail(final long playlistId) {
|
||||
final String def = "drawable://" + R.drawable.placeholder_thumbnail_playlist;
|
||||
return playlistStreamTable.getAutomaticThumbnailUrl(playlistId, def).blockingFirst();
|
||||
}
|
||||
|
||||
private Maybe<Integer> modifyPlaylist(final long playlistId,
|
||||
@Nullable final String name,
|
||||
@Nullable final String thumbnailUrl,
|
||||
final boolean isPermanent) {
|
||||
return playlistTable.getPlaylist(playlistId)
|
||||
.firstElement()
|
||||
.filter(playlistEntities -> !playlistEntities.isEmpty())
|
||||
.map(playlistEntities -> {
|
||||
final PlaylistEntity playlist = playlistEntities.get(0);
|
||||
if (name != null) {
|
||||
|
|
Loading…
Reference in a new issue