[Android] Pass medialist reference via Application singleton

Geoffrey Métais git at videolan.org
Thu Jan 28 13:03:41 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jan 28 13:01:47 2016 +0100| [264c472117e17550a85ebe22ad009e57932500e2] | committer: Geoffrey Métais

Pass medialist reference via Application singleton

- Avoids the 1Mb limit of parcelable objects
- Avoids the serialization/deserialization process

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

 .../src/org/videolan/vlc/gui/SecondaryActivity.java    | 14 +++++++++-----
 .../src/org/videolan/vlc/gui/audio/AlbumAdapter.java   |  7 ++++---
 .../org/videolan/vlc/gui/audio/AudioAlbumFragment.java |  2 +-
 .../vlc/gui/audio/AudioAlbumsSongsFragment.java        |  7 ++-----
 .../videolan/vlc/gui/audio/AudioBrowserFragment.java   | 18 +++++++++---------
 5 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java b/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java
index 34224f2..befd8ec 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java
@@ -30,6 +30,7 @@ import android.view.Menu;
 import android.view.MenuItem;
 
 import org.videolan.vlc.R;
+import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.audio.AudioAlbumFragment;
 import org.videolan.vlc.gui.audio.AudioAlbumsSongsFragment;
 import org.videolan.vlc.gui.audio.EqualizerFragment;
@@ -49,6 +50,9 @@ public class SecondaryActivity extends AudioPlayerContainerActivity {
 
     public static final int ACTIVITY_RESULT_SECONDARY = 3;
 
+    public static final String KEY_FRAGMENT = "fragment";
+    public static final String KEY_FILTER = "filter";
+
     public static final String ALBUMS_SONGS = "albumsSongs";
     public static final String ALBUM = "album";
     public static final String EQUALIZER = "equalizer";
@@ -68,7 +72,7 @@ public class SecondaryActivity extends AudioPlayerContainerActivity {
         mActionBar.setDisplayHomeAsUpEnabled(true);
 
         if (getSupportFragmentManager().getFragments() == null) {
-            String fragmentId = getIntent().getStringExtra("fragment");
+            String fragmentId = getIntent().getStringExtra(KEY_FRAGMENT);
             fetchSecondaryFragment(fragmentId);
             if (mFragment == null){
                 finish();
@@ -138,13 +142,13 @@ public class SecondaryActivity extends AudioPlayerContainerActivity {
 
     public void fetchSecondaryFragment(String id) {
         if (id.equals(ALBUMS_SONGS)) {
-            ArrayList<MediaWrapper> mediaList = getIntent().getParcelableArrayListExtra("list");
-            String filter = getIntent().getStringExtra("filter");
+            ArrayList<MediaWrapper> mediaList = (ArrayList<MediaWrapper>) VLCApplication.getData(ALBUMS_SONGS);
+            String filter = getIntent().getStringExtra(KEY_FILTER);
             mFragment = new AudioAlbumsSongsFragment();
             ((AudioAlbumsSongsFragment) mFragment).setMediaList(mediaList, filter);
         } else if(id.equals(ALBUM)) {
-            ArrayList<MediaWrapper> mediaList = getIntent().getParcelableArrayListExtra("list");
-            String filter = getIntent().getStringExtra("filter");
+            ArrayList<MediaWrapper> mediaList = (ArrayList<MediaWrapper>) VLCApplication.getData(ALBUM);
+            String filter = getIntent().getStringExtra(KEY_FILTER);
             mFragment = new AudioAlbumFragment();
             ((AudioAlbumFragment) mFragment).setMediaList(mediaList, filter);
         } else if(id.equals(EQUALIZER)) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AlbumAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AlbumAdapter.java
index 96f0d55..091bb31 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AlbumAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AlbumAdapter.java
@@ -112,10 +112,11 @@ public class AlbumAdapter extends BaseAdapter implements IAudioClickHandler{
     }
 
     public void addAll(ArrayList<MediaWrapper> tracks){
-        if (tracks != null)
+        if (tracks != null) {
             Collections.sort(tracks, MediaComparators.byTrackNumber);
-        mMediaList = new ArrayList<>(tracks);
-        notifyDataSetChanged();
+            mMediaList = new ArrayList<>(tracks);
+            notifyDataSetChanged();
+        }
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumFragment.java
index d9f09bc..2db50a5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumFragment.java
@@ -73,12 +73,12 @@ public class AudioAlbumFragment extends PlaybackServiceFragment implements Adapt
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        mAdapter = new AlbumAdapter(getActivity(), mMediaList);
 
         mAdapter.setContextPopupMenuListener(mContextPopupMenuListener);
 
         if (savedInstanceState != null)
             setMediaList(savedInstanceState.<MediaWrapper>getParcelableArrayList("list"), savedInstanceState.getString("title"));
+        mAdapter = new AlbumAdapter(getActivity(), mMediaList);
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
index 11aa659..678fe43 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -73,9 +73,6 @@ public class AudioAlbumsSongsFragment extends PlaybackServiceFragment implements
 
     public final static String TAG = "VLC/AudioAlbumsSongsFragment";
 
-    private static final int DELETE_MEDIA = 0;
-    private static final int DELETE_DURATION = 3000;
-
     private MediaLibrary mMediaLibrary;
     private PlaybackService.Client mClient;
     Handler mHandler = new Handler(Looper.getMainLooper());
@@ -315,8 +312,8 @@ public class AudioAlbumsSongsFragment extends PlaybackServiceFragment implements
         public void onItemClick(AdapterView<?> av, View v, int p, long id) {
             ArrayList<MediaWrapper> mediaList = mAlbumsAdapter.getMedias(p);
             Intent i = new Intent(getActivity(), SecondaryActivity.class);
-            i.putExtra("fragment", SecondaryActivity.ALBUM);
-            i.putParcelableArrayListExtra("list", mediaList);
+            i.putExtra(SecondaryActivity.KEY_FRAGMENT, SecondaryActivity.ALBUM);
+            VLCApplication.storeData(SecondaryActivity.ALBUM, mediaList);
             i.putExtra("filter", mAlbumsAdapter.getTitle(p));
             startActivity(i);
         }
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 0c403aa..e11cb8c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -345,9 +345,9 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
                 return;
             MainActivity activity = (MainActivity)getActivity();
             Intent i = new Intent(getActivity(), SecondaryActivity.class);
-            i.putExtra("fragment", "albumsSongs");
-            i.putParcelableArrayListExtra("list", mediaList);
-            i.putExtra("filter", MediaUtils.getMediaArtist(activity, mediaList.get(0)));
+            i.putExtra(SecondaryActivity.KEY_FRAGMENT, SecondaryActivity.ALBUMS_SONGS);
+            VLCApplication.storeData(SecondaryActivity.ALBUMS_SONGS, mediaList);
+            i.putExtra(SecondaryActivity.KEY_FILTER, MediaUtils.getMediaArtist(activity, mediaList.get(0)));
             startActivity(i);
         }
     };
@@ -359,9 +359,9 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
             if (mediaList.isEmpty())
                 return;
             Intent i = new Intent(getActivity(), SecondaryActivity.class);
-            i.putExtra("fragment", SecondaryActivity.ALBUM);
-            i.putParcelableArrayListExtra("list", mediaList);
-            i.putExtra("filter", MediaUtils.getMediaAlbum(getActivity(), mediaList.get(0)));
+            i.putExtra(SecondaryActivity.KEY_FRAGMENT, SecondaryActivity.ALBUM);
+            VLCApplication.storeData(SecondaryActivity.ALBUM, mediaList);
+            i.putExtra(SecondaryActivity.KEY_FILTER, MediaUtils.getMediaAlbum(getActivity(), mediaList.get(0)));
             startActivity(i);
         }
     };
@@ -373,9 +373,9 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
             if (mediaList.isEmpty())
                 return;
             Intent i = new Intent(getActivity(), SecondaryActivity.class);
-            i.putExtra("fragment", SecondaryActivity.ALBUMS_SONGS);
-            i.putParcelableArrayListExtra("list", mediaList);
-            i.putExtra("filter", MediaUtils.getMediaGenre(getActivity(), mediaList.get(0)));
+            i.putExtra(SecondaryActivity.KEY_FRAGMENT, SecondaryActivity.ALBUMS_SONGS);
+            VLCApplication.storeData(SecondaryActivity.ALBUMS_SONGS, mediaList);
+            i.putExtra(SecondaryActivity.KEY_FILTER, MediaUtils.getMediaGenre(getActivity(), mediaList.get(0)));
             startActivity(i);
         }
     };



More information about the Android mailing list