Skip to content
Snippets Groups Projects
Commit d495f076 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Devices/folders management API implementation

parent 2fd16ab6
No related branches found
No related tags found
No related merge requests found
......@@ -68,6 +68,12 @@ AndroidMediaLibrary::addDevice(std::string uuid, std::string path, bool removabl
p_DeviceListerCb->onDevicePlugged(uuid, path);
}
std::vector<std::tuple<std::string, std::string, bool>>
AndroidMediaLibrary::devices()
{
return p_lister->devices();
}
bool
AndroidMediaLibrary::removeDevice(std::string uuid)
{
......@@ -89,6 +95,18 @@ AndroidMediaLibrary::discover(const std::string& libraryPath)
p_ml->discover(libraryPath);
}
void
AndroidMediaLibrary::removeEntryPoint(const std::string& entryPoint)
{
p_ml->removeEntryPoint(entryPoint);
}
std::vector<medialibrary::FolderPtr>
AndroidMediaLibrary::entryPoints()
{
return p_ml->entryPoints();
}
bool
AndroidMediaLibrary::isWorking()
{
......
......@@ -16,6 +16,7 @@
#include <medialibrary/IArtist.h>
#include <medialibrary/IGenre.h>
#include <medialibrary/IPlaylist.h>
#include <medialibrary/IFolder.h>
#include <medialibrary/Types.h>
#include <medialibrary/IDeviceLister.h>
#include <medialibrary/IMedia.h>
......@@ -29,9 +30,12 @@ public:
void initML(const std::string& dbPath, const std::string& thumbsPath);
void addDevice(std::string uuid, std::string path, bool removable);
std::vector<std::tuple<std::string, std::string, bool>> devices();
bool removeDevice(std::string uuid);
void banFolder(const std::string& path);
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);
......
......@@ -64,6 +64,20 @@ void addDevice(JNIEnv* env, jobject thiz, jstring uuid, jstring storagePath, jbo
env->ReleaseStringUTFChars(storagePath, path);
}
jobjectArray
devices(JNIEnv* env, jobject thiz)
{
AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
auto devices = aml->devices();
jobjectArray deviceRefs = (jobjectArray) env->NewObjectArray(devices.size(), env->FindClass("java/lang/String"), NULL);
int index = -1;
for(auto device : devices) {
std::string path = std::get<1>(device);
env->SetObjectArrayElement(deviceRefs, ++index, env->NewStringUTF(path.c_str()));
}
return deviceRefs;
}
void
discover(JNIEnv* env, jobject thiz, jstring storagePath)
{
......@@ -73,6 +87,28 @@ discover(JNIEnv* env, jobject thiz, jstring storagePath)
env->ReleaseStringUTFChars(storagePath, path);
}
void
removeEntryPoint(JNIEnv* env, jobject thiz, jstring storagePath)
{
AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
const char *path = env->GetStringUTFChars(storagePath, JNI_FALSE);
aml->removeEntryPoint(path);
env->ReleaseStringUTFChars(storagePath, path);
}
jobjectArray
entryPoints(JNIEnv* env, jobject thiz)
{
AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
std::vector<medialibrary::FolderPtr> entryPoints = aml->entryPoints();
jobjectArray mediaRefs = (jobjectArray) env->NewObjectArray(entryPoints.size(), env->FindClass("java/lang/String"), NULL);
int index = -1;
for(medialibrary::FolderPtr const& entrypoint : entryPoints) {
env->SetObjectArrayElement(mediaRefs, ++index, env->NewStringUTF(entrypoint->path().c_str()));
}
return mediaRefs;
}
jboolean
removeDevice(JNIEnv* env, jobject thiz, jstring uuid)
{
......@@ -515,7 +551,10 @@ static JNINativeMethod methods[] = {
{"nativeInit", "(Ljava/lang/String;Ljava/lang/String;)V", (void*)init },
{"nativeRelease", "()V", (void*)release },
{"nativeAddDevice", "(Ljava/lang/String;Ljava/lang/String;Z)V", (void*)addDevice },
{"nativeDevices", "()[Ljava/lang/String;", (void*)devices },
{"nativeDiscover", "(Ljava/lang/String;)V", (void*)discover },
{"nativeRemoveEntryPoint", "(Ljava/lang/String;)V", (void*)removeEntryPoint },
{"nativeEntryPoints", "()[Ljava/lang/String;", (void*)entryPoints },
{"nativeRemoveDevice", "(Ljava/lang/String;)Z", (void*)removeDevice },
{"nativeBanFolder", "(Ljava/lang/String;)V", (void*)banFolder },
{"nativeLastMediaPlayed", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)lastMediaPLayed },
......
......@@ -90,6 +90,10 @@ public class Medialibrary {
if (mIsInitiated)
nativeBanFolder(path);
}
public String[] getDevices() {
return nativeDevices();
}
public void addDevice(String uuid, String path, boolean removable) {
nativeAddDevice(uuid, path, removable);
for (String folder : banList)
......@@ -100,6 +104,14 @@ public class Medialibrary {
nativeDiscover(path);
}
public void removeFolder(String path) {
nativeRemoveEntryPoint(path);
}
public String[] getFoldersList() {
return nativeEntryPoints();
}
public boolean removeDevice(String uuid) {
return nativeRemoveDevice(uuid);
}
......@@ -379,7 +391,10 @@ public class Medialibrary {
private native void nativeRelease();
private native void nativeBanFolder(String path);
private native void nativeAddDevice(String uuid, String path, boolean removable);
private native String[] nativeDevices();
private native void nativeDiscover(String path);
private native void nativeRemoveEntryPoint(String path);
private native String[] nativeEntryPoints();
private native boolean nativeRemoveDevice(String uuid);
private native MediaWrapper[] nativeLastMediaPlayed();
private native MediaWrapper nativeGetMedia(long id);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment