[Android] Real undo action for video deletion
Geoffrey Métais
git at videolan.org
Wed Jan 6 18:36:00 CET 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jan 6 17:40:46 2016 +0100| [4c3f3fd4a9f3e1ec79edb3340f21618308e653a0] | committer: Geoffrey Métais
Real undo action for video deletion
> https://code.videolan.org/videolan/vlc-android/commit/4c3f3fd4a9f3e1ec79edb3340f21618308e653a0
---
.../org/videolan/vlc/gui/video/VideoGridFragment.java | 17 +++++++++--------
.../org/videolan/vlc/gui/video/VideoListAdapter.java | 15 +++++++++++----
2 files changed, 20 insertions(+), 12 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 d0dbbf6..5a6844e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -122,7 +122,6 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
mGridView.addOnScrollListener(mScrollListener);
mGridView.setAdapter(mVideoAdapter);
- mGridView.setItemAnimator(null);
return v;
}
@@ -268,7 +267,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
private boolean handleContextItemSelected(MenuItem menu, final int position) {
if (position >= mVideoAdapter.getItemCount())
return false;
- MediaWrapper media = mVideoAdapter.getItem(position);
+ final MediaWrapper media = mVideoAdapter.getItem(position);
if (media == null)
return false;
switch (menu.getItemId()){
@@ -301,10 +300,16 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
}
return true;
case R.id.video_list_delete:
+ mVideoAdapter.remove(position);
UiTools.snackerWithCancel(getView(), getString(R.string.file_deleted), new Runnable() {
@Override
public void run() {
- deleteMedia(position);
+ deleteMedia(media);
+ }
+ }, new Runnable() {
+ @Override
+ public void run() {
+ mVideoAdapter.add(position, media);
}
});
return true;
@@ -508,10 +513,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
mVideoAdapter.clear();
}
- public void deleteMedia(int position){
- final MediaWrapper media = mVideoAdapter.getItem(position);
- if (media == null)
- return;
+ public void deleteMedia(final MediaWrapper media){
VLCApplication.runBackground(new Runnable() {
@Override
public void run() {
@@ -520,7 +522,6 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
}
});
mMediaLibrary.getMediaItems().remove(media);
- mVideoAdapter.remove(media);
if (mService != null) {
final List<String> list = mService.getMediaLocations();
if (list != null && list.contains(media.getLocation())) {
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 1986328..4fe2880 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -210,15 +210,22 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
mVideos.add(item);
}
+ public void add(int position, MediaWrapper item) {
+ mVideos.add(position, item);
+ notifyItemInserted(position);
+ }
+
@MainThread
public void remove(MediaWrapper item) {
- int position = getItemPosition(item);
+ remove(getItemPosition(item));
+ }
+
+ @MainThread
+ public void remove(int position) {
if (position == -1)
return;
mVideos.remove(position);
- // Remove the whole end of list to update position tags stored in
- // items views for databinder interactions, like contextual menu
- notifyItemRangeChanged(position, getItemCount()-position);
+ notifyItemRemoved(position);
}
private int getItemPosition(MediaWrapper mw) {
More information about the Android
mailing list