[Android] Delete song in contextMenuListener
Alexandre Perraud
git at videolan.org
Wed Jun 20 17:19:32 CEST 2012
android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Wed Jun 20 17:04:21 2012 +0200| [cf5aad852c40bd2499baf24e1904a12336f10ec2] | committer: Jean-Baptiste Kempf
Delete song in contextMenuListener
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=cf5aad852c40bd2499baf24e1904a12336f10ec2
---
vlc-android/res/values/strings.xml | 2 ++
.../vlc/gui/audio/AudioBrowserActivity.java | 35 +++++++++++++++++++-
.../vlc/gui/audio/AudioSongsListAdapter.java | 6 ++++
3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 7d4ee42..7eaecec 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -23,6 +23,8 @@
<string name="append">Append</string>
<string name="play_all">Play all</string>
<string name="append_all">Append all</string>
+ <string name="delete">Delete</string>
+ <string name="confirm_delete">Delete this file ?</string>
<string name="pause">Pause</string>
<string name="close">Close</string>
<string name="not_show_again">"Don't show this message again."</string>
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserActivity.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserActivity.java
index 4a32dc2..bf02608 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserActivity.java
@@ -20,6 +20,9 @@
package org.videolan.vlc.gui.audio;
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -33,6 +36,8 @@ import org.videolan.vlc.widget.FlingViewGroup;
import org.videolan.vlc.widget.FlingViewGroup.ViewSwitchListener;
import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
@@ -82,6 +87,7 @@ public class AudioBrowserActivity extends Activity implements ISortable {
public final static int MENU_APPEND = Menu.FIRST + 1;
public final static int MENU_PLAY_ALL = Menu.FIRST + 2;
public final static int MENU_APPEND_ALL = Menu.FIRST + 3;
+ public final static int MENU_DELETE = Menu.FIRST + 4;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -173,6 +179,7 @@ public class AudioBrowserActivity extends Activity implements ISortable {
if (v.getId() == R.id.songs_list) {
menu.add(Menu.NONE, MENU_PLAY_ALL, Menu.NONE, R.string.play_all);
menu.add(Menu.NONE, MENU_APPEND_ALL, Menu.NONE, R.string.append_all);
+ menu.add(Menu.NONE, MENU_DELETE, Menu.NONE, R.string.delete);
}
}
};
@@ -196,12 +203,38 @@ public class AudioBrowserActivity extends Activity implements ISortable {
childPosition = 0;
}
else {
-
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
groupPosition = info.position;
childPosition = 0;
}
+ if (id == MENU_DELETE){
+ final int groupPositionDelete = groupPosition;
+ AlertDialog alertDialog = new AlertDialog.Builder(this.getParent())
+ .setTitle(R.string.confirm_delete)
+ .setMessage(R.string.validation)
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+ List<String> adressMedia = mSongsAdapter.getLocation(groupPositionDelete);
+ URI adressMediaUri = null;
+ try {
+ adressMediaUri = new URI (adressMedia.get(0));
+ } catch (URISyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ File fileMedia = new File(adressMediaUri);
+ fileMedia.delete();
+ mMediaLibrary.getMediaItems().remove(mSongsAdapter.getItem(groupPositionDelete));
+ updateLists();
+ }
+ })
+ .setNegativeButton(android.R.string.cancel, null).create();
+ alertDialog.show();
+ return true;
+ }
+
if (play_all) {
startPosition = groupPosition;
medias = mSongsAdapter.getLocations();
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioSongsListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioSongsListAdapter.java
index 10538e5..7a58d60 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioSongsListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioSongsListAdapter.java
@@ -53,6 +53,12 @@ public class AudioSongsListAdapter extends ArrayAdapter<Media> {
}
@Override
+ public void remove(Media m) {
+ mMediaList.remove(m);
+ super.remove(m);
+ }
+
+ @Override
public void clear() {
mMediaList.clear();
super.clear();
More information about the Android
mailing list