Commit 3881a509 authored by Ludovic Fauvet's avatar Ludovic Fauvet
Browse files

MainActivity: start a rescan of the media library only if needed

A rescan will only be triggered if a previous scan was ongoing during
the last call to onPause().
parent fe103f0d
......@@ -71,6 +71,14 @@ public class MediaLibrary {
isStopping = true;
}
public boolean isWorking() {
if (mLoadingThread != null &&
mLoadingThread.getState() != State.TERMINATED &&
mLoadingThread.getState() != State.NEW)
return true;
return false;
}
public static MediaLibrary getInstance(Context context) {
if (mInstance == null)
mInstance = new MediaLibrary(context);
......
......@@ -103,6 +103,7 @@ public class MainActivity extends SherlockFragmentActivity {
private int mVersionNumber = -1;
private boolean mFirstRun = false;
private boolean mScanNeeded = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -305,7 +306,8 @@ public class MainActivity extends SherlockFragmentActivity {
getIntent().removeExtra(AudioService.START_FROM_NOTIFICATION);
/* Load media items from database and storage */
MediaLibrary.getInstance(this).loadMediaItems(this);
if (mScanNeeded)
MediaLibrary.getInstance(this).loadMediaItems(this);
super.onResume();
}
......@@ -315,6 +317,8 @@ public class MainActivity extends SherlockFragmentActivity {
*/
@Override
protected void onPause() {
/* Check for an ongoing scan that needs to be resumed during onResume */
mScanNeeded = MediaLibrary.getInstance(this).isWorking();
/* Stop scanning for files */
MediaLibrary.getInstance(this).stop();
/* Stop the thumbnailer */
......
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