[Android] Video grid: prevent deleting the wrong item if list has changed
Sébastien Toque
git at videolan.org
Thu Oct 29 06:47:01 CET 2015
vlc-ports/android | branch: delete_on_lollipop | Sébastien Toque <xilasz at gmail.com> | Sun Oct 25 08:06:39 2015 +0100| [b3cf783717a33ede62cd38674d6aadc03ea64d4b] | committer: Sébastien Toque
Video grid: prevent deleting the wrong item if list has changed
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=b3cf783717a33ede62cd38674d6aadc03ea64d4b
---
.../org/videolan/vlc/gui/video/VideoGridFragment.java | 16 +++++++++-------
.../org/videolan/vlc/gui/video/VideoListAdapter.java | 9 +++++++++
2 files changed, 18 insertions(+), 7 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 f7e0c8f..6817fe6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -57,6 +57,7 @@ import android.widget.TextView;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.util.AndroidUtil;
+import org.videolan.vlc.BuildConfig;
import org.videolan.vlc.MediaDatabase;
import org.videolan.vlc.MediaGroup;
import org.videolan.vlc.MediaLibrary;
@@ -174,6 +175,9 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
mMediaLibrary.setBrowser(null);
mMediaLibrary.removeUpdateHandler(mHandler);
+ /* Clear current deletion */
+ mDeleteHandler.removeMessages(DELETE_MEDIA);
+
/* Stop the thumbnailer */
if (mThumbnailer != null)
mThumbnailer.stop();
@@ -319,7 +323,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
Snackbar.make(getView(), getString(R.string.file_deleted), DELETE_DURATION)
.setAction(android.R.string.cancel, mCancelDeleteMediaListener)
.show();
- Message msg = mDeleteHandler.obtainMessage(DELETE_MEDIA, position, 0);
+ Message msg = mDeleteHandler.obtainMessage(DELETE_MEDIA, media.getLocation());
mDeleteHandler.sendMessageDelayed(msg, DELETE_DURATION);
return true;
}
@@ -350,8 +354,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
hasInfo = true;
media.release();
menu.findItem(R.id.video_list_info).setVisible(hasInfo);
- menu.findItem(R.id.video_list_delete).setVisible(!AndroidUtil.isLolliPopOrLater() ||
- mediaWrapper.getLocation().startsWith("file://" + AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY));
+ menu.findItem(R.id.video_list_delete).setVisible(BuildConfig.DEBUG);
}
@Override
@@ -555,8 +558,8 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
mVideoAdapter.clear();
}
- public void deleteMedia(int position){
- final MediaWrapper media = mVideoAdapter.getItem(position);
+ public void deleteMedia(String location){
+ final MediaWrapper media = mVideoAdapter.getItem(location);
final String path = media.getUri().getPath();
VLCApplication.runBackground(new Runnable() {
public void run() {
@@ -573,7 +576,6 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
}
}
-
View.OnClickListener mCancelDeleteMediaListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -594,7 +596,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
super.handleMessage(msg);
switch (msg.what){
case DELETE_MEDIA:
- getOwner().deleteMedia(msg.arg1);
+ getOwner().deleteMedia(msg.obj.toString());
}
}
}
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 3ab1c05..254adf6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -89,6 +89,15 @@ public class VideoListAdapter extends ArrayAdapter<MediaWrapper>
notifyDataSetChanged();
}
+ public MediaWrapper getItem(String location) {
+ for (int i = 0; i < getCount(); ++i) {
+ MediaWrapper media = getItem(i);
+ if (media.getLocation().equals(location))
+ return media;
+ }
+ return null;
+ }
+
public int sortDirection(int sortby) {
if (sortby == mSortBy)
return mSortDirection;
More information about the Android
mailing list