615 lines
24 KiB
Java
615 lines
24 KiB
Java
package org.schabi.newpipe.local.bookmark;
|
|
|
|
import static org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout;
|
|
|
|
import android.os.Bundle;
|
|
import android.os.Parcelable;
|
|
import android.text.InputType;
|
|
import android.util.Log;
|
|
import android.util.Pair;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.appcompat.app.AlertDialog;
|
|
import androidx.fragment.app.FragmentManager;
|
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import org.reactivestreams.Subscriber;
|
|
import org.reactivestreams.Subscription;
|
|
import org.schabi.newpipe.NewPipeDatabase;
|
|
import org.schabi.newpipe.R;
|
|
import org.schabi.newpipe.database.AppDatabase;
|
|
import org.schabi.newpipe.database.LocalItem;
|
|
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.error.ErrorInfo;
|
|
import org.schabi.newpipe.error.UserAction;
|
|
import org.schabi.newpipe.local.BaseLocalListFragment;
|
|
import org.schabi.newpipe.local.holder.LocalBookmarkPlaylistItemHolder;
|
|
import org.schabi.newpipe.local.holder.RemoteBookmarkPlaylistItemHolder;
|
|
import org.schabi.newpipe.local.playlist.LocalPlaylistManager;
|
|
import org.schabi.newpipe.local.playlist.RemotePlaylistManager;
|
|
import org.schabi.newpipe.util.NavigationHelper;
|
|
import org.schabi.newpipe.util.OnClickGesture;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
import icepick.State;
|
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
|
import io.reactivex.rxjava3.core.Flowable;
|
|
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
|
import io.reactivex.rxjava3.disposables.Disposable;
|
|
import io.reactivex.rxjava3.subjects.PublishSubject;
|
|
|
|
public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistLocalItem>, Void> {
|
|
|
|
// Save the list 10 seconds after the last change occurred
|
|
private static final long SAVE_DEBOUNCE_MILLIS = 10000;
|
|
private static final int MINIMUM_INITIAL_DRAG_VELOCITY = 12;
|
|
@State
|
|
protected Parcelable itemsListState;
|
|
|
|
private Subscription databaseSubscription;
|
|
private CompositeDisposable disposables = new CompositeDisposable();
|
|
private LocalPlaylistManager localPlaylistManager;
|
|
private RemotePlaylistManager remotePlaylistManager;
|
|
private ItemTouchHelper itemTouchHelper;
|
|
|
|
private PublishSubject<Long> debouncedSaveSignal;
|
|
|
|
/* Has the playlist been fully loaded from db */
|
|
private AtomicBoolean isLoadingComplete;
|
|
/* Has the playlist been modified (e.g. items reordered or deleted) */
|
|
private AtomicBoolean isModified;
|
|
|
|
// Map from (uid, local/remote item) to the saved display index in the database.
|
|
private Map<Pair<Long, LocalItem.LocalItemType>, Long> displayIndexInDatabase;
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
// Fragment LifeCycle - Creation
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
@Override
|
|
public void onCreate(final Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
if (activity == null) {
|
|
return;
|
|
}
|
|
final AppDatabase database = NewPipeDatabase.getInstance(activity);
|
|
localPlaylistManager = new LocalPlaylistManager(database);
|
|
remotePlaylistManager = new RemotePlaylistManager(database);
|
|
disposables = new CompositeDisposable();
|
|
|
|
debouncedSaveSignal = PublishSubject.create();
|
|
isLoadingComplete = new AtomicBoolean();
|
|
isModified = new AtomicBoolean();
|
|
|
|
displayIndexInDatabase = new HashMap<>();
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public View onCreateView(@NonNull final LayoutInflater inflater,
|
|
@Nullable final ViewGroup container,
|
|
final Bundle savedInstanceState) {
|
|
|
|
if (!useAsFrontPage) {
|
|
setTitle(activity.getString(R.string.tab_bookmarks));
|
|
}
|
|
return inflater.inflate(R.layout.fragment_bookmarks, container, false);
|
|
}
|
|
|
|
@Override
|
|
public void onResume() {
|
|
super.onResume();
|
|
if (activity != null) {
|
|
setTitle(activity.getString(R.string.tab_bookmarks));
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
// Fragment LifeCycle - Views
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
@Override
|
|
protected void initViews(final View rootView, final Bundle savedInstanceState) {
|
|
super.initViews(rootView, savedInstanceState);
|
|
|
|
itemListAdapter.setUseItemHandle(true);
|
|
}
|
|
|
|
@Override
|
|
protected void initListeners() {
|
|
super.initListeners();
|
|
|
|
itemTouchHelper = new ItemTouchHelper(getItemTouchCallback());
|
|
itemTouchHelper.attachToRecyclerView(itemsList);
|
|
|
|
itemListAdapter.setSelectedListener(new OnClickGesture<LocalItem>() {
|
|
@Override
|
|
public void selected(final LocalItem selectedItem) {
|
|
final FragmentManager fragmentManager = getFM();
|
|
|
|
if (selectedItem instanceof PlaylistMetadataEntry) {
|
|
final PlaylistMetadataEntry entry = ((PlaylistMetadataEntry) selectedItem);
|
|
NavigationHelper.openLocalPlaylistFragment(fragmentManager, entry.uid,
|
|
entry.name);
|
|
|
|
} else if (selectedItem instanceof PlaylistRemoteEntity) {
|
|
final PlaylistRemoteEntity entry = ((PlaylistRemoteEntity) selectedItem);
|
|
NavigationHelper.openPlaylistFragment(
|
|
fragmentManager,
|
|
entry.getServiceId(),
|
|
entry.getUrl(),
|
|
entry.getName());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void held(final LocalItem selectedItem) {
|
|
if (selectedItem instanceof PlaylistMetadataEntry) {
|
|
showLocalDialog((PlaylistMetadataEntry) selectedItem);
|
|
} else if (selectedItem instanceof PlaylistRemoteEntity) {
|
|
showRemoteDeleteDialog((PlaylistRemoteEntity) selectedItem);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void drag(final LocalItem selectedItem,
|
|
final RecyclerView.ViewHolder viewHolder) {
|
|
if (itemTouchHelper != null) {
|
|
itemTouchHelper.startDrag(viewHolder);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
// Fragment LifeCycle - Loading
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
@Override
|
|
public void startLoading(final boolean forceLoad) {
|
|
super.startLoading(forceLoad);
|
|
|
|
disposables.add(getDebouncedSaver());
|
|
isLoadingComplete.set(false);
|
|
isModified.set(false);
|
|
|
|
Flowable.combineLatest(localPlaylistManager.getPlaylists(),
|
|
remotePlaylistManager.getPlaylists(), PlaylistLocalItem::merge)
|
|
.onBackpressureLatest()
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(getPlaylistsSubscriber());
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
// Fragment LifeCycle - Destruction
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
@Override
|
|
public void onPause() {
|
|
super.onPause();
|
|
itemsListState = itemsList.getLayoutManager().onSaveInstanceState();
|
|
|
|
// Save on exit
|
|
saveImmediate();
|
|
}
|
|
|
|
@Override
|
|
public void onDestroyView() {
|
|
super.onDestroyView();
|
|
|
|
if (disposables != null) {
|
|
disposables.clear();
|
|
}
|
|
if (databaseSubscription != null) {
|
|
databaseSubscription.cancel();
|
|
}
|
|
|
|
databaseSubscription = null;
|
|
itemTouchHelper = null;
|
|
}
|
|
|
|
@Override
|
|
public void onDestroy() {
|
|
super.onDestroy();
|
|
if (debouncedSaveSignal != null) {
|
|
debouncedSaveSignal.onComplete();
|
|
}
|
|
if (disposables != null) {
|
|
disposables.dispose();
|
|
}
|
|
|
|
debouncedSaveSignal = null;
|
|
disposables = null;
|
|
localPlaylistManager = null;
|
|
remotePlaylistManager = null;
|
|
itemsListState = null;
|
|
|
|
isLoadingComplete = null;
|
|
isModified = null;
|
|
displayIndexInDatabase = null;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
// Subscriptions Loader
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
private Subscriber<List<PlaylistLocalItem>> getPlaylistsSubscriber() {
|
|
return new Subscriber<List<PlaylistLocalItem>>() {
|
|
@Override
|
|
public void onSubscribe(final Subscription s) {
|
|
showLoading();
|
|
isLoadingComplete.set(false);
|
|
|
|
if (databaseSubscription != null) {
|
|
databaseSubscription.cancel();
|
|
}
|
|
databaseSubscription = s;
|
|
databaseSubscription.request(1);
|
|
}
|
|
|
|
@Override
|
|
public void onNext(final List<PlaylistLocalItem> subscriptions) {
|
|
if (isModified == null || !isModified.get()) {
|
|
checkDisplayIndexModified(subscriptions);
|
|
handleResult(subscriptions);
|
|
isLoadingComplete.set(true);
|
|
}
|
|
if (databaseSubscription != null) {
|
|
databaseSubscription.request(1);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onError(final Throwable exception) {
|
|
showError(new ErrorInfo(exception,
|
|
UserAction.REQUESTED_BOOKMARK, "Loading playlists"));
|
|
}
|
|
|
|
@Override
|
|
public void onComplete() {
|
|
// Do nothing.
|
|
}
|
|
};
|
|
}
|
|
|
|
@Override
|
|
public void handleResult(@NonNull final List<PlaylistLocalItem> result) {
|
|
super.handleResult(result);
|
|
|
|
itemListAdapter.clearStreamItemList();
|
|
|
|
if (result.isEmpty()) {
|
|
showEmptyState();
|
|
return;
|
|
}
|
|
|
|
itemListAdapter.addItems(result);
|
|
if (itemsListState != null) {
|
|
itemsList.getLayoutManager().onRestoreInstanceState(itemsListState);
|
|
itemsListState = null;
|
|
}
|
|
hideLoading();
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
// Fragment Error Handling
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
@Override
|
|
protected void resetFragment() {
|
|
super.resetFragment();
|
|
if (disposables != null) {
|
|
disposables.clear();
|
|
}
|
|
}
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
// Playlist Metadata Manipulation
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
private void changeLocalPlaylistName(final long id, final String name) {
|
|
if (localPlaylistManager == null) {
|
|
return;
|
|
}
|
|
|
|
if (DEBUG) {
|
|
Log.d(TAG, "Updating playlist id=[" + id + "] "
|
|
+ "with new name=[" + name + "] items");
|
|
}
|
|
|
|
final Disposable disposable = localPlaylistManager.renamePlaylist(id, name)
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(longs -> { /*Do nothing on success*/ }, throwable -> showError(
|
|
new ErrorInfo(throwable,
|
|
UserAction.REQUESTED_BOOKMARK,
|
|
"Changing playlist name")));
|
|
disposables.add(disposable);
|
|
}
|
|
|
|
private void deleteItem(final PlaylistLocalItem item) {
|
|
if (itemListAdapter == null) {
|
|
return;
|
|
}
|
|
itemListAdapter.removeItem(item);
|
|
|
|
saveChanges();
|
|
}
|
|
|
|
private void checkDisplayIndexModified(@NonNull final List<PlaylistLocalItem> result) {
|
|
if (isModified != null && isModified.get()) {
|
|
return;
|
|
}
|
|
|
|
displayIndexInDatabase.clear();
|
|
|
|
// If the display index does not match actual index in the list, update the display index.
|
|
// This may happen when a new list is created
|
|
// or on the first run after database update
|
|
// or displayIndex is not continuous for some reason.
|
|
boolean isDisplayIndexModified = false;
|
|
for (int i = 0; i < result.size(); i++) {
|
|
final PlaylistLocalItem item = result.get(i);
|
|
if (item.getDisplayIndex() != i) {
|
|
isDisplayIndexModified = true;
|
|
}
|
|
|
|
// Updating display index in the item does not affect the value inserts into
|
|
// database, which will be recalculated during the database update. Updating
|
|
// display index in the item here is to determine whether it is recently modified.
|
|
// Save the index read from the database.
|
|
if (item instanceof PlaylistMetadataEntry) {
|
|
|
|
displayIndexInDatabase.put(new Pair<>(((PlaylistMetadataEntry) item).uid,
|
|
LocalItem.LocalItemType.PLAYLIST_LOCAL_ITEM), item.getDisplayIndex());
|
|
((PlaylistMetadataEntry) item).displayIndex = i;
|
|
|
|
} else if (item instanceof PlaylistRemoteEntity) {
|
|
|
|
displayIndexInDatabase.put(new Pair<>(((PlaylistRemoteEntity) item).getUid(),
|
|
LocalItem.LocalItemType.PLAYLIST_REMOTE_ITEM),
|
|
item.getDisplayIndex());
|
|
((PlaylistRemoteEntity) item).setDisplayIndex(i);
|
|
|
|
}
|
|
}
|
|
|
|
if (isDisplayIndexModified) {
|
|
saveChanges();
|
|
}
|
|
}
|
|
|
|
private void saveChanges() {
|
|
if (isModified == null || debouncedSaveSignal == null) {
|
|
return;
|
|
}
|
|
|
|
isModified.set(true);
|
|
debouncedSaveSignal.onNext(System.currentTimeMillis());
|
|
}
|
|
|
|
private Disposable getDebouncedSaver() {
|
|
if (debouncedSaveSignal == null) {
|
|
return Disposable.empty();
|
|
}
|
|
|
|
return debouncedSaveSignal
|
|
.debounce(SAVE_DEBOUNCE_MILLIS, TimeUnit.MILLISECONDS)
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(ignored -> saveImmediate(), throwable ->
|
|
showError(new ErrorInfo(throwable, UserAction.SOMETHING_ELSE,
|
|
"Debounced saver")));
|
|
}
|
|
|
|
private void saveImmediate() {
|
|
if (itemListAdapter == null) {
|
|
return;
|
|
}
|
|
|
|
// List must be loaded and modified in order to save
|
|
if (isLoadingComplete == null || isModified == null
|
|
|| !isLoadingComplete.get() || !isModified.get()) {
|
|
Log.w(TAG, "Attempting to save playlists in bookmark when bookmark "
|
|
+ "is not loaded or playlists not modified");
|
|
return;
|
|
}
|
|
|
|
final List<LocalItem> items = itemListAdapter.getItemsList();
|
|
final List<PlaylistMetadataEntry> localItemsUpdate = new ArrayList<>();
|
|
final List<Long> localItemsDeleteUid = new ArrayList<>();
|
|
final List<PlaylistRemoteEntity> remoteItemsUpdate = new ArrayList<>();
|
|
final List<Long> remoteItemsDeleteUid = new ArrayList<>();
|
|
|
|
// Calculate display index
|
|
for (int i = 0; i < items.size(); i++) {
|
|
final LocalItem item = items.get(i);
|
|
|
|
if (item instanceof PlaylistMetadataEntry) {
|
|
((PlaylistMetadataEntry) item).displayIndex = i;
|
|
|
|
final Long uid = ((PlaylistMetadataEntry) item).uid;
|
|
final Pair<Long, LocalItem.LocalItemType> key = new Pair<>(uid,
|
|
LocalItem.LocalItemType.PLAYLIST_LOCAL_ITEM);
|
|
final Long databaseIndex = displayIndexInDatabase.remove(key);
|
|
|
|
// The database index should not be null because inserting new item into database
|
|
// is not handled here. NullPointerException has occurred once, but I can't
|
|
// reproduce it. Enhance robustness here.
|
|
if (databaseIndex != null && databaseIndex != i) {
|
|
localItemsUpdate.add((PlaylistMetadataEntry) item);
|
|
}
|
|
} else if (item instanceof PlaylistRemoteEntity) {
|
|
((PlaylistRemoteEntity) item).setDisplayIndex(i);
|
|
|
|
final Long uid = ((PlaylistRemoteEntity) item).getUid();
|
|
final Pair<Long, LocalItem.LocalItemType> key = new Pair<>(uid,
|
|
LocalItem.LocalItemType.PLAYLIST_REMOTE_ITEM);
|
|
final Long databaseIndex = displayIndexInDatabase.remove(key);
|
|
|
|
if (databaseIndex != null && databaseIndex != i) {
|
|
remoteItemsUpdate.add((PlaylistRemoteEntity) item);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Find deleted items
|
|
for (final Pair<Long, LocalItem.LocalItemType> key : displayIndexInDatabase.keySet()) {
|
|
if (key.second.equals(LocalItem.LocalItemType.PLAYLIST_LOCAL_ITEM)) {
|
|
localItemsDeleteUid.add(key.first);
|
|
} else if (key.second.equals(LocalItem.LocalItemType.PLAYLIST_REMOTE_ITEM)) {
|
|
remoteItemsDeleteUid.add(key.first);
|
|
}
|
|
}
|
|
|
|
displayIndexInDatabase.clear();
|
|
|
|
// 1. Update local playlists
|
|
// 2. Update remote playlists
|
|
// 3. Set isModified false
|
|
disposables.add(localPlaylistManager.updatePlaylists(localItemsUpdate, localItemsDeleteUid)
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(() -> disposables.add(remotePlaylistManager.updatePlaylists(
|
|
remoteItemsUpdate, remoteItemsDeleteUid)
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(() -> {
|
|
if (isModified != null) {
|
|
isModified.set(false);
|
|
}
|
|
},
|
|
throwable -> showError(new ErrorInfo(throwable,
|
|
UserAction.REQUESTED_BOOKMARK,
|
|
"Saving playlist"))
|
|
)),
|
|
throwable -> showError(new ErrorInfo(throwable,
|
|
UserAction.REQUESTED_BOOKMARK, "Saving playlist"))
|
|
));
|
|
|
|
}
|
|
|
|
private ItemTouchHelper.SimpleCallback getItemTouchCallback() {
|
|
int directions = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
|
|
if (shouldUseGridLayout(requireContext())) {
|
|
directions |= ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
|
|
}
|
|
return new ItemTouchHelper.SimpleCallback(directions,
|
|
ItemTouchHelper.ACTION_STATE_IDLE) {
|
|
@Override
|
|
public int interpolateOutOfBoundsScroll(@NonNull final RecyclerView recyclerView,
|
|
final int viewSize,
|
|
final int viewSizeOutOfBounds,
|
|
final int totalSize,
|
|
final long msSinceStartScroll) {
|
|
final int standardSpeed = super.interpolateOutOfBoundsScroll(recyclerView,
|
|
viewSize, viewSizeOutOfBounds, totalSize, msSinceStartScroll);
|
|
final int minimumAbsVelocity = Math.max(MINIMUM_INITIAL_DRAG_VELOCITY,
|
|
Math.abs(standardSpeed));
|
|
return minimumAbsVelocity * (int) Math.signum(viewSizeOutOfBounds);
|
|
}
|
|
|
|
@Override
|
|
public boolean onMove(@NonNull final RecyclerView recyclerView,
|
|
@NonNull final RecyclerView.ViewHolder source,
|
|
@NonNull final RecyclerView.ViewHolder target) {
|
|
|
|
// Allow swap LocalBookmarkPlaylistItemHolder and RemoteBookmarkPlaylistItemHolder.
|
|
if (itemListAdapter == null
|
|
|| source.getItemViewType() != target.getItemViewType()
|
|
&& !(
|
|
(
|
|
(source instanceof LocalBookmarkPlaylistItemHolder)
|
|
|| (source instanceof RemoteBookmarkPlaylistItemHolder)
|
|
)
|
|
&& (
|
|
(target instanceof LocalBookmarkPlaylistItemHolder)
|
|
|| (target instanceof RemoteBookmarkPlaylistItemHolder)
|
|
))
|
|
) {
|
|
return false;
|
|
}
|
|
|
|
final int sourceIndex = source.getBindingAdapterPosition();
|
|
final int targetIndex = target.getBindingAdapterPosition();
|
|
final boolean isSwapped = itemListAdapter.swapItems(sourceIndex, targetIndex);
|
|
if (isSwapped) {
|
|
saveChanges();
|
|
}
|
|
return isSwapped;
|
|
}
|
|
|
|
@Override
|
|
public boolean isLongPressDragEnabled() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isItemViewSwipeEnabled() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public void onSwiped(@NonNull final RecyclerView.ViewHolder viewHolder,
|
|
final int swipeDir) {
|
|
// Do nothing.
|
|
}
|
|
};
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
// Utils
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
private void showRemoteDeleteDialog(final PlaylistRemoteEntity item) {
|
|
showDeleteDialog(item.getName(), item);
|
|
}
|
|
|
|
private void showLocalDialog(final PlaylistMetadataEntry selectedItem) {
|
|
final DialogEditTextBinding dialogBinding
|
|
= DialogEditTextBinding.inflate(getLayoutInflater());
|
|
dialogBinding.dialogEditText.setHint(R.string.name);
|
|
dialogBinding.dialogEditText.setInputType(InputType.TYPE_CLASS_TEXT);
|
|
dialogBinding.dialogEditText.setText(selectedItem.name);
|
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
builder.setView(dialogBinding.getRoot())
|
|
.setPositiveButton(R.string.rename_playlist, (dialog, which) ->
|
|
changeLocalPlaylistName(
|
|
selectedItem.uid,
|
|
dialogBinding.dialogEditText.getText().toString()))
|
|
.setNegativeButton(R.string.cancel, null)
|
|
.setNeutralButton(R.string.delete, (dialog, which) -> {
|
|
showDeleteDialog(selectedItem.name, selectedItem);
|
|
dialog.dismiss();
|
|
})
|
|
.create()
|
|
.show();
|
|
}
|
|
|
|
private void showDeleteDialog(final String name, final PlaylistLocalItem item) {
|
|
if (activity == null || disposables == null) {
|
|
return;
|
|
}
|
|
|
|
new AlertDialog.Builder(activity)
|
|
.setTitle(name)
|
|
.setMessage(R.string.delete_playlist_prompt)
|
|
.setCancelable(true)
|
|
.setPositiveButton(R.string.delete, (dialog, i) -> deleteItem(item))
|
|
.setNegativeButton(R.string.cancel, null)
|
|
.show();
|
|
}
|
|
}
|
|
|