[Android] Real undo action for browser deletion

Geoffrey Métais git at videolan.org
Wed Jan 6 18:36:01 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jan  6 17:57:23 2016 +0100| [3d52141681b332f1b1fd788e6d70461136d9e1ce] | committer: Geoffrey Métais

Real undo action for browser deletion

> https://code.videolan.org/videolan/vlc-android/commit/3d52141681b332f1b1fd788e6d70461136d9e1ce
---

 .../vlc/gui/browser/BaseBrowserAdapter.java         | 21 ++++++++++++++++-----
 .../vlc/gui/browser/BaseBrowserFragment.java        |  7 ++++++-
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
index a3b283f..6fb9187 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -223,14 +223,25 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
         return mMediaList.isEmpty();
     }
 
-    public void addItem(Media media, boolean notify, boolean top){
-        MediaWrapper mediaWrapper = new MediaWrapper(media);
-        addItem(mediaWrapper, notify, top);
+    public void addItem(Object item, boolean notify, boolean top){
+        addItem(item, notify, top, -1);
 
     }
 
-    public void addItem(Object item, boolean notify, boolean top){
-        int position = top ? 0 : mMediaList.size();
+    public void addItem(Object item, boolean notify, int position){
+        addItem(item, notify, false, position);
+    }
+
+    public void addItem(Object item, boolean notify, boolean top, int positionTo){
+        int position;
+        if (positionTo != -1)
+            position = positionTo;
+        else
+            position = top ? 0 : mMediaList.size();
+
+        if (item instanceof Media)
+            item = new MediaWrapper((Media) item);
+
         if (item instanceof MediaWrapper && ((MediaWrapper)item).getTitle().startsWith("."))
             return;
         else if (item instanceof Media)
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index fd3a990..4bb9780 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -408,7 +408,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
         mRecyclerView.openContextMenu(position);
     }
 
-    protected boolean handleContextItemSelected(MenuItem item, int position) {
+    protected boolean handleContextItemSelected(MenuItem item, final int position) {
         int id = item.getItemId();
         if (! (mAdapter.getItem(position) instanceof MediaWrapper))
             return super.onContextItemSelected(item);
@@ -430,6 +430,11 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
                     public void run() {
                         deleteMedia(mw);
                     }
+                }, new Runnable() {
+                    @Override
+                    public void run() {
+                        mAdapter.addItem(mw, true, position);
+                    }
                 });
                 return true;
             case  R.id.directory_view_info:



More information about the Android mailing list