From 10a5741f36e0fa8c3d806a6a64c1584f06b4ef40 Mon Sep 17 00:00:00 2001 From: Jared Fantaye Date: Wed, 7 Dec 2022 02:32:53 +0100 Subject: [PATCH] Tried to implement the feature --- .../playlist/model/PlaylistEntity.java | 18 ++++++- .../local/bookmark/BookmarkFragment.java | 53 ++++++++++++------- .../local/dialog/PlaylistAppendDialog.java | 2 +- .../local/playlist/LocalPlaylistFragment.java | 26 +++++---- .../local/playlist/LocalPlaylistManager.java | 18 ++++--- app/src/main/res/values/strings.xml | 2 + 6 files changed, 80 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistEntity.java b/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistEntity.java index 37e79f060..a04a284da 100644 --- a/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistEntity.java +++ b/app/src/main/java/org/schabi/newpipe/database/playlist/model/PlaylistEntity.java @@ -15,7 +15,7 @@ public class PlaylistEntity { public static final String PLAYLIST_ID = "uid"; public static final String PLAYLIST_NAME = "name"; public static final String PLAYLIST_THUMBNAIL_URL = "thumbnail_url"; - //TODO: add field + public static final String PLAYLIST_THUMBNAIL_SET = "isThumbnailSet"; @PrimaryKey(autoGenerate = true) @ColumnInfo(name = PLAYLIST_ID) @@ -27,9 +27,14 @@ public class PlaylistEntity { @ColumnInfo(name = PLAYLIST_THUMBNAIL_URL) private String thumbnailUrl; - public PlaylistEntity(final String name, final String thumbnailUrl) { + @ColumnInfo(name = PLAYLIST_THUMBNAIL_SET) + private boolean isThumbnailSet; + + public PlaylistEntity(final String name, final String thumbnailUrl, + final boolean isThumbnailSet) { this.name = name; this.thumbnailUrl = thumbnailUrl; + this.isThumbnailSet = isThumbnailSet; } public long getUid() { @@ -55,4 +60,13 @@ public class PlaylistEntity { public void setThumbnailUrl(final String thumbnailUrl) { this.thumbnailUrl = thumbnailUrl; } + + public boolean getIsThumbnailSet() { + return isThumbnailSet; + } + + public void setIsThumbnailSet(final boolean isThumbnailSet) { + this.isThumbnailSet = isThumbnailSet; + } + } diff --git a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java index 2170f7d97..65db40d16 100644 --- a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java @@ -8,6 +8,8 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -24,7 +26,6 @@ import org.schabi.newpipe.database.playlist.PlaylistLocalItem; import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry; import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity; import org.schabi.newpipe.databinding.DialogEditTextBinding; -import org.schabi.newpipe.databinding.DialogTitleBinding; import org.schabi.newpipe.error.ErrorInfo; import org.schabi.newpipe.error.UserAction; import org.schabi.newpipe.local.BaseLocalListFragment; @@ -258,32 +259,51 @@ public final class BookmarkFragment extends BaseLocalListFragment arrayAdapter = new ArrayAdapter<>(getContext(), + android.R.layout.simple_list_item_1) { + @Override + public View getView(final int position, final View convertView, + final ViewGroup parent) { + final View v = super.getView(position, convertView, parent); + final TextView textView = v.findViewById(android.R.id.text1); - final DialogTitleBinding dialogBinding = - DialogTitleBinding.inflate(LayoutInflater.from(requireContext())); + if (!isPlaylistThumbnailSet && position == 2) { + textView.setEnabled(false); + return v; + } - dialogBinding.itemRoot.setVisibility(View.GONE); - dialogBinding.itemTitleView.setVisibility(View.GONE); - dialogBinding.itemAdditionalDetails.setVisibility(View.GONE); - final String[] items = new String[]{"Delete", "Rename", "Thumbnail"}; - final DialogInterface.OnClickListener action = (d, index) -> { + textView.setEnabled(true); + 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; } }; - //TODO add rename dialog - - final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - - builder.setItems(items, action) + builder.setAdapter(arrayAdapter, action) .create() .show(); } @@ -302,11 +322,6 @@ public final class BookmarkFragment extends BaseLocalListFragment { - showDeleteDialog(selectedItem.name, - localPlaylistManager.deletePlaylist(selectedItem.uid)); - dialog.dismiss(); - }) .create() .show(); } diff --git a/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java b/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java index 3d5d16c39..88dec3911 100644 --- a/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java +++ b/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java @@ -134,7 +134,7 @@ public final class PlaylistAppendDialog extends PlaylistDialog { if (playlist.thumbnailUrl .equals("drawable://" + R.drawable.placeholder_thumbnail_playlist)) { playlistDisposables.add(manager - .changePlaylistThumbnail(playlist.uid, streams.get(0).getThumbnailUrl()) + .changePlaylistThumbnail(playlist.uid, streams.get(0).getThumbnailUrl(), false) .observeOn(AndroidSchedulers.mainThread()) .subscribe(ignored -> successToast.show())); } diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index 66e7cbf8f..78e455c78 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -405,8 +405,9 @@ public class LocalPlaylistFragment extends BaseLocalListFragment { // Remove Watched, Functionality data final List notWatchedItems = new ArrayList<>(); + final boolean isThumbnailSet = playlistManager + .getIsPlaylistThumbnailSet(playlistId); boolean thumbnailVideoRemoved = false; - //TODO: add blocker here if (removePartiallyWatched) { for (final var playlistItem : playlist) { @@ -415,7 +416,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment successToast.show(), throwable -> showError(new ErrorInfo(throwable, UserAction.REQUESTED_BOOKMARK, @@ -612,8 +612,11 @@ public class LocalPlaylistFragment extends BaseLocalListFragment - changeThumbnailUrl(item.getStreamEntity().getThumbnailUrl())) + changeThumbnailUrl(item.getStreamEntity().getThumbnailUrl(), + true)) .setAction( StreamDialogDefaultEntry.DELETE, (f, i) -> deleteItem(item)) diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistManager.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistManager.java index 33296aa84..2510b284d 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistManager.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistManager.java @@ -41,7 +41,7 @@ public class LocalPlaylistManager { } final StreamEntity defaultStream = streams.get(0); final PlaylistEntity newPlaylist = - new PlaylistEntity(name, defaultStream.getThumbnailUrl()); + new PlaylistEntity(name, defaultStream.getThumbnailUrl(), false); return Maybe.fromCallable(() -> database.runInTransaction(() -> upsertStreams(playlistTable.insert(newPlaylist), streams, 0)) @@ -96,24 +96,29 @@ public class LocalPlaylistManager { } public Maybe renamePlaylist(final long playlistId, final String name) { - return modifyPlaylist(playlistId, name, null); + return modifyPlaylist(playlistId, name, null, false); } public Maybe changePlaylistThumbnail(final long playlistId, - final String thumbnailUrl) { - return modifyPlaylist(playlistId, null, thumbnailUrl); + final String thumbnailUrl, + final boolean isPermanent) { + return modifyPlaylist(playlistId, null, thumbnailUrl, isPermanent); } public String getPlaylistThumbnail(final long playlistId) { return playlistTable.getPlaylist(playlistId).blockingFirst().get(0).getThumbnailUrl(); } + public boolean getIsPlaylistThumbnailSet(final long playlistId) { + return playlistTable.getPlaylist(playlistId).blockingFirst().get(0).getIsThumbnailSet(); + } + private Maybe modifyPlaylist(final long playlistId, @Nullable final String name, - @Nullable final String thumbnailUrl) { + @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) { @@ -121,6 +126,7 @@ public class LocalPlaylistManager { } if (thumbnailUrl != null) { playlist.setThumbnailUrl(thumbnailUrl); + playlist.setIsThumbnailSet(isPermanent); } return playlistTable.update(playlist); }).subscribeOn(Schedulers.io()); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3fa37155a..b79bb2815 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -7,6 +7,7 @@ Install Cancel OK + Yes Open in browser Mark as watched Open in popup mode @@ -438,6 +439,7 @@ Mute Unmute Set as playlist thumbnail + Unset thumbnail Bookmark Playlist Remove Bookmark Delete this playlist\?