[Android] Fix video delete cancellation

Geoffrey Métais git at videolan.org
Tue Dec 5 14:39:05 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Dec  5 14:38:41 2017 +0100| [919636b6071c68db8e5cbf399ddf47e3d3e8c6cb] | committer: Geoffrey Métais

Fix video delete cancellation

> https://code.videolan.org/videolan/vlc-android/commit/919636b6071c68db8e5cbf399ddf47e3d3e8c6cb
---

 .../src/org/videolan/vlc/gui/video/VideoGridFragment.java   |  9 +++++----
 .../src/org/videolan/vlc/gui/video/VideoListAdapter.java    | 13 ++++++++-----
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 4be925151..52ab90d45 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -292,9 +292,10 @@ public class VideoGridFragment extends SortableFragment<VideoListAdapter> implem
     }
 
     private void removeVideo(final MediaWrapper media) {
-        mAdapter.remove(media);
-        if (getView() != null)
-            UiTools.snackerWithCancel(getView(), getString(R.string.file_deleted), new Runnable() {
+        final int position = mAdapter.remove(media);
+        final View view = getView();
+        if (position != -1 && view != null)
+            UiTools.snackerWithCancel(view, getString(R.string.file_deleted), new Runnable() {
                 @Override
                 public void run() {
                     deleteMedia(media, false);
@@ -302,7 +303,7 @@ public class VideoGridFragment extends SortableFragment<VideoListAdapter> implem
             }, new Runnable() {
                 @Override
                 public void run() {
-                    mAdapter.add(media);
+                    mAdapter.add(media, position);
                 }
             });
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index 0587035a2..9cd97c46c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -153,17 +153,20 @@ public class VideoListAdapter extends SortableAdapter<MediaWrapper, VideoListAda
     }
 
     @MainThread
-    public void add(MediaWrapper item) {
+    public void add(MediaWrapper item, int position) {
         final ArrayList<MediaWrapper> list = new ArrayList<>(peekLast());
-        list.add(item);
+        list.add(position, item);
         update(list);
     }
 
     @MainThread
-    public void remove(MediaWrapper item) {
+    public int remove(MediaWrapper item) {
         final ArrayList<MediaWrapper> refList = new ArrayList<>(peekLast());
-        if (refList.remove(item))
-            update(refList);
+        final int position = refList.indexOf(item);
+        if (position < 0 || position >= refList.size()) return -1;
+        refList.remove(position);
+        update(refList);
+        return position;
     }
 
     @MainThread



More information about the Android mailing list