[Android] Allow deletion in AudioListActivity too

Jean-Baptiste Kempf git at videolan.org
Thu Jun 21 17:40:53 CEST 2012


android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Thu Jun 21 17:40:17 2012 +0200| [e5f80d29f3aa2deaacb7f15186c9841cb1fe01ba] | committer: Jean-Baptiste Kempf

Allow deletion in AudioListActivity too

> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=e5f80d29f3aa2deaacb7f15186c9841cb1fe01ba
---

 .../vlc/gui/audio/AudioBrowserFragment.java        |   16 +++---
 .../videolan/vlc/gui/audio/AudioListActivity.java  |   55 ++++++++++++++++----
 2 files changed, 55 insertions(+), 16 deletions(-)

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 69d5916..6c3e96d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -201,7 +201,7 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
             }
         }
     };
-    
+
     public void deleteMedia( final List<String> addressMedia, final Media aMedia ) {
         AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
         .setTitle(R.string.confirm_delete)
@@ -226,7 +226,7 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
         
         alertDialog.show();
     }
-    
+
     @Override
     public boolean onContextItemSelected(MenuItem item) {
         int startPosition;
@@ -234,8 +234,9 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
         int childPosition;
         List<String> medias;
         int id = item.getItemId();
-        boolean play_all = id == MENU_PLAY_ALL || id == MENU_APPEND_ALL;
-        boolean play_append = id == MENU_APPEND || id == MENU_APPEND_ALL;
+
+        boolean useAllItems = id == MENU_PLAY_ALL || id == MENU_APPEND_ALL;
+        boolean append = id == MENU_APPEND || id == MENU_APPEND_ALL;
 
         ContextMenuInfo menuInfo = item.getMenuInfo();
         if (ExpandableListContextMenuInfo.class.isInstance(menuInfo)) {
@@ -255,8 +256,8 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
             deleteMedia(mSongsAdapter.getLocation(groupPosition), mSongsAdapter.getItem(groupPosition));
             return true;
         }
-        
-        if (play_all) {
+
+        if (useAllItems) {
             startPosition = groupPosition;
             medias = mSongsAdapter.getLocations();
         }
@@ -280,7 +281,8 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
                     return true;
             }
         }
-        if (play_append)
+
+        if (append)
             mAudioController.append(medias);
         else
             mAudioController.load(medias, startPosition);
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioListActivity.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioListActivity.java
index d5538ec..5d83b20 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioListActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioListActivity.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;
@@ -29,6 +32,8 @@ import org.videolan.vlc.Media;
 import org.videolan.vlc.MediaLibrary;
 import org.videolan.vlc.R;
 
+import android.app.AlertDialog;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.os.Bundle;
 import android.os.Handler;
@@ -124,31 +129,63 @@ public class AudioListActivity extends SherlockListActivity {
             menu.add(Menu.NONE, AudioBrowserFragment.MENU_APPEND, Menu.NONE, R.string.append);
             menu.add(Menu.NONE, AudioBrowserFragment.MENU_PLAY_ALL, Menu.NONE, R.string.play_all);
             menu.add(Menu.NONE, AudioBrowserFragment.MENU_APPEND_ALL, Menu.NONE, R.string.append_all);
+            menu.add(Menu.NONE, AudioBrowserFragment.MENU_DELETE, Menu.NONE, R.string.delete);
         }
     };
 
+    public void deleteMedia( final List<String> addressMedia, final Media aMedia ) {
+        AlertDialog alertDialog = new AlertDialog.Builder(this)
+        .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) {
+                URI adressMediaUri = null;
+                try {
+                    adressMediaUri = new URI (addressMedia.get(0));
+                } catch (URISyntaxException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+                File fileMedia =  new File(adressMediaUri);
+                fileMedia.delete();
+                mMediaLibrary.getMediaItems().remove(aMedia);
+                updateList();
+            }
+        })
+        .setNegativeButton(android.R.string.cancel, null).create();
+        
+        alertDialog.show();
+    }
+
     @Override
     public boolean onContextItemSelected(MenuItem item) {
         AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
+        int startPosition;
+        List<String> medias;
         int id = item.getItemId();
 
-        boolean play_all = id == AudioBrowserFragment.MENU_PLAY_ALL || id == AudioBrowserFragment.MENU_APPEND_ALL;
-        boolean play_append = id == AudioBrowserFragment.MENU_APPEND || id == AudioBrowserFragment.MENU_APPEND_ALL;
-        int start_position;
-        List<String> medias;
+        boolean useAllItems = id == AudioBrowserFragment.MENU_PLAY_ALL || id == AudioBrowserFragment.MENU_APPEND_ALL;
+        boolean append = id == AudioBrowserFragment.MENU_APPEND || id == AudioBrowserFragment.MENU_APPEND_ALL;
+
+        if (id == AudioBrowserFragment.MENU_DELETE) {
+            deleteMedia(mSongsAdapter.getLocation(menuInfo.position),
+                        mSongsAdapter.getItem(menuInfo.position));
+            return true;
+        }
 
-        if (play_all) {
-            start_position = menuInfo.position;
+        if (useAllItems) {
+            startPosition = menuInfo.position;
             medias = mSongsAdapter.getLocations();
         }
         else {
-            start_position = 0;
+            startPosition = 0;
             medias = mSongsAdapter.getLocation(menuInfo.position);
         }
-        if (play_append)
+        if (append)
             mAudioController.append(medias);
         else
-            mAudioController.load(medias, start_position);
+            mAudioController.load(medias, startPosition);
 
         Intent intent = new Intent(AudioListActivity.this, AudioPlayerActivity.class);
         intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);



More information about the Android mailing list