[Android] Do not store mContext in Directory*
Jean-Baptiste Kempf
git at videolan.org
Mon Jun 25 12:59:00 CEST 2012
android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Mon Jun 25 12:52:22 2012 +0200| [c31eb21fb82551ceac9027fe4d3e0ce6c709778a] | committer: Jean-Baptiste Kempf
Do not store mContext in Directory*
> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=c31eb21fb82551ceac9027fe4d3e0ce6c709778a
---
.../src/org/videolan/vlc/gui/DirectoryAdapter.java | 24 +++++++++++---------
.../videolan/vlc/gui/DirectoryViewFragment.java | 8 +------
.../src/org/videolan/vlc/gui/MainActivity.java | 2 +-
3 files changed, 15 insertions(+), 19 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
index e876448..6dc7588 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
@@ -31,6 +31,7 @@ import org.videolan.vlc.LibVLC;
import org.videolan.vlc.Media;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
+import org.videolan.vlc.VLCApplication;
import android.content.Context;
import android.preference.PreferenceManager;
@@ -175,29 +176,27 @@ public class DirectoryAdapter extends BaseAdapter {
}
}
- private Context mContext;
private LayoutInflater mInflater;
private DirectoryAdapter.Node mRootNode;
private DirectoryAdapter.Node mCurrentNode;
private String mRootDir;
private String mCurrentDir;
- public DirectoryAdapter(Context context) {
- DirectoryAdapter_Core(context,
- PreferenceManager.getDefaultSharedPreferences(context)
+ public DirectoryAdapter() {
+ DirectoryAdapter_Core(
+ PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext())
.getString("directories_root", android.os.Environment.getExternalStorageDirectory().getPath())
);
}
public DirectoryAdapter(Context context, String rootDir) {
- DirectoryAdapter_Core(context, rootDir);
+ DirectoryAdapter_Core(rootDir);
}
- private void DirectoryAdapter_Core(Context context, String rootDir) {
+ private void DirectoryAdapter_Core(String rootDir) {
rootDir = Util.stripTrailingSlash(rootDir);
Log.v(TAG, "rootMRL is " + rootDir);
- mContext = context;
- mInflater = LayoutInflater.from(context);
+ mInflater = LayoutInflater.from(VLCApplication.getAppContext());
mRootNode = new DirectoryAdapter.Node(rootDir);
mCurrentDir = rootDir;
mRootDir = rootDir;
@@ -233,6 +232,9 @@ public class DirectoryAdapter extends BaseAdapter {
DirectoryAdapter.Node selectedNode = mCurrentNode.children.get(position);
DirectoryViewHolder holder;
View v = convertView;
+
+ Context context = VLCApplication.getAppContext();
+
/* If view not created */
if (v == null) {
v = mInflater.inflate(R.layout.directory_view_item, parent, false);
@@ -257,20 +259,20 @@ public class DirectoryAdapter extends BaseAdapter {
holder.title.setText(selectedNode.name);
if(selectedNode.name == "..")
- holderText = mContext.getString(R.string.parent_folder);
+ holderText = context.getString(R.string.parent_folder);
else if(!selectedNode.isFile()) {
int folderCount = selectedNode.subfolderCount();
int songCount = selectedNode.subfilesCount();
holderText = "";
if(folderCount > 0)
- holderText += mContext.getResources().getQuantityString(
+ holderText += context.getResources().getQuantityString(
R.plurals.subfolders, folderCount, folderCount
);
if(folderCount > 0 && songCount > 0)
holderText += ", ";
if(songCount > 0)
- holderText += mContext.getResources().getQuantityString(
+ holderText += context.getResources().getQuantityString(
R.plurals.songs, songCount, songCount
);
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java b/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
index 93183be..b4ba96b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
@@ -31,7 +31,6 @@ import org.videolan.vlc.gui.audio.AudioPlayerActivity;
import org.videolan.vlc.gui.video.VideoPlayerActivity;
import org.videolan.vlc.interfaces.ISortable;
-import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -45,17 +44,12 @@ public class DirectoryViewFragment extends SherlockListFragment implements ISort
public final static String TAG = "VLC/DirectoryViewFragment";
private DirectoryAdapter mDirectoryAdapter;
- private final Context mContext;
-
- public DirectoryViewFragment(Context context) {
- mContext = context;
- }
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mDirectoryAdapter = new DirectoryAdapter(mContext);
+ mDirectoryAdapter = new DirectoryAdapter();
}
@Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index df9c9ad..c5ef1f9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -130,7 +130,7 @@ public class MainActivity extends SherlockFragmentActivity {
this, "audio", AudioBrowserFragment.class)));
/* DirectoryView */
- mDirectoryView = new DirectoryViewFragment(this);
+ mDirectoryView = new DirectoryViewFragment();
mDirectoryView.setRetainInstance(true); /* Retain instance across attach/detach */
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_placeholder, mDirectoryView)
More information about the Android
mailing list