[Android] Audio context menu: factorization

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


android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Thu Jun 21 14:04:59 2012 +0200| [182281d4acf144f7ec131939b155a2ed0547e1e8] | committer: Jean-Baptiste Kempf

Audio context menu: factorization

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

 .../vlc/gui/audio/AudioBrowserActivity.java        |   55 +++++++++++---------
 1 file changed, 29 insertions(+), 26 deletions(-)

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 37dbc47..91e0118 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserActivity.java
@@ -201,7 +201,32 @@ public class AudioBrowserActivity 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)
+        .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);
+                updateLists();
+            }
+        })
+        .setNegativeButton(android.R.string.cancel, null).create();
+        
+        alertDialog.show();
+    }
+    
     @Override
     public boolean onContextItemSelected(MenuItem item) {
         int startPosition;
@@ -226,33 +251,11 @@ public class AudioBrowserActivity extends SherlockFragment implements ISortable
             childPosition = 0;
         }
 
-        if (id == MENU_DELETE){
-            final int groupPositionDelete = groupPosition;
-            AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
-            .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();
+        if (id == MENU_DELETE) {
+            deleteMedia(mSongsAdapter.getLocation(groupPosition), mSongsAdapter.getItem(groupPosition));
             return true;
         }
-
+        
         if (play_all) {
             startPosition = groupPosition;
             medias = mSongsAdapter.getLocations();



More information about the Android mailing list