[Android] Reload library on fragment restore if needed

Geoffrey Métais git at videolan.org
Wed Aug 12 11:43:35 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Aug 12 11:42:48 2015 +0200| [2a24ef0075191a12c6e3a0c82c20936da0524ec5] | committer: Geoffrey Métais

Reload library on fragment restore if needed

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=2a24ef0075191a12c6e3a0c82c20936da0524ec5
---

 .../videolan/vlc/gui/audio/AudioBrowserFragment.java  |    3 ---
 .../vlc/gui/browser/MediaBrowserFragment.java         |   17 +++++++++++++++++
 .../org/videolan/vlc/gui/video/VideoGridFragment.java |    2 --
 3 files changed, 17 insertions(+), 5 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 ea133c6..5755e0e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -80,7 +80,6 @@ import java.util.concurrent.Executors;
 public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeRefreshLayout.OnRefreshListener, MediaBrowser.EventListener, IBrowser {
     public final static String TAG = "VLC/AudioBrowserFragment";
 
-    private MediaLibrary mMediaLibrary;
     private MediaBrowser mMediaBrowser;
     private MainActivity mMainActivity;
 
@@ -118,8 +117,6 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
-        mMediaLibrary = MediaLibrary.getInstance();
-
         mSongsAdapter = new AudioBrowserListAdapter(getActivity(), AudioBrowserListAdapter.ITEM_WITH_COVER);
         mArtistsAdapter = new AudioBrowserListAdapter(getActivity(), AudioBrowserListAdapter.ITEM_WITH_COVER);
         mAlbumsAdapter = new AudioBrowserListAdapter(getActivity(), AudioBrowserListAdapter.ITEM_WITH_COVER);
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java
index 484727a..3e7962e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java
@@ -22,8 +22,10 @@
 
 package org.videolan.vlc.gui.browser;
 
+import android.os.Bundle;
 import android.support.v7.app.AppCompatActivity;
 
+import org.videolan.vlc.MediaLibrary;
 import org.videolan.vlc.gui.PlaybackServiceFragment;
 import org.videolan.vlc.widget.SwipeRefreshLayout;
 
@@ -31,6 +33,21 @@ public abstract class MediaBrowserFragment extends PlaybackServiceFragment {
 
     protected SwipeRefreshLayout mSwipeRefreshLayout;
     protected volatile boolean mReadyToDisplay = true;
+    protected MediaLibrary mMediaLibrary;
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        mMediaLibrary = MediaLibrary.getInstance();
+    }
+
+    @Override
+    public void onViewStateRestored(Bundle savedInstanceState) {
+        super.onViewStateRestored(savedInstanceState);
+        if (MediaLibrary.getInstance().getMediaItems().isEmpty()) {
+            mMediaLibrary.loadMediaItems();
+        }
+    }
 
     public void setReadyToDisplay(boolean ready) {
         if (ready && !mReadyToDisplay)
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 91886b5..8aa25e6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -107,7 +107,6 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
     protected final CyclicBarrier mBarrier = new CyclicBarrier(2);
 
     private VideoListAdapter mVideoAdapter;
-    private MediaLibrary mMediaLibrary;
     private Thumbnailer mThumbnailer;
     private VideoGridAnimator mAnimator;
 
@@ -124,7 +123,6 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
         super.onCreate(savedInstanceState);
 
         mVideoAdapter = new VideoListAdapter(this);
-        mMediaLibrary = MediaLibrary.getInstance();
 
         if (savedInstanceState != null)
             setGroup(savedInstanceState.getString(KEY_GROUP));



More information about the Android mailing list