[Android] Snackbar for deletion in VideoGridFragment
Geoffrey Métais
git at videolan.org
Thu Jun 4 18:07:51 CEST 2015
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jun 4 17:47:24 2015 +0200| [288d08ff269a25aeab367f1f6f11b35b6dfd1e83] | committer: Geoffrey Métais
Snackbar for deletion in VideoGridFragment
+ Use of appcontext for safety, and change delay to 3 secs to match with
Snackbar.LENGTH_LONG
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=288d08ff269a25aeab367f1f6f11b35b6dfd1e83
---
.../vlc/gui/audio/AudioAlbumsSongsFragment.java | 5 +-
.../vlc/gui/audio/AudioBrowserFragment.java | 5 +-
.../videolan/vlc/gui/video/VideoGridFragment.java | 72 +++++++++++++++-----
.../videolan/vlc/gui/video/VideoListHandler.java | 1 +
4 files changed, 61 insertions(+), 22 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
index 6504444..747202b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -54,6 +54,7 @@ import org.videolan.vlc.MediaLibrary;
import org.videolan.vlc.MediaWrapper;
import org.videolan.vlc.PlaybackServiceController;
import org.videolan.vlc.R;
+import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.dialogs.CommonDialogs;
import org.videolan.vlc.gui.SecondaryActivity;
import org.videolan.vlc.util.AndroidDevices;
@@ -73,7 +74,7 @@ public class AudioAlbumsSongsFragment extends Fragment implements SwipeRefreshLa
public final static String TAG = "VLC/AudioAlbumsSongsFragment";
private static final int DELETE_MEDIA = 0;
- private static final int DELETE_DURATION = 4000;
+ private static final int DELETE_DURATION = 3000;
PlaybackServiceController mAudioController;
private MediaLibrary mMediaLibrary;
@@ -399,7 +400,7 @@ public class AudioAlbumsSongsFragment extends Fragment implements SwipeRefreshLa
fragment.mMediaLibrary.getMediaItems().remove(media);
new Thread(new Runnable() {
public void run() {
- Util.recursiveDelete(fragment.getActivity(), new File(path));
+ Util.recursiveDelete(VLCApplication.getAppContext(), new File(path));
}
}).start();
break;
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index 1c32313..4aeb121 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -59,6 +59,7 @@ import org.videolan.vlc.MediaLibrary;
import org.videolan.vlc.MediaWrapper;
import org.videolan.vlc.PlaybackServiceController;
import org.videolan.vlc.R;
+import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.SecondaryActivity;
import org.videolan.vlc.gui.browser.MediaBrowserFragment;
@@ -103,7 +104,7 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
public static final int DELETE_MEDIA = 101;
public static final int DELETE_PLAYLIST = 102;
- public static final int DELETE_DURATION = 4000;
+ public static final int DELETE_DURATION = 3000;
public final static int MODE_ARTIST = 0;
public final static int MODE_ALBUM = 1;
public final static int MODE_SONG = 2;
@@ -666,7 +667,7 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
Toast.makeText(fragment.getActivity(), "deleting file", Toast.LENGTH_SHORT).show();
new Thread(new Runnable() {
public void run() {
- Util.recursiveDelete(fragment.getActivity(), new File(path));
+ Util.recursiveDelete(VLCApplication.getAppContext(), new File(path));
}
}).start();
fragment.mMediaLibrary.getMediaItems().remove(mw);
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 22ae8fb..118950d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -31,9 +31,10 @@ import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
+import android.os.Message;
import android.preference.PreferenceManager;
+import android.support.design.widget.Snackbar;
import android.support.v4.app.FragmentActivity;
-import android.support.v7.app.AlertDialog;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.ContextMenu;
@@ -62,7 +63,7 @@ import org.videolan.vlc.MediaWrapper;
import org.videolan.vlc.PlaybackServiceController;
import org.videolan.vlc.R;
import org.videolan.vlc.Thumbnailer;
-import org.videolan.vlc.gui.dialogs.CommonDialogs;
+import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.SecondaryActivity;
import org.videolan.vlc.gui.browser.MediaBrowserFragment;
@@ -71,9 +72,10 @@ import org.videolan.vlc.interfaces.IVideoBrowser;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.VLCInstance;
-import org.videolan.vlc.util.VLCRunnable;
+import org.videolan.vlc.util.WeakHandler;
import org.videolan.vlc.widget.SwipeRefreshLayout;
+import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.BrokenBarrierException;
@@ -85,6 +87,9 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
public final static String KEY_GROUP = "key_group";
+ private static final int DELETE_MEDIA = 0;
+ private static final int DELETE_DURATION = 3000;
+
protected static final String ACTION_SCAN_START = "org.videolan.vlc.gui.ScanStart";
protected static final String ACTION_SCAN_STOP = "org.videolan.vlc.gui.ScanStop";
protected static final int UPDATE_ITEM = 0;
@@ -330,20 +335,11 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
}
return true;
case R.id.video_list_delete:
- AlertDialog alertDialog = CommonDialogs.deleteMedia(
- getActivity(),
- media.getLocation(),
- new VLCRunnable(media) {
- @Override
- public void run(Object o) {
- MediaWrapper media = (MediaWrapper) o;
- mMediaLibrary.getMediaItems().remove(media);
- mVideoAdapter.remove(media);
- if (mAudioController.getMediaLocations().contains(media.getLocation()))
- mAudioController.removeLocation(media.getLocation());
- }
- });
- alertDialog.show();
+ Snackbar.make(getView(), getString(R.string.playlist_deleted), Snackbar.LENGTH_LONG)
+ .setAction(android.R.string.cancel, mCancelDeleteMediaListener)
+ .show();
+ Message msg = mDeleteHandler.obtainMessage(DELETE_MEDIA, position, 0);
+ mDeleteHandler.sendMessageDelayed(msg, DELETE_DURATION);
return true;
}
return false;
@@ -558,7 +554,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
- mViewNomedia.setVisibility(mVideoAdapter.getCount()>0 ? View.GONE : View.VISIBLE);
+ mViewNomedia.setVisibility(mVideoAdapter.getCount() > 0 ? View.GONE : View.VISIBLE);
mReadyToDisplay = true;
mVideoAdapter.setNotifyOnChange(true);
mVideoAdapter.sort();
@@ -573,4 +569,44 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
public void clear(){
mVideoAdapter.clear();
}
+
+ public void deleteMedia(int position){
+ MediaWrapper media = mVideoAdapter.getItem(position);
+ final String path = media.getUri().getPath();
+ new Thread(new Runnable() {
+ public void run() {
+ Util.recursiveDelete(VLCApplication.getAppContext(), new File(path));
+ }
+ }).start();
+ mMediaLibrary.getMediaItems().remove(media);
+ mVideoAdapter.remove(media);
+ if (mAudioController.getMediaLocations().contains(media.getLocation()))
+ mAudioController.removeLocation(media.getLocation());
+ }
+
+
+ View.OnClickListener mCancelDeleteMediaListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ mDeleteHandler.removeMessages(DELETE_MEDIA);
+ }
+ };
+
+ Handler mDeleteHandler = new VideoDeleteHandler(this);
+
+ private static class VideoDeleteHandler extends WeakHandler<VideoGridFragment>{
+
+ public VideoDeleteHandler(VideoGridFragment owner) {
+ super(owner);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ super.handleMessage(msg);
+ switch (msg.what){
+ case DELETE_MEDIA:
+ getOwner().deleteMedia(msg.arg1);
+ }
+ }
+ }
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListHandler.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListHandler.java
index 0105dfd..afdb069 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListHandler.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListHandler.java
@@ -25,6 +25,7 @@ public class VideoListHandler extends WeakHandler<IVideoBrowser> {
break;
case MediaLibrary.MEDIA_ITEMS_UPDATED:
owner.updateList();
+ break;
}
}
};
\ No newline at end of file
More information about the Android
mailing list