mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 00:20:32 +00:00
Tried to implement the feature
This commit is contained in:
parent
8fc5fa979d
commit
10a5741f36
@ -15,7 +15,7 @@ public class PlaylistEntity {
|
|||||||
public static final String PLAYLIST_ID = "uid";
|
public static final String PLAYLIST_ID = "uid";
|
||||||
public static final String PLAYLIST_NAME = "name";
|
public static final String PLAYLIST_NAME = "name";
|
||||||
public static final String PLAYLIST_THUMBNAIL_URL = "thumbnail_url";
|
public static final String PLAYLIST_THUMBNAIL_URL = "thumbnail_url";
|
||||||
//TODO: add field
|
public static final String PLAYLIST_THUMBNAIL_SET = "isThumbnailSet";
|
||||||
|
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
@ColumnInfo(name = PLAYLIST_ID)
|
@ColumnInfo(name = PLAYLIST_ID)
|
||||||
@ -27,9 +27,14 @@ public class PlaylistEntity {
|
|||||||
@ColumnInfo(name = PLAYLIST_THUMBNAIL_URL)
|
@ColumnInfo(name = PLAYLIST_THUMBNAIL_URL)
|
||||||
private String thumbnailUrl;
|
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.name = name;
|
||||||
this.thumbnailUrl = thumbnailUrl;
|
this.thumbnailUrl = thumbnailUrl;
|
||||||
|
this.isThumbnailSet = isThumbnailSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getUid() {
|
public long getUid() {
|
||||||
@ -55,4 +60,13 @@ public class PlaylistEntity {
|
|||||||
public void setThumbnailUrl(final String thumbnailUrl) {
|
public void setThumbnailUrl(final String thumbnailUrl) {
|
||||||
this.thumbnailUrl = thumbnailUrl;
|
this.thumbnailUrl = thumbnailUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getIsThumbnailSet() {
|
||||||
|
return isThumbnailSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsThumbnailSet(final boolean isThumbnailSet) {
|
||||||
|
this.isThumbnailSet = isThumbnailSet;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ import android.util.Log;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
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.PlaylistMetadataEntry;
|
||||||
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
|
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
|
||||||
import org.schabi.newpipe.databinding.DialogEditTextBinding;
|
import org.schabi.newpipe.databinding.DialogEditTextBinding;
|
||||||
import org.schabi.newpipe.databinding.DialogTitleBinding;
|
|
||||||
import org.schabi.newpipe.error.ErrorInfo;
|
import org.schabi.newpipe.error.ErrorInfo;
|
||||||
import org.schabi.newpipe.error.UserAction;
|
import org.schabi.newpipe.error.UserAction;
|
||||||
import org.schabi.newpipe.local.BaseLocalListFragment;
|
import org.schabi.newpipe.local.BaseLocalListFragment;
|
||||||
@ -258,32 +259,51 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showLocalDialog(final PlaylistMetadataEntry selectedItem) {
|
private void showLocalDialog(final PlaylistMetadataEntry selectedItem) {
|
||||||
|
final boolean isPlaylistThumbnailSet = localPlaylistManager
|
||||||
|
.getIsPlaylistThumbnailSet(selectedItem.uid);
|
||||||
|
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||||
|
|
||||||
//TODO
|
final ArrayAdapter<String> 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 =
|
if (!isPlaylistThumbnailSet && position == 2) {
|
||||||
DialogTitleBinding.inflate(LayoutInflater.from(requireContext()));
|
textView.setEnabled(false);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
dialogBinding.itemRoot.setVisibility(View.GONE);
|
textView.setEnabled(true);
|
||||||
dialogBinding.itemTitleView.setVisibility(View.GONE);
|
return v;
|
||||||
dialogBinding.itemAdditionalDetails.setVisibility(View.GONE);
|
}
|
||||||
final String[] items = new String[]{"Delete", "Rename", "Thumbnail"};
|
};
|
||||||
final DialogInterface.OnClickListener action = (d, index) -> {
|
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) {
|
switch (index) {
|
||||||
case 0: showRenameDialog(selectedItem);
|
case 0: showRenameDialog(selectedItem);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
showDeleteDialog(selectedItem.name,
|
||||||
|
localPlaylistManager.deletePlaylist(selectedItem.uid));
|
||||||
|
dialog.dismiss();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
if (isPlaylistThumbnailSet) {
|
||||||
|
final String ur = "drawable://" + R.drawable.placeholder_thumbnail_playlist;
|
||||||
|
localPlaylistManager.changePlaylistThumbnail(selectedItem.uid, ur,
|
||||||
|
false).observeOn(AndroidSchedulers.mainThread()).subscribe();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO add rename dialog
|
builder.setAdapter(arrayAdapter, action)
|
||||||
|
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
||||||
|
|
||||||
builder.setItems(items, action)
|
|
||||||
.create()
|
.create()
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
@ -302,11 +322,6 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
|||||||
selectedItem.uid,
|
selectedItem.uid,
|
||||||
dialogBinding.dialogEditText.getText().toString()))
|
dialogBinding.dialogEditText.getText().toString()))
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.setNeutralButton(R.string.delete, (dialog, which) -> {
|
|
||||||
showDeleteDialog(selectedItem.name,
|
|
||||||
localPlaylistManager.deletePlaylist(selectedItem.uid));
|
|
||||||
dialog.dismiss();
|
|
||||||
})
|
|
||||||
.create()
|
.create()
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
|
|||||||
if (playlist.thumbnailUrl
|
if (playlist.thumbnailUrl
|
||||||
.equals("drawable://" + R.drawable.placeholder_thumbnail_playlist)) {
|
.equals("drawable://" + R.drawable.placeholder_thumbnail_playlist)) {
|
||||||
playlistDisposables.add(manager
|
playlistDisposables.add(manager
|
||||||
.changePlaylistThumbnail(playlist.uid, streams.get(0).getThumbnailUrl())
|
.changePlaylistThumbnail(playlist.uid, streams.get(0).getThumbnailUrl(), false)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(ignored -> successToast.show()));
|
.subscribe(ignored -> successToast.show()));
|
||||||
}
|
}
|
||||||
|
@ -405,8 +405,9 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
.zipWith(historyIdsMaybe, (playlist, historyStreamIds) -> {
|
.zipWith(historyIdsMaybe, (playlist, historyStreamIds) -> {
|
||||||
// Remove Watched, Functionality data
|
// Remove Watched, Functionality data
|
||||||
final List<PlaylistStreamEntry> notWatchedItems = new ArrayList<>();
|
final List<PlaylistStreamEntry> notWatchedItems = new ArrayList<>();
|
||||||
|
final boolean isThumbnailSet = playlistManager
|
||||||
|
.getIsPlaylistThumbnailSet(playlistId);
|
||||||
boolean thumbnailVideoRemoved = false;
|
boolean thumbnailVideoRemoved = false;
|
||||||
//TODO: add blocker here
|
|
||||||
|
|
||||||
if (removePartiallyWatched) {
|
if (removePartiallyWatched) {
|
||||||
for (final var playlistItem : playlist) {
|
for (final var playlistItem : playlist) {
|
||||||
@ -415,7 +416,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
|
|
||||||
if (indexInHistory < 0) {
|
if (indexInHistory < 0) {
|
||||||
notWatchedItems.add(playlistItem);
|
notWatchedItems.add(playlistItem);
|
||||||
} else if (!thumbnailVideoRemoved
|
} else if (!isThumbnailSet && !thumbnailVideoRemoved
|
||||||
&& playlistManager.getPlaylistThumbnail(playlistId)
|
&& playlistManager.getPlaylistThumbnail(playlistId)
|
||||||
.equals(playlistItem.getStreamEntity().getThumbnailUrl())) {
|
.equals(playlistItem.getStreamEntity().getThumbnailUrl())) {
|
||||||
thumbnailVideoRemoved = true;
|
thumbnailVideoRemoved = true;
|
||||||
@ -436,7 +437,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
if (indexInHistory < 0 || (streamStateEntity != null
|
if (indexInHistory < 0 || (streamStateEntity != null
|
||||||
&& !streamStateEntity.isFinished(duration))) {
|
&& !streamStateEntity.isFinished(duration))) {
|
||||||
notWatchedItems.add(playlistItem);
|
notWatchedItems.add(playlistItem);
|
||||||
} else if (!thumbnailVideoRemoved
|
} else if (!isThumbnailSet && !thumbnailVideoRemoved
|
||||||
&& playlistManager.getPlaylistThumbnail(playlistId)
|
&& playlistManager.getPlaylistThumbnail(playlistId)
|
||||||
.equals(playlistItem.getStreamEntity().getThumbnailUrl())) {
|
.equals(playlistItem.getStreamEntity().getThumbnailUrl())) {
|
||||||
thumbnailVideoRemoved = true;
|
thumbnailVideoRemoved = true;
|
||||||
@ -586,13 +587,12 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
disposables.add(disposable);
|
disposables.add(disposable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeThumbnailUrl(final String thumbnailUrl) {
|
private void changeThumbnailUrl(final String thumbnailUrl, final boolean isPermanent) {
|
||||||
if (playlistManager == null) {
|
if (playlistManager == null || (!isPermanent && playlistManager
|
||||||
|
.getIsPlaylistThumbnailSet(playlistId))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO add blocker here
|
|
||||||
|
|
||||||
final Toast successToast = Toast.makeText(getActivity(),
|
final Toast successToast = Toast.makeText(getActivity(),
|
||||||
R.string.playlist_thumbnail_change_success,
|
R.string.playlist_thumbnail_change_success,
|
||||||
Toast.LENGTH_SHORT);
|
Toast.LENGTH_SHORT);
|
||||||
@ -603,7 +603,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Disposable disposable = playlistManager
|
final Disposable disposable = playlistManager
|
||||||
.changePlaylistThumbnail(playlistId, thumbnailUrl)
|
.changePlaylistThumbnail(playlistId, thumbnailUrl, isPermanent)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(ignore -> successToast.show(), throwable ->
|
.subscribe(ignore -> successToast.show(), throwable ->
|
||||||
showError(new ErrorInfo(throwable, UserAction.REQUESTED_BOOKMARK,
|
showError(new ErrorInfo(throwable, UserAction.REQUESTED_BOOKMARK,
|
||||||
@ -612,8 +612,11 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateThumbnailUrl() {
|
private void updateThumbnailUrl() {
|
||||||
|
if (playlistManager.getIsPlaylistThumbnailSet(playlistId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final String newThumbnailUrl;
|
final String newThumbnailUrl;
|
||||||
//TODO: add blocker here
|
|
||||||
if (!itemListAdapter.getItemsList().isEmpty()) {
|
if (!itemListAdapter.getItemsList().isEmpty()) {
|
||||||
newThumbnailUrl = ((PlaylistStreamEntry) itemListAdapter.getItemsList().get(0))
|
newThumbnailUrl = ((PlaylistStreamEntry) itemListAdapter.getItemsList().get(0))
|
||||||
.getStreamEntity().getThumbnailUrl();
|
.getStreamEntity().getThumbnailUrl();
|
||||||
@ -621,7 +624,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
newThumbnailUrl = "drawable://" + R.drawable.placeholder_thumbnail_playlist;
|
newThumbnailUrl = "drawable://" + R.drawable.placeholder_thumbnail_playlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
changeThumbnailUrl(newThumbnailUrl);
|
changeThumbnailUrl(newThumbnailUrl, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteItem(final PlaylistStreamEntry item) {
|
private void deleteItem(final PlaylistStreamEntry item) {
|
||||||
@ -789,7 +792,8 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
.setAction(
|
.setAction(
|
||||||
StreamDialogDefaultEntry.SET_AS_PLAYLIST_THUMBNAIL,
|
StreamDialogDefaultEntry.SET_AS_PLAYLIST_THUMBNAIL,
|
||||||
(f, i) ->
|
(f, i) ->
|
||||||
changeThumbnailUrl(item.getStreamEntity().getThumbnailUrl()))
|
changeThumbnailUrl(item.getStreamEntity().getThumbnailUrl(),
|
||||||
|
true))
|
||||||
.setAction(
|
.setAction(
|
||||||
StreamDialogDefaultEntry.DELETE,
|
StreamDialogDefaultEntry.DELETE,
|
||||||
(f, i) -> deleteItem(item))
|
(f, i) -> deleteItem(item))
|
||||||
|
@ -41,7 +41,7 @@ public class LocalPlaylistManager {
|
|||||||
}
|
}
|
||||||
final StreamEntity defaultStream = streams.get(0);
|
final StreamEntity defaultStream = streams.get(0);
|
||||||
final PlaylistEntity newPlaylist =
|
final PlaylistEntity newPlaylist =
|
||||||
new PlaylistEntity(name, defaultStream.getThumbnailUrl());
|
new PlaylistEntity(name, defaultStream.getThumbnailUrl(), false);
|
||||||
|
|
||||||
return Maybe.fromCallable(() -> database.runInTransaction(() ->
|
return Maybe.fromCallable(() -> database.runInTransaction(() ->
|
||||||
upsertStreams(playlistTable.insert(newPlaylist), streams, 0))
|
upsertStreams(playlistTable.insert(newPlaylist), streams, 0))
|
||||||
@ -96,24 +96,29 @@ public class LocalPlaylistManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Maybe<Integer> renamePlaylist(final long playlistId, final String name) {
|
public Maybe<Integer> renamePlaylist(final long playlistId, final String name) {
|
||||||
return modifyPlaylist(playlistId, name, null);
|
return modifyPlaylist(playlistId, name, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Maybe<Integer> changePlaylistThumbnail(final long playlistId,
|
public Maybe<Integer> changePlaylistThumbnail(final long playlistId,
|
||||||
final String thumbnailUrl) {
|
final String thumbnailUrl,
|
||||||
return modifyPlaylist(playlistId, null, thumbnailUrl);
|
final boolean isPermanent) {
|
||||||
|
return modifyPlaylist(playlistId, null, thumbnailUrl, isPermanent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPlaylistThumbnail(final long playlistId) {
|
public String getPlaylistThumbnail(final long playlistId) {
|
||||||
return playlistTable.getPlaylist(playlistId).blockingFirst().get(0).getThumbnailUrl();
|
return playlistTable.getPlaylist(playlistId).blockingFirst().get(0).getThumbnailUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getIsPlaylistThumbnailSet(final long playlistId) {
|
||||||
|
return playlistTable.getPlaylist(playlistId).blockingFirst().get(0).getIsThumbnailSet();
|
||||||
|
}
|
||||||
|
|
||||||
private Maybe<Integer> modifyPlaylist(final long playlistId,
|
private Maybe<Integer> modifyPlaylist(final long playlistId,
|
||||||
@Nullable final String name,
|
@Nullable final String name,
|
||||||
@Nullable final String thumbnailUrl) {
|
@Nullable final String thumbnailUrl,
|
||||||
|
final boolean isPermanent) {
|
||||||
return playlistTable.getPlaylist(playlistId)
|
return playlistTable.getPlaylist(playlistId)
|
||||||
.firstElement()
|
.firstElement()
|
||||||
.filter(playlistEntities -> !playlistEntities.isEmpty())
|
|
||||||
.map(playlistEntities -> {
|
.map(playlistEntities -> {
|
||||||
final PlaylistEntity playlist = playlistEntities.get(0);
|
final PlaylistEntity playlist = playlistEntities.get(0);
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
@ -121,6 +126,7 @@ public class LocalPlaylistManager {
|
|||||||
}
|
}
|
||||||
if (thumbnailUrl != null) {
|
if (thumbnailUrl != null) {
|
||||||
playlist.setThumbnailUrl(thumbnailUrl);
|
playlist.setThumbnailUrl(thumbnailUrl);
|
||||||
|
playlist.setIsThumbnailSet(isPermanent);
|
||||||
}
|
}
|
||||||
return playlistTable.update(playlist);
|
return playlistTable.update(playlist);
|
||||||
}).subscribeOn(Schedulers.io());
|
}).subscribeOn(Schedulers.io());
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
<string name="install">Install</string>
|
<string name="install">Install</string>
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
|
<string name="yes">Yes</string>
|
||||||
<string name="open_in_browser">Open in browser</string>
|
<string name="open_in_browser">Open in browser</string>
|
||||||
<string name="mark_as_watched">Mark as watched</string>
|
<string name="mark_as_watched">Mark as watched</string>
|
||||||
<string name="open_in_popup_mode">Open in popup mode</string>
|
<string name="open_in_popup_mode">Open in popup mode</string>
|
||||||
@ -438,6 +439,7 @@
|
|||||||
<string name="mute">Mute</string>
|
<string name="mute">Mute</string>
|
||||||
<string name="unmute">Unmute</string>
|
<string name="unmute">Unmute</string>
|
||||||
<string name="set_as_playlist_thumbnail">Set as playlist thumbnail</string>
|
<string name="set_as_playlist_thumbnail">Set as playlist thumbnail</string>
|
||||||
|
<string name="unset_playlist_thumbnail">Unset thumbnail</string>
|
||||||
<string name="bookmark_playlist">Bookmark Playlist</string>
|
<string name="bookmark_playlist">Bookmark Playlist</string>
|
||||||
<string name="unbookmark_playlist">Remove Bookmark</string>
|
<string name="unbookmark_playlist">Remove Bookmark</string>
|
||||||
<string name="delete_playlist_prompt">Delete this playlist\?</string>
|
<string name="delete_playlist_prompt">Delete this playlist\?</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user