Commit 919636b6 authored by Geoffrey Métais's avatar Geoffrey Métais

Fix video delete cancellation

parent 962d2521
......@@ -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);
}
});
}
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment