[Android] src: Add a CommonDialogs to avoid code duplication
Edward Wang
git at videolan.org
Wed Jul 11 05:04:41 CEST 2012
android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Tue Jul 10 22:59:40 2012 -0400| [a48ddb288defeecb325a49dae689bdff4c7fa82f] | committer: Edward Wang
src: Add a CommonDialogs to avoid code duplication
> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=a48ddb288defeecb325a49dae689bdff4c7fa82f
---
.../src/org/videolan/vlc/gui/CommonDialogs.java | 61 ++++++++++++++++++++
.../vlc/gui/audio/AudioBrowserFragment.java | 47 +++++----------
2 files changed, 77 insertions(+), 31 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/CommonDialogs.java b/vlc-android/src/org/videolan/vlc/gui/CommonDialogs.java
new file mode 100644
index 0000000..1395bf5
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/gui/CommonDialogs.java
@@ -0,0 +1,61 @@
+/*****************************************************************************
+ * CommonDialogs.java
+ *****************************************************************************
+ * Copyright © 2012 VLC authors and VideoLAN
+ * Copyright © 2012 Edward Wang
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+package org.videolan.vlc.gui;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import org.videolan.vlc.R;
+import org.videolan.vlc.VLCCallbackTask;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+
+public class CommonDialogs {
+ public final static String TAG = "VLC/CommonDialogs";
+
+ public static AlertDialog deleteMedia( final Context context, final String addressMedia, final VLCCallbackTask task ) {
+ AlertDialog alertDialog = new AlertDialog.Builder(context)
+ .setTitle(R.string.confirm_delete)
+ .setMessage(R.string.validation)
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int whichButton) {
+ URI adressMediaUri = null;
+ try {
+ adressMediaUri = new URI (addressMedia);
+ } catch (URISyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ File fileMedia = new File(adressMediaUri);
+ fileMedia.delete();
+ if(task != null)
+ task.run();
+ }
+ })
+ .setNegativeButton(android.R.string.cancel, null).create();
+
+ return alertDialog;
+ }
+}
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 66dd063..03a970c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -20,9 +20,6 @@
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;
@@ -31,13 +28,14 @@ import org.videolan.vlc.AudioServiceController;
import org.videolan.vlc.Media;
import org.videolan.vlc.MediaLibrary;
import org.videolan.vlc.R;
+import org.videolan.vlc.VLCCallbackTask;
import org.videolan.vlc.WeakHandler;
+import org.videolan.vlc.gui.CommonDialogs;
import org.videolan.vlc.interfaces.ISortable;
import org.videolan.vlc.widget.FlingViewGroup;
import org.videolan.vlc.widget.FlingViewGroup.ViewSwitchListener;
import android.app.AlertDialog;
-import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
@@ -234,32 +232,6 @@ 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)
- .setMessage(R.string.validation)
- .setIcon(android.R.drawable.ic_dialog_alert)
- .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
- @Override
- 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 void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
MenuInflater inflater = getActivity().getMenuInflater();
@@ -297,7 +269,20 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
}
if (id == R.id.audio_list_browser_delete) {
- deleteMedia(mSongsAdapter.getLocation(groupPosition), mSongsAdapter.getItem(groupPosition));
+ AlertDialog alertDialog = CommonDialogs.deleteMedia(getActivity(), mSongsAdapter.getLocation(groupPosition).get(0),
+ new VLCCallbackTask(new VLCCallbackTask.CallbackListener() {
+
+ @Override
+ public void callback_object(Object o) {
+ Media aMedia = (Media)o;
+ mMediaLibrary.getMediaItems().remove(aMedia);
+ updateLists();
+ }
+
+ @Override
+ public void callback() { }
+ }, mSongsAdapter.getItem(groupPosition)));
+ alertDialog.show();
return true;
}
More information about the Android
mailing list