[Android] VideoGridFragment: don't overuse context

Jean-Baptiste Kempf git at videolan.org
Sun Jul 6 08:24:10 CEST 2014


vlc-ports/android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Sun Jul  6 05:36:23 2014 +0200| [8faa09da54e8baa4da3880a2341a1761207794e7] | committer: Jean-Baptiste Kempf

VideoGridFragment: don't overuse context

Just to send a broadcast, use the VLCApplication context

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

 vlc-android/src/org/videolan/vlc/MediaLibrary.java      |    2 +-
 .../org/videolan/vlc/gui/video/VideoGridFragment.java   |   15 ++++++---------
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaLibrary.java b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
index 8c03a48..6f8e3b5 100644
--- a/vlc-android/src/org/videolan/vlc/MediaLibrary.java
+++ b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
@@ -81,7 +81,7 @@ public class MediaLibrary {
     public void loadMediaItems(Context context) {
         if (mLoadingThread == null || mLoadingThread.getState() == State.TERMINATED) {
             isStopping = false;
-            VideoGridFragment.actionScanStart(context.getApplicationContext());
+            VideoGridFragment.actionScanStart();
             mLoadingThread = new Thread(new GetMediaItemsRunnable(context.getApplicationContext()));
             mLoadingThread.start();
         }
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 a1567f6..4f7d464 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -35,6 +35,7 @@ import org.videolan.vlc.MediaLibrary;
 import org.videolan.vlc.R;
 import org.videolan.vlc.Thumbnailer;
 import org.videolan.vlc.Util;
+import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.VlcRunnable;
 import org.videolan.vlc.WeakHandler;
 import org.videolan.vlc.gui.CommonDialogs;
@@ -153,7 +154,7 @@ public class VideoGridFragment extends SherlockGridFragment implements ISortable
         getActivity().registerReceiver(messageReceiverVideoListFragment, filter);
         Log.i(TAG,"mMediaLibrary.isWorking() " + Boolean.toString(mMediaLibrary.isWorking()));
         if (mMediaLibrary.isWorking()) {
-            actionScanStart(getActivity().getApplicationContext());
+            actionScanStart();
         }
 
         mAnimator = new VideoGridAnimator(getGridView());
@@ -479,19 +480,15 @@ public class VideoGridFragment extends SherlockGridFragment implements ISortable
         }
     };
 
-    public static void actionScanStart(Context context) {
-        if (context == null)
-            return;
+    public static void actionScanStart() {
         Intent intent = new Intent();
         intent.setAction(ACTION_SCAN_START);
-        context.getApplicationContext().sendBroadcast(intent);
+        VLCApplication.getAppContext().sendBroadcast(intent);
     }
 
-    public static void actionScanStop(Context context) {
-        if (context == null)
-            return;
+    public static void actionScanStop() {
         Intent intent = new Intent();
         intent.setAction(ACTION_SCAN_STOP);
-        context.getApplicationContext().sendBroadcast(intent);
+        VLCApplication.getAppContext().sendBroadcast(intent);
     }
 }



More information about the Android mailing list