[Android] Factorize list->array conversion for playlist

Geoffrey Métais git at videolan.org
Wed Mar 22 10:20:44 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Mar 22 10:19:47 2017 +0100| [bb81142e05101f1faa2966a07cc1bdb0b2db8cc4] | committer: Geoffrey Métais

Factorize list->array conversion for playlist

> https://code.videolan.org/videolan/vlc-android/commit/bb81142e05101f1faa2966a07cc1bdb0b2db8cc4
---

 vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java     |  6 ++----
 .../src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java       |  4 +---
 .../src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java  |  4 +---
 .../src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java     | 10 +++-------
 vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java      |  9 +++++++--
 5 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
index 7a4b895..0fdd39e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
@@ -259,10 +259,8 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
             case R.id.action_mode_audio_append:
                 mService.append(tracks);
                 break;
-            case R.id.action_mode_audio_add_playlist:
-                MediaWrapper[] trackList = new MediaWrapper[tracks.size()];
-                tracks.toArray(trackList);
-                UiTools.addToPlaylist(this, trackList);
+            case R.id.action_mode_audio_add_playlist:;
+                UiTools.addToPlaylist(this, tracks);
                 break;
             case R.id.action_mode_audio_info:
                 showInfoDialog((MediaWrapper) list.get(0));
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java b/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java
index 732e156..6e54704 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java
@@ -90,9 +90,7 @@ public abstract class BaseAudioBrowser extends MediaBrowserFragment implements I
                     mService.append(tracks);
                     break;
                 case R.id.action_mode_audio_add_playlist:
-                    MediaWrapper[] trackList = new MediaWrapper[tracks.size()];
-                    tracks.toArray(trackList);
-                    UiTools.addToPlaylist(getActivity(), trackList);
+                    UiTools.addToPlaylist(getActivity(), tracks);
                     break;
                 case R.id.action_mode_audio_info:
                     showInfoDialog(list.get(0));
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 49825fc..537b83a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -751,9 +751,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
                         deleteMedia(media, true);
                     break;
                 case R.id.action_mode_file_add_playlist:
-                    MediaWrapper[] trackList = new MediaWrapper[list.size()];
-                    list.toArray(trackList);
-                    UiTools.addToPlaylist(getActivity(), trackList);
+                    UiTools.addToPlaylist(getActivity(), list);
                     break;
                 case R.id.action_mode_file_info:
                     showMediaInfo(list.get(0));
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
index e235d4b..573d6e7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
@@ -34,7 +34,6 @@ import android.content.res.TypedArray;
 import android.graphics.Color;
 import android.os.Build;
 import android.os.Bundle;
-import android.os.Parcelable;
 import android.support.v4.app.DialogFragment;
 import android.support.v4.content.ContextCompat;
 import android.support.v7.preference.PreferenceManager;
@@ -229,12 +228,9 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
                 tag = "select_chapter";
                 break;
             case ID_SAVE_PLAYLIST:
-                newFragment = new SavePlaylistDialog();
-                Bundle args = new Bundle();
-                args.putParcelableArray(SavePlaylistDialog.KEY_TRACKS, (Parcelable[]) mService.getMedias().toArray());
-                newFragment.setArguments(args);
-                tag = "fragment_save_playlist";
-                break;
+                UiTools.addToPlaylist(getActivity(), mService.getMedias());
+                dismiss();
+                return;
             default:
                 return;
         }
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
index 8d9cddb..a14c342 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
@@ -38,7 +38,6 @@ import android.preference.PreferenceManager;
 import android.renderscript.Allocation;
 import android.renderscript.Element;
 import android.renderscript.RenderScript;
-import android.renderscript.ScriptIntrinsic;
 import android.renderscript.ScriptIntrinsicBlur;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
@@ -66,7 +65,7 @@ import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.dialogs.SavePlaylistDialog;
 
-import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
 public class UiTools {
@@ -245,6 +244,12 @@ public class UiTools {
         });
     }
 
+    public static void addToPlaylist(FragmentActivity activity, List<MediaWrapper> list) {
+        MediaWrapper[] trackList = new MediaWrapper[list.size()];
+        list.toArray(trackList);
+        addToPlaylist(activity, trackList);
+    }
+
     public static void addToPlaylist(FragmentActivity activity, MediaWrapper[] tracks) {
         SavePlaylistDialog savePlaylistDialog = new SavePlaylistDialog();
         Bundle args = new Bundle();



More information about the Android mailing list