Commit 270a40cc authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf
Browse files

Remove context from MediaDatabase.getInstance() parameters

parent 55ed03dc
......@@ -101,9 +101,9 @@ public class MediaDatabase {
this.mDb = helper.getWritableDatabase();
}
public synchronized static MediaDatabase getInstance(Context context) {
public synchronized static MediaDatabase getInstance() {
if (instance == null) {
instance = new MediaDatabase(context.getApplicationContext());
instance = new MediaDatabase(VLCApplication.getAppContext());
}
return instance;
}
......
......@@ -215,7 +215,7 @@ public class MediaLibrary {
}
// Initialize variables
final MediaDatabase DBManager = MediaDatabase.getInstance(VLCApplication.getAppContext());
final MediaDatabase DBManager = MediaDatabase.getInstance();
// show progressbar in footer
MainActivity.showProgressBar();
......@@ -322,7 +322,7 @@ public class MediaLibrary {
Media m = new Media(libVlcInstance, fileURI);
mItemList.add(m);
// Add this item to database
MediaDatabase db = MediaDatabase.getInstance(VLCApplication.getAppContext());
MediaDatabase db = MediaDatabase.getInstance();
db.addMedia(m);
mItemListLock.writeLock().unlock();
}
......
......@@ -76,7 +76,7 @@ public class VLCApplication extends Application {
instance = this;
// Initialize the database soon enough to avoid any race condition and crash
MediaDatabase.getInstance(this);
MediaDatabase.getInstance();
// Prepare cache folder constants
AudioUtil.prepareCacheFolder(this);
}
......
......@@ -417,8 +417,7 @@ public class AudioService extends Service {
String location = service.mLibVLC.getMediaList().getMRL(service.mCurrentIndex);
long length = service.mLibVLC.getLength();
MediaDatabase dbManager = MediaDatabase
.getInstance(VLCApplication.getAppContext());
MediaDatabase dbManager = MediaDatabase.getInstance();
Media m = dbManager.getMedia(location);
/**
* 1) There is a media to update
......@@ -1098,7 +1097,7 @@ public class AudioService extends Service {
mPrevious.clear();
MediaDatabase db = MediaDatabase.getInstance(AudioService.this);
MediaDatabase db = MediaDatabase.getInstance();
for (int i = 0; i < mediaPathList.size(); i++) {
String location = mediaPathList.get(i);
Media media = db.getMedia(location);
......@@ -1203,7 +1202,7 @@ public class AudioService extends Service {
return;
}
MediaDatabase db = MediaDatabase.getInstance(AudioService.this);
MediaDatabase db = MediaDatabase.getInstance();
for (int i = 0; i < mediaLocationList.size(); i++) {
String location = mediaLocationList.get(i);
Media media = db.getMedia(location);
......
......@@ -124,7 +124,7 @@ public class BrowserActivity extends ListActivity {
@Override
public boolean onMenuItemClick(MenuItem arg0) {
// remove any checkmarks of the custom item
final MediaDatabase dbManager = MediaDatabase.getInstance(BrowserActivity.this);
final MediaDatabase dbManager = MediaDatabase.getInstance();
for(File f : dbManager.getMediaDirs()) {
if(f.getPath().startsWith(item.getPath()))
dbManager.removeDir(f.getPath());
......
......@@ -76,7 +76,7 @@ public class BrowserAdapter extends ArrayAdapter<File>
holder = (ViewHolder) view.getTag();
final File item = getItem(position);
final MediaDatabase dbManager = MediaDatabase.getInstance(view.getContext());
final MediaDatabase dbManager = MediaDatabase.getInstance();
if(item != null && item.getPath().equals(ADD_ITEM_PATH)) {
holder.text.setText(R.string.add_custom_path);
......@@ -112,7 +112,7 @@ public class BrowserAdapter extends ArrayAdapter<File>
private final OnCheckedChangeListener onCheckedChangeListener = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
final MediaDatabase dbManager = MediaDatabase.getInstance(buttonView.getContext());
final MediaDatabase dbManager = MediaDatabase.getInstance();
File item = (File) buttonView.getTag();
if (item == null)
return;
......
......@@ -670,7 +670,7 @@ public class MainActivity extends ActionBarActivity {
mMenu.showMenu();
break;
case R.id.search_clear_history:
MediaDatabase.getInstance(this).clearSearchHistory();
MediaDatabase.getInstance().clearSearchHistory();
break;
}
return super.onOptionsItemSelected(item);
......
......@@ -143,7 +143,7 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
@Override
public void onClick(DialogInterface dialog, int whichButton) {
MediaDatabase db = MediaDatabase.getInstance(getApplicationContext());
MediaDatabase db = MediaDatabase.getInstance();
db.clearSearchHistory();
}
})
......@@ -159,7 +159,7 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
MediaDatabase.getInstance(getBaseContext()).emptyDatabase();
MediaDatabase.getInstance().emptyDatabase();
BitmapCache.getInstance().clear();
AudioUtil.clearCacheFolders();
Toast.makeText(getBaseContext(), R.string.media_db_cleared, Toast.LENGTH_SHORT).show();
......
......@@ -155,7 +155,7 @@ public class SearchFragment extends ListFragment {
String headerText = getString(R.string.search_history);
showListHeader(headerText);
MediaDatabase db = MediaDatabase.getInstance(getActivity());
MediaDatabase db = MediaDatabase.getInstance();
mHistoryAdapter.clear();
ArrayList<String> history = db.getSearchhistory(20);
for (String s : history)
......@@ -205,7 +205,7 @@ public class SearchFragment extends ListFragment {
mSearchText.requestFocus();
} else if (getListAdapter() == mResultAdapter) {
// add search text to the database (history)
MediaDatabase db = MediaDatabase.getInstance(getActivity());
MediaDatabase db = MediaDatabase.getInstance();
db.addSearchhistoryItem(mSearchText.getText().toString());
// open media in the player
......
......@@ -175,7 +175,7 @@ public class VideoGridFragment extends SherlockGridFragment implements ISortable
public void onResume() {
super.onResume();
//Get & set times
HashMap<String, Long> times = MediaDatabase.getInstance(getActivity()).getVideoTimes(getActivity());
HashMap<String, Long> times = MediaDatabase.getInstance().getVideoTimes(getActivity());
mVideoAdapter.setTimes(times);
mVideoAdapter.notifyDataSetChanged();
updateList();
......
......@@ -462,8 +462,8 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
SharedPreferences.Editor editor = mSettings.edit();
// Save position
if (time >= 0 && mCanSeek) {
if(MediaDatabase.getInstance(this).mediaItemExists(mLocation)) {
MediaDatabase.getInstance(this).updateMedia(
if(MediaDatabase.getInstance().mediaItemExists(mLocation)) {
MediaDatabase.getInstance().updateMedia(
mLocation,
MediaDatabase.mediaColumn.MEDIA_TIME,
time);
......@@ -1377,7 +1377,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
}
if(trackID < 0) return;
MediaDatabase.getInstance(VideoPlayerActivity.this).updateMedia(
MediaDatabase.getInstance().updateMedia(
mLocation,
MediaDatabase.mediaColumn.MEDIA_AUDIOTRACK,
trackID);
......@@ -1424,7 +1424,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
}
if(trackID < -1) return;
MediaDatabase.getInstance(VideoPlayerActivity.this).updateMedia(
MediaDatabase.getInstance().updateMedia(
mLocation,
MediaDatabase.mediaColumn.MEDIA_SPUTRACK,
trackID);
......@@ -1710,7 +1710,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
int time = (int) mLibVLC.getTime();
int length = (int) mLibVLC.getLength();
if (length == 0) {
Media media = MediaDatabase.getInstance(this).getMedia(mLocation);
Media media = MediaDatabase.getInstance().getMedia(mLocation);
if (media != null)
length = (int) media.getLength();
}
......@@ -1941,7 +1941,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
if (mLocation != null && mLocation.length() > 0 && !dontParse) {
// restore last position
Media media = MediaDatabase.getInstance(this).getMedia(mLocation);
Media media = MediaDatabase.getInstance().getMedia(mLocation);
if(media != null) {
// in media library
if(media.getTime() > 0 && !fromStart)
......
......@@ -47,7 +47,6 @@ import org.videolan.libvlc.Media;
import org.videolan.vlc.MediaDatabase;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.VlcCrashHandler;
import org.videolan.vlc.MediaDatabase.mediaColumn;
import org.videolan.vlc.gui.NativeCrashActivity;
import android.content.Context;
......@@ -390,7 +389,7 @@ public class Util {
* adding it to the memcache for later use.
*/
Context c = VLCApplication.getAppContext();
picture = MediaDatabase.getInstance(c).getPicture(c, media.getLocation());
picture = MediaDatabase.getInstance().getPicture(c, media.getLocation());
cache.addBitmapToMemCache(media.getLocation(), picture);
}
return picture;
......@@ -402,7 +401,7 @@ public class Util {
public static void setPicture(Context context, Media m, Bitmap p) {
Log.d(TAG, "Setting new picture for " + m.getTitle());
try {
MediaDatabase.getInstance(context).updateMedia(
MediaDatabase.getInstance().updateMedia(
m.getLocation(),
MediaDatabase.mediaColumn.MEDIA_PICTURE,
p);
......
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