[Android] Undo action for MRL item removal

Geoffrey Métais git at videolan.org
Tue Apr 5 14:52:24 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Apr  5 14:48:31 2016 +0200| [57759089b86f61e5cdd5a8a495287e10733dc236] | committer: Geoffrey Métais

Undo action for MRL item removal

> https://code.videolan.org/videolan/vlc-android/commit/57759089b86f61e5cdd5a8a495287e10733dc236
---

 .../org/videolan/vlc/gui/network/MRLAdapter.java   | 26 +++++++++++++++++-----
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/network/MRLAdapter.java b/vlc-android/src/org/videolan/vlc/gui/network/MRLAdapter.java
index ed24255..e1522a2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/network/MRLAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/network/MRLAdapter.java
@@ -60,7 +60,7 @@ public class MRLAdapter extends RecyclerView.Adapter<MRLAdapter.ViewHolder> {
     }
 
     @Override
-    public void onBindViewHolder(final ViewHolder holder, int position) {
+    public void onBindViewHolder(final ViewHolder holder, final int position) {
         final String uri = mDataset.get(position);
         holder.uriTv.setText(uri);
         holder.uriTv.setOnClickListener(new View.OnClickListener() {
@@ -73,11 +73,25 @@ public class MRLAdapter extends RecyclerView.Adapter<MRLAdapter.ViewHolder> {
         holder.deleteButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                int pos = holder.getPosition();
-                if (pos > -1) {
-                    MediaDatabase.getInstance().deleteMrlUri(mDataset.get(pos));
-                    mDataset.remove(pos);
-                    notifyItemRemoved(pos);
+                UiTools.setKeyboardVisibility(holder.itemView, false);
+                if (holder.getAdapterPosition() > -1) {
+                    final String mrl = mDataset.get(position);
+                    mDataset.remove(position);
+                    notifyItemRemoved(position);
+                    UiTools.snackerWithCancel(holder.itemView,
+                            holder.itemView.getContext().getString(R.string.file_deleted),
+                            new Runnable() {
+                                @Override
+                                public void run() {
+                                    MediaDatabase.getInstance().deleteMrlUri(mrl);
+                                }
+                            }, new Runnable() {
+                                @Override
+                                public void run() {
+                                    mDataset.add(position, mrl);
+                                    notifyItemInserted(position);
+                                }
+                            });
                 }
             }
         });



More information about the Android mailing list