Merge branch 'dev' into recaptcha
This commit is contained in:
commit
3372bacc62
3 changed files with 68 additions and 9 deletions
|
@ -1,8 +1,11 @@
|
||||||
package org.schabi.newpipe.local.bookmark;
|
package org.schabi.newpipe.local.bookmark;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.app.AlertDialog.Builder;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.EditText;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
@ -10,6 +13,7 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import io.reactivex.disposables.Disposable;
|
||||||
import org.reactivestreams.Subscriber;
|
import org.reactivestreams.Subscriber;
|
||||||
import org.reactivestreams.Subscription;
|
import org.reactivestreams.Subscription;
|
||||||
import org.schabi.newpipe.NewPipeDatabase;
|
import org.schabi.newpipe.NewPipeDatabase;
|
||||||
|
@ -118,8 +122,7 @@ public final class BookmarkFragment
|
||||||
@Override
|
@Override
|
||||||
public void held(LocalItem selectedItem) {
|
public void held(LocalItem selectedItem) {
|
||||||
if (selectedItem instanceof PlaylistMetadataEntry) {
|
if (selectedItem instanceof PlaylistMetadataEntry) {
|
||||||
showLocalDeleteDialog((PlaylistMetadataEntry) selectedItem);
|
showLocalDialog((PlaylistMetadataEntry) selectedItem);
|
||||||
|
|
||||||
} else if (selectedItem instanceof PlaylistRemoteEntity) {
|
} else if (selectedItem instanceof PlaylistRemoteEntity) {
|
||||||
showRemoteDeleteDialog((PlaylistRemoteEntity) selectedItem);
|
showRemoteDeleteDialog((PlaylistRemoteEntity) selectedItem);
|
||||||
}
|
}
|
||||||
|
@ -247,14 +250,30 @@ public final class BookmarkFragment
|
||||||
// Utils
|
// Utils
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
private void showLocalDeleteDialog(final PlaylistMetadataEntry item) {
|
|
||||||
showDeleteDialog(item.name, localPlaylistManager.deletePlaylist(item.uid));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showRemoteDeleteDialog(final PlaylistRemoteEntity item) {
|
private void showRemoteDeleteDialog(final PlaylistRemoteEntity item) {
|
||||||
showDeleteDialog(item.getName(), remotePlaylistManager.deletePlaylist(item.getUid()));
|
showDeleteDialog(item.getName(), remotePlaylistManager.deletePlaylist(item.getUid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showLocalDialog(PlaylistMetadataEntry selectedItem) {
|
||||||
|
View dialogView = View.inflate(getContext(), R.layout.dialog_bookmark, null);
|
||||||
|
EditText editText = dialogView.findViewById(R.id.playlist_name_edit_text);
|
||||||
|
editText.setText(selectedItem.name);
|
||||||
|
|
||||||
|
Builder builder = new AlertDialog.Builder(activity);
|
||||||
|
builder.setView(dialogView)
|
||||||
|
.setPositiveButton(R.string.rename_playlist, (dialog, which) -> {
|
||||||
|
changeLocalPlaylistName(selectedItem.uid, editText.getText().toString());
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
.setNeutralButton(R.string.delete, (dialog, which) -> {
|
||||||
|
showDeleteDialog(selectedItem.name,
|
||||||
|
localPlaylistManager.deletePlaylist(selectedItem.uid));
|
||||||
|
dialog.dismiss();
|
||||||
|
})
|
||||||
|
.create()
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
private void showDeleteDialog(final String name, final Single<Integer> deleteReactor) {
|
private void showDeleteDialog(final String name, final Single<Integer> deleteReactor) {
|
||||||
if (activity == null || disposables == null) return;
|
if (activity == null || disposables == null) return;
|
||||||
|
|
||||||
|
@ -271,6 +290,23 @@ public final class BookmarkFragment
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void changeLocalPlaylistName(long id, String name) {
|
||||||
|
if (localPlaylistManager == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "Updating playlist id=[" + id +
|
||||||
|
"] with new name=[" + name + "] items");
|
||||||
|
}
|
||||||
|
|
||||||
|
localPlaylistManager.renamePlaylist(id, name);
|
||||||
|
final Disposable disposable = localPlaylistManager.renamePlaylist(id, name)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(longs -> {/*Do nothing on success*/}, this::onError);
|
||||||
|
disposables.add(disposable);
|
||||||
|
}
|
||||||
|
|
||||||
private static List<PlaylistLocalItem> merge(final List<PlaylistMetadataEntry> localPlaylists,
|
private static List<PlaylistLocalItem> merge(final List<PlaylistMetadataEntry> localPlaylists,
|
||||||
final List<PlaylistRemoteEntity> remotePlaylists) {
|
final List<PlaylistRemoteEntity> remotePlaylists) {
|
||||||
List<PlaylistLocalItem> items = new ArrayList<>(
|
List<PlaylistLocalItem> items = new ArrayList<>(
|
||||||
|
|
|
@ -388,8 +388,10 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
||||||
this.name = name;
|
this.name = name;
|
||||||
setTitle(name);
|
setTitle(name);
|
||||||
|
|
||||||
Log.d(TAG, "Updating playlist id=[" + playlistId +
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "Updating playlist id=[" + playlistId +
|
||||||
"] with new name=[" + name + "] items");
|
"] with new name=[" + name + "] items");
|
||||||
|
}
|
||||||
|
|
||||||
final Disposable disposable = playlistManager.renamePlaylist(playlistId, name)
|
final Disposable disposable = playlistManager.renamePlaylist(playlistId, name)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
@ -404,8 +406,10 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
||||||
R.string.playlist_thumbnail_change_success,
|
R.string.playlist_thumbnail_change_success,
|
||||||
Toast.LENGTH_SHORT);
|
Toast.LENGTH_SHORT);
|
||||||
|
|
||||||
Log.d(TAG, "Updating playlist id=[" + playlistId +
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "Updating playlist id=[" + playlistId +
|
||||||
"] with new thumbnail url=[" + thumbnailUrl + "]");
|
"] with new thumbnail url=[" + thumbnailUrl + "]");
|
||||||
|
}
|
||||||
|
|
||||||
final Disposable disposable = playlistManager
|
final Disposable disposable = playlistManager
|
||||||
.changePlaylistThumbnail(playlistId, thumbnailUrl)
|
.changePlaylistThumbnail(playlistId, thumbnailUrl)
|
||||||
|
@ -472,8 +476,10 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG, "Updating playlist id=[" + playlistId +
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "Updating playlist id=[" + playlistId +
|
||||||
"] with [" + streamIds.size() + "] items");
|
"] with [" + streamIds.size() + "] items");
|
||||||
|
}
|
||||||
|
|
||||||
final Disposable disposable = playlistManager.updateJoin(playlistId, streamIds)
|
final Disposable disposable = playlistManager.updateJoin(playlistId, streamIds)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
|
17
app/src/main/res/layout/dialog_bookmark.xml
Normal file
17
app/src/main/res/layout/dialog_bookmark.xml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/playlist_name_edit_text"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:importantForAutofill="no"
|
||||||
|
android:inputType="text"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
android:hint="@string/playlist_name_input"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
Loading…
Reference in a new issue