Commit 348e0ec5 authored by Sébastien Toque's avatar Sébastien Toque
Browse files
parent 09145083
......@@ -88,7 +88,7 @@ public class AudioBrowserActivity extends Activity {
mHeader = (HorizontalScrollView) findViewById(R.id.header);
mAudioController = AudioServiceController.getInstance();
mMediaLibrary = MediaLibrary.getInstance(this);
mMediaLibrary = MediaLibrary.getInstance();
mMediaLibrary.addUpdateHandler(mHandler);
mSongsAdapter = new AudioSongsListAdapter(this, R.layout.audio_browser_item);
......@@ -291,7 +291,7 @@ public class AudioBrowserActivity extends Activity {
};
private void updateLists() {
List<Media> audioList = MediaLibrary.getInstance(this).getAudioItems();
List<Media> audioList = MediaLibrary.getInstance().getAudioItems();
mSongsAdapter.clear();
mArtistsAdapter.clear();
mAlbumsAdapter.clear();
......
......@@ -63,7 +63,7 @@ public class AudioListActivity extends ListActivity {
mAudioController = AudioServiceController.getInstance();
mMediaLibrary = MediaLibrary.getInstance(this);
mMediaLibrary = MediaLibrary.getInstance();
mMediaLibrary.addUpdateHandler(mHandler);
mTitle = (TextView) findViewById(R.id.title);
......@@ -189,11 +189,11 @@ public class AudioListActivity extends ListActivity {
if (name == null || mode == 0) {
mTitle.setText(R.string.songs);
itemList = AudioServiceController.getInstance().getItems();
audioList = MediaLibrary.getInstance(this).getMediaItems(itemList);
audioList = MediaLibrary.getInstance().getMediaItems(itemList);
}
else {
mTitle.setText(name);
audioList = MediaLibrary.getInstance(this).getAudioItems(name, mode);
audioList = MediaLibrary.getInstance().getAudioItems(name, mode);
}
mSongsAdapter.clear();
......
......@@ -463,7 +463,7 @@ public class AudioService extends Service {
DatabaseManager db = DatabaseManager.getInstance();
for (int i = 0; i < mediaPathList.size(); i++) {
String path = mediaPathList.get(i);
Media media = db.getMedia(path);
Media media = db.getMedia(AudioService.this, path);
mMediaList.add(media);
}
......@@ -486,7 +486,7 @@ public class AudioService extends Service {
DatabaseManager db = DatabaseManager.getInstance();
for (int i = 0; i < mediaPathList.size(); i++) {
String path = mediaPathList.get(i);
Media media = db.getMedia(path);
Media media = db.getMedia(AudioService.this, path);
mMediaList.add(media);
}
}
......
......@@ -127,7 +127,7 @@ public class BrowserActivity extends ListActivity {
@Override
protected void onStop() {
// Update the MediaList
MediaLibrary.getInstance(this).loadMediaItems();
MediaLibrary.getInstance().loadMediaItems();
super.onStop();
}
......
......@@ -73,8 +73,6 @@ public class DatabaseManager {
private final String SEARCHHISTORY_DATE = "date";
private final String SEARCHHISTORY_KEY = "key";
private Context mContext;
public enum mediaColumn {
MEDIA_TABLE_NAME, MEDIA_PATH, MEDIA_TIME, MEDIA_LENGTH,
MEDIA_TYPE, MEDIA_PICTURE, MEDIA_TITLE, MEDIA_ARTIST, MEDIA_GENRE, MEDIA_ALBUM
......@@ -86,7 +84,6 @@ public class DatabaseManager {
* @param context
*/
private DatabaseManager(Context context) {
mContext = context;
// create or open database
DatabaseHelper helper = new DatabaseHelper(context);
this.mDb = helper.getWritableDatabase();
......@@ -223,7 +220,7 @@ public class DatabaseManager {
PLAYLIST_MEDIA_PLAYLISTNAME + "=?", new String[] { playlistName },
null, null, "ASC");
MediaLibrary mediaLibrary = MediaLibrary.getInstance(mContext);
MediaLibrary mediaLibrary = MediaLibrary.getInstance();
cursor.moveToFirst();
if (!cursor.isAfterLast()) {
do {
......@@ -297,7 +294,7 @@ public class DatabaseManager {
return files;
}
public synchronized HashMap<String, Media> getMedias() {
public synchronized HashMap<String, Media> getMedias(Context context) {
Cursor cursor;
HashMap<String, Media> medias = new HashMap<String, Media>();
......@@ -329,7 +326,7 @@ public class DatabaseManager {
picture = BitmapFactory.decodeByteArray(blob, 0, blob.length);
}
Media media = new Media(mContext, new File(cursor.getString(8)), cursor.getLong(0),
Media media = new Media(context, new File(cursor.getString(8)), cursor.getLong(0),
cursor.getLong(1), cursor.getInt(2),
picture, cursor.getString(4),
cursor.getString(5), cursor.getString(6),
......@@ -346,7 +343,7 @@ public class DatabaseManager {
return medias;
}
public synchronized Media getMedia(String path) {
public synchronized Media getMedia(Context context, String path) {
Cursor cursor;
Media media = null;
......@@ -375,7 +372,7 @@ public class DatabaseManager {
picture = BitmapFactory.decodeByteArray(blob, 0, blob.length);
}
media = new Media(mContext, new File(path), cursor.getLong(0),
media = new Media(context, new File(path), cursor.getLong(0),
cursor.getLong(1), cursor.getInt(2),
picture, cursor.getString(4),
cursor.getString(5), cursor.getString(6),
......
......@@ -23,7 +23,6 @@ import org.videolan.vlc.android.LibVlcException;
import android.util.Log;
import android.view.Surface;
import android.preference.PreferenceManager;
import android.content.SharedPreferences;
import android.os.Build;
public class LibVLC {
......
......@@ -137,7 +137,7 @@ public class MainActivity extends TabActivity {
}
/* Load media items from database and storage */
MediaLibrary.getInstance(this).loadMediaItems();
MediaLibrary.getInstance().loadMediaItems();
}
@Override
......@@ -220,7 +220,7 @@ public class MainActivity extends TabActivity {
break;
// Refresh
case R.id.ml_menu_refresh:
MediaLibrary.getInstance(this).loadMediaItems();
MediaLibrary.getInstance().loadMediaItems();
break;
}
return super.onOptionsItemSelected(item);
......
......@@ -70,15 +70,12 @@ public class Media implements Comparable<Media> {
private int mHeight = 0;
private Bitmap mPicture;
private Context mContext;
/**
* Create an new Media
* @param file: path on the local storage
*/
public Media(Context context, File file) {
this.mFile = file;
mContext = context;
LibVLC mLibVlc = null;
try {
......@@ -97,13 +94,13 @@ public class Media implements Comparable<Media> {
mTitle = v;
Log.d(TAG, "Title " + mTitle);
} else if (s.equals("artist")) {
mArtist = v;
mArtist = v != null ? v : context.getString(R.string.unknown_artist);
Log.d(TAG, "Artist " + mArtist);
} else if (s.equals("genre")) {
mGenre = v;
Log.d(TAG, "Genre " + mGenre);
} else if (s.equals("album")) {
mAlbum = v;
mAlbum = v != null ? v : context.getString(R.string.unknown_album);
Log.d(TAG, "Album " + mAlbum);
}
}
......@@ -118,8 +115,6 @@ public class Media implements Comparable<Media> {
public Media(Context context, File file, long time, long length, int type,
Bitmap picture, String title, String artist, String genre, String album) {
mContext = context;
mFile = file;
mTime = time;
mLength = length;
......@@ -127,9 +122,9 @@ public class Media implements Comparable<Media> {
mPicture = picture;
mTitle = title;
mArtist = artist;
mArtist = artist != null ? artist : context.getString(R.string.unknown_artist);
mGenre = genre;
mAlbum = album;
mAlbum = album != null ? album : context.getString(R.string.unknown_album);
}
/**
......@@ -201,10 +196,7 @@ public class Media implements Comparable<Media> {
}
public String getArtist() {
if (mArtist == null)
return mContext.getString(R.string.unknown_artist);
else
return mArtist;
return mArtist;
}
public String getGenre() {
......@@ -216,10 +208,7 @@ public class Media implements Comparable<Media> {
}
public String getAlbum() {
if (mAlbum == null)
return mContext.getString(R.string.unknown_album);
else
return mAlbum;
return mAlbum;
}
public String getTrackNumber() {
......
......@@ -45,7 +45,7 @@ public class MediaInfoActivity extends Activity {
String path = getIntent().getExtras().getString("filePath");
if (path == null)
return;
mItem = MediaLibrary.getInstance(this).getMediaItem(path);
mItem = MediaLibrary.getInstance().getMediaItem(path);
// set title
TextView titleView = (TextView) findViewById(R.id.title);
......
......@@ -30,7 +30,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Stack;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Environment;
import android.os.Handler;
......@@ -45,12 +44,10 @@ public class MediaLibrary {
private DatabaseManager mDBManager;
private ArrayList<Media> mItemList;
private ArrayList<Handler> mUpdateHandler;
protected Context mContext;
protected Thread mLoadingThread;
private MediaLibrary(Context context) {
private MediaLibrary() {
mInstance = this;
mContext = context;
mItemList = new ArrayList<Media>();
mUpdateHandler = new ArrayList<Handler>();
mDBManager = DatabaseManager.getInstance();
......@@ -63,9 +60,9 @@ public class MediaLibrary {
}
}
public static MediaLibrary getInstance(Context context) {
public static MediaLibrary getInstance() {
if (mInstance == null)
mInstance = new MediaLibrary(context);
mInstance = new MediaLibrary();
return mInstance;
}
......@@ -177,7 +174,7 @@ public class MediaLibrary {
directorys.add(new File(root));
// get all existing media items
HashMap<String, Media> existingMedias = mDBManager.getMedias();
HashMap<String, Media> existingMedias = mDBManager.getMedias(mMainActivity);
// list of all added files
HashSet<File> addedFiles = new HashSet<File>();
......@@ -233,7 +230,7 @@ public class MediaLibrary {
}
} else {
// create new media item
mItemList.add(new Media(mContext, file));
mItemList.add(new Media(mMainActivity, file));
}
} else if (file.isDirectory()) {
directorys.push(file);
......
......@@ -106,7 +106,7 @@ public class SearchActivity extends ListActivity {
// set result adapter to the list
mResultAdapter.clear();
String[] keys = key.toString().split("\\s+");
ArrayList<Media> allItems = MediaLibrary.getInstance(this).getMediaItems();
ArrayList<Media> allItems = MediaLibrary.getInstance().getMediaItems();
int results = 0;
for (int i = 0; i < allItems.size(); i++) {
Media item = allItems.get(i);
......
......@@ -59,7 +59,7 @@ public class VideoListActivity extends ListActivity {
mNoFileLayout = (LinearLayout) findViewById(R.id.video_list_empty_nofile);
mLoadFileLayout = (LinearLayout) findViewById(R.id.video_list_empty_loadfile);
mMediaLibrary = MediaLibrary.getInstance(this);
mMediaLibrary = MediaLibrary.getInstance();
mMediaLibrary.addUpdateHandler(mHandler);
mThumbnailerManager = new ThumbnailerManager();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment