[Android] Remove useless Context references

Geoffrey Métais git at videolan.org
Wed May 13 12:16:12 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed May 13 11:17:19 2015 +0200| [0689aabbcfe2e74c04170096776d2406a9186172] | committer: Geoffrey Métais

Remove useless Context references

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

 vlc-android/src/org/videolan/vlc/MediaLibrary.java    |    2 +-
 .../src/org/videolan/vlc/gui/MainActivity.java        |   17 ++++++++++-------
 .../src/org/videolan/vlc/gui/SecondaryActivity.java   |    2 +-
 .../videolan/vlc/gui/audio/AudioBrowserFragment.java  |    2 +-
 .../org/videolan/vlc/gui/video/MediaInfoFragment.java |    2 +-
 .../org/videolan/vlc/gui/video/VideoGridFragment.java |    5 ++---
 .../org/videolan/vlc/gui/video/VideoListAdapter.java  |    9 ++++-----
 7 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaLibrary.java b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
index 6fde980..44bb220 100644
--- a/vlc-android/src/org/videolan/vlc/MediaLibrary.java
+++ b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
@@ -93,7 +93,7 @@ public class MediaLibrary {
         mItemListLock = new ReentrantReadWriteLock();
     }
 
-    public void loadMediaItems(Context context, boolean restart) {
+    public void loadMediaItems(boolean restart) {
         if (restart && isWorking()) {
             /* do a clean restart if a scan is ongoing */
             mRestart = true;
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 47591c3..cddcc91 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -89,6 +89,8 @@ public class MainActivity extends AudioPlayerContainerActivity implements OnItem
     private static final int ACTIVITY_HIDE_PROGRESSBAR = 4;
     private static final int ACTIVITY_SHOW_TEXTINFO = 5;
 
+    MediaLibrary mMediaLibrary;
+
     private SidebarAdapter mSidebarAdapter;
     private HackyDrawerLayout mDrawerLayout;
     private ListView mListView;
@@ -133,7 +135,8 @@ public class MainActivity extends AudioPlayerContainerActivity implements OnItem
         }
 
         /* Load media items from database and storage */
-        MediaLibrary.getInstance().loadMediaItems();
+        mMediaLibrary = MediaLibrary.getInstance();
+        mMediaLibrary.loadMediaItems();
 
         /*** Start initializing the UI ***/
 
@@ -223,7 +226,7 @@ public class MainActivity extends AudioPlayerContainerActivity implements OnItem
 
         /* Load media items from database and storage */
         if (mScanNeeded)
-            MediaLibrary.getInstance().loadMediaItems();
+            mMediaLibrary.loadMediaItems();
         if (mSlidingPane.getState() == mSlidingPane.STATE_CLOSED)
             mActionBar.hide();
    }
@@ -277,9 +280,9 @@ public class MainActivity extends AudioPlayerContainerActivity implements OnItem
         super.onPause();
 
         /* Check for an ongoing scan that needs to be resumed during onResume */
-        mScanNeeded = MediaLibrary.getInstance().isWorking();
+        mScanNeeded = mMediaLibrary.isWorking();
         /* Stop scanning for files */
-        MediaLibrary.getInstance().stop();
+        mMediaLibrary.stop();
         /* Save the tab status in pref */
         SharedPreferences.Editor editor = mSettings.edit();
         editor.putString("fragment", mCurrentFragment);
@@ -491,11 +494,11 @@ public class MainActivity extends AudioPlayerContainerActivity implements OnItem
                 break;
             // Refresh
             case R.id.ml_menu_refresh:
-                if (!MediaLibrary.getInstance().isWorking()) {
+                if (!mMediaLibrary.isWorking()) {
                     if(current != null && current instanceof IRefreshable)
                         ((IRefreshable) current).refresh();
                     else
-                        MediaLibrary.getInstance().loadMediaItems(this, true);
+                        mMediaLibrary.loadMediaItems(true);
                 }
                 break;
             // Restore last playlist
@@ -538,7 +541,7 @@ public class MainActivity extends AudioPlayerContainerActivity implements OnItem
         super.onActivityResult(requestCode, resultCode, data);
         if (requestCode == ACTIVITY_RESULT_PREFERENCES) {
             if (resultCode == PreferencesActivity.RESULT_RESCAN)
-                MediaLibrary.getInstance().loadMediaItems(this, true);
+                mMediaLibrary.loadMediaItems(true);
             else if (resultCode == PreferencesActivity.RESULT_RESTART) {
                 Intent intent = getIntent();
                 finish();
diff --git a/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java b/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java
index 094b260..975f2b9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java
@@ -121,7 +121,7 @@ public class SecondaryActivity extends AudioPlayerContainerActivity {
                 break;
             case R.id.ml_menu_refresh:
                 if (!MediaLibrary.getInstance().isWorking())
-                    MediaLibrary.getInstance().loadMediaItems(this, true);
+                    MediaLibrary.getInstance().loadMediaItems(true);
                 break;
         }
         return super.onOptionsItemSelected(item);
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 f04b2e3..fee060f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -548,7 +548,7 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
     @Override
     public void onRefresh() {
         if (!MediaLibrary.getInstance().isWorking())
-            MediaLibrary.getInstance().loadMediaItems(getActivity(), true);
+            MediaLibrary.getInstance().loadMediaItems(true);
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
index 0f28689..3245ebd 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
@@ -321,7 +321,7 @@ public class MediaInfoFragment extends ListFragment {
                     break;
                 case EXIT:
                     fragment.getActivity().finish();
-                    MediaLibrary.getInstance().loadMediaItems(fragment.getActivity(), true);
+                    MediaLibrary.getInstance().loadMediaItems(true);
                     break;
                 case SHOW_SUBTITLES:
                     fragment.mSubtitles.setVisibility(View.VISIBLE);
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 e9904dd..740b41e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -30,7 +30,6 @@ import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.os.Build;
 import android.os.Bundle;
-import android.os.Environment;
 import android.os.Handler;
 import android.preference.PreferenceManager;
 import android.support.v4.app.FragmentActivity;
@@ -123,7 +122,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
 
         mAudioController = AudioServiceController.getInstance();
 
-        mVideoAdapter = new VideoListAdapter(getActivity(), this);
+        mVideoAdapter = new VideoListAdapter(this);
         mMediaLibrary = MediaLibrary.getInstance();
 
         if (savedInstanceState != null)
@@ -550,7 +549,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
     @Override
     public void onRefresh() {
         if (getActivity()!=null && !MediaLibrary.getInstance().isWorking())
-            MediaLibrary.getInstance().loadMediaItems(getActivity(), true);
+            MediaLibrary.getInstance().loadMediaItems(true);
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index 6c51007..bf8df07 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -36,6 +36,7 @@ import android.widget.TextView;
 import org.videolan.vlc.MediaGroup;
 import org.videolan.vlc.MediaWrapper;
 import org.videolan.vlc.R;
+import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.util.BitmapCache;
 import org.videolan.vlc.util.BitmapUtil;
 import org.videolan.vlc.util.Strings;
@@ -54,12 +55,10 @@ public class VideoListAdapter extends ArrayAdapter<MediaWrapper>
     private int mSortDirection = 1;
     private int mSortBy = SORT_BY_TITLE;
     private boolean mListMode = false;
-    private Context mContext;
     private VideoGridFragment mFragment;
 
-    public VideoListAdapter(Context context, VideoGridFragment fragment) {
-        super(context, 0);
-        mContext = context;
+    public VideoListAdapter(VideoGridFragment fragment) {
+        super(fragment.getActivity(), 0);
         mFragment = fragment;
     }
 
@@ -218,7 +217,7 @@ public class VideoListAdapter extends ArrayAdapter<MediaWrapper>
 
         /* Color state */
         ColorStateList titleColor = v.getResources().getColorStateList(
-                Util.getResourceFromAttribute(mContext, R.attr.list_title));
+                Util.getResourceFromAttribute(getContext(), R.attr.list_title));
         holder.title.setTextColor(titleColor);
 
         if (media instanceof MediaGroup)



More information about the Android mailing list