Commit a9da204a authored by Geoffrey Métais's avatar Geoffrey Métais

Update Medialibrary method to check if scanning

parent 2c74b883
......@@ -16,7 +16,7 @@ checkfail()
# ARGUMENTS #
#############
MEDIALIBRARY_HASH=1b6ac171
MEDIALIBRARY_HASH=a490aec
RELEASE=0
ASAN=0
......
......@@ -113,12 +113,6 @@ AndroidMediaLibrary::entryPoints()
return p_ml->entryPoints();
}
bool
AndroidMediaLibrary::isWorking()
{
return !m_paused && (m_nbDiscovery > 0 || (m_progress > 0 && m_progress < 100));
}
void
AndroidMediaLibrary::pauseBackgroundOperations()
{
......@@ -759,6 +753,21 @@ void AndroidMediaLibrary::onParsingStatsUpdated( uint32_t percent)
}
}
void AndroidMediaLibrary::onBackgroundTasksIdleChanged( bool isIdle )
{
JNIEnv *env = getEnv();
if (env == NULL)
return;
jobject thiz = getWeakReference(env);
if (thiz != NULL)
{
env->CallVoidMethod(thiz, p_fields->MediaLibrary.onBackgroundTasksIdleChangedId, isIdle);
if (weak_compat)
env->DeleteLocalRef(thiz);
}
}
jobject
AndroidMediaLibrary::getWeakReference(JNIEnv *env)
{
......
......@@ -37,7 +37,6 @@ public:
void discover(const std::string&);
void removeEntryPoint(const std::string& entryPoint);
std::vector<medialibrary::FolderPtr> entryPoints();
bool isWorking();
void setMediaUpdatedCbFlag(int flags);
void setMediaAddedCbFlag(int flags);
void pauseBackgroundOperations();
......@@ -114,6 +113,7 @@ public:
void onEntryPointUnbanned( const std::string& entryPoint, bool success );
void onEntryPointRemoved( const std::string& entryPoint, bool success );
void onParsingStatsUpdated( uint32_t percent);
void onBackgroundTasksIdleChanged( bool isIdle );
private:
void jni_detach_thread(void *data);
......
......@@ -135,13 +135,6 @@ removeDevice(JNIEnv* env, jobject thiz, jstring uuid)
return removed;
}
jboolean
isWorking(JNIEnv* env, jobject thiz)
{
AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
return (jboolean) aml->isWorking();
}
void
setMediaUpdatedCbFlag(JNIEnv* env, jobject thiz, jint flags)
{
......@@ -785,7 +778,6 @@ static JNINativeMethod methods[] = {
{"nativeGetGenre", "(J)Lorg/videolan/medialibrary/media/Genre;", (void*)getGenre },
{"nativeGetPlaylists", "()[Lorg/videolan/medialibrary/media/Playlist;", (void*)getPlaylists },
{"nativeGetPlaylist", "(J)Lorg/videolan/medialibrary/media/Playlist;", (void*)getPlaylist },
{"nativeIsWorking", "()Z", (void*)isWorking },
{"nativePauseBackgroundOperations", "()V", (void*)pauseBackgroundOperations },
{"nativeResumeBackgroundOperations", "()V", (void*)resumeBackgroundOperations },
{"nativeReload", "()V", (void*)reload },
......@@ -1045,6 +1037,10 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
ml_fields.MediaLibrary.onParsingStatsUpdatedId,
ml_fields.MediaLibrary.clazz,
"onParsingStatsUpdated", "(I)V");
GET_ID(GetMethodID,
ml_fields.MediaLibrary.onBackgroundTasksIdleChangedId,
ml_fields.MediaLibrary.clazz,
"onBackgroundTasksIdleChanged", "(Z)V");
GET_ID(GetMethodID,
ml_fields.MediaLibrary.onReloadStartedId,
ml_fields.MediaLibrary.clazz,
......
......@@ -53,6 +53,7 @@ struct fields {
jmethodID onDiscoveryProgressId;
jmethodID onDiscoveryCompletedId;
jmethodID onParsingStatsUpdatedId;
jmethodID onBackgroundTasksIdleChangedId;
jmethodID onReloadStartedId;
jmethodID onReloadCompletedId;
jmethodID onEntryPointBannedId;
......
......@@ -46,8 +46,11 @@ public class Medialibrary {
public static final String VLC_MEDIA_DB_NAME = "/vlc_media.db";
public static final String THUMBS_FOLDER_NAME = "/thumbs";
private Context mContext;
private long mInstanceID;
private volatile boolean mIsInitiated = false;
private boolean mIsWorking = false;
private MediaUpdatedCb mediaUpdatedCb = null;
private MediaAddedCb mediaAddedCb = null;
......@@ -118,9 +121,11 @@ public class Medialibrary {
super.finalize();
}
public static synchronized Medialibrary getInstance() {
if (sInstance == null)
public static synchronized Medialibrary getInstance(Context context) {
if (sInstance == null) {
sInstance = new Medialibrary();
sInstance.mContext = context;
}
return sInstance;
}
......@@ -242,7 +247,7 @@ public class Medialibrary {
}
public boolean isWorking() {
return !mIsInitiated || nativeIsWorking();
return mIsWorking;
}
public boolean isInitiated() {
......@@ -359,6 +364,10 @@ public class Medialibrary {
}
}
public void onBackgroundTasksIdleChanged(boolean isIdle) {
mIsWorking = !isIdle;
}
void onReloadStarted(String entryPoint) {
synchronized (devicesDiscoveryCbList) {
if (!devicesDiscoveryCbList.isEmpty())
......@@ -561,7 +570,6 @@ public class Medialibrary {
private native MediaWrapper[] nativeGetRecentAudio();
private native int nativeGetVideoCount();
private native int nativeGetAudioCount();
private native boolean nativeIsWorking();
private native Album[] nativeGetAlbums();
private native Album nativeGetAlbum(long albumtId);
private native Artist[] nativeGetArtists();
......
......@@ -248,7 +248,7 @@ public class VLCApplication extends Application {
public static synchronized Medialibrary getMLInstance() {
if (sMedialibraryInstance == null) {
VLCInstance.get(); // ensure VLC is loaded before medialibrary
sMedialibraryInstance = Medialibrary.getInstance();
sMedialibraryInstance = Medialibrary.getInstance(instance);
}
return sMedialibraryInstance;
}
......
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