Commit 18f2fe8c authored by Duncan McNAMARA's avatar Duncan McNAMARA
Browse files

Medialibrary: Add stub

parent f24fa2a5
......@@ -66,6 +66,9 @@ while [ $# -gt 0 ]; do
run)
RUN=1
;;
test)
TEST=1
;;
--no-ml)
NO_ML=1
;;
......@@ -370,10 +373,14 @@ fi
#######
if [ "$RUN" = 1 ]; then
export PATH="${ANDROID_SDK}/platform-tools/:$PATH"
EXTRA=""
if [ "$TEST" = 1 ]; then
EXTRA="--ez 'extra_test_stubs' true"
fi
adb wait-for-device
if [ "$RELEASE" = 1 ]; then
adb shell am start -n org.videolan.vlc/org.videolan.vlc.StartActivity
adb shell am start -n org.videolan.vlc/org.videolan.vlc.StartActivity $EXTRA
else
adb shell am start -n org.videolan.vlc.debug/org.videolan.vlc.StartActivity
adb shell am start -n org.videolan.vlc.debug/org.videolan.vlc.StartActivity $EXTRA
fi
fi
/*****************************************************************************
/*
*****************************************************************************
* Medialibrary.java
*****************************************************************************
* Copyright © 2017-2018 VLC authors and VideoLAN
......@@ -423,308 +424,6 @@ public class Medialibrary extends AMedialibrary {
return mw;
}
@SuppressWarnings("unused")
public void onMediaAdded(AMediaWrapper[] mediaList) {
synchronized (mMediaCbs) {
for (MediaCb cb : mMediaCbs) cb.onMediaAdded();
}
}
@SuppressWarnings("unused")
public void onMediaUpdated(AMediaWrapper[] mediaList) {
synchronized (mMediaCbs) {
for (MediaCb cb : mMediaCbs) cb.onMediaModified();
}
}
@SuppressWarnings("unused")
public void onMediaDeleted() {
synchronized (mMediaCbs) {
for (MediaCb cb : mMediaCbs) cb.onMediaDeleted();
}
}
@SuppressWarnings("unused")
public void onArtistsAdded() {
synchronized (mArtistsCbs) {
for (ArtistsCb cb : mArtistsCbs) cb.onArtistsAdded();
}
}
@SuppressWarnings("unused")
public void onArtistsModified() {
synchronized (mArtistsCbs) {
for (ArtistsCb cb : mArtistsCbs) cb.onArtistsModified();
}
}
@SuppressWarnings("unused")
public void onArtistsDeleted() {
synchronized (mArtistsCbs) {
for (ArtistsCb cb : mArtistsCbs) cb.onArtistsDeleted();
}
}
@SuppressWarnings("unused")
public void onAlbumsAdded() {
synchronized (mAlbumsCbs) {
for (AlbumsCb cb : mAlbumsCbs) cb.onAlbumsAdded();
}
}
@SuppressWarnings("unused")
public void onAlbumsModified() {
synchronized (mAlbumsCbs) {
for (AlbumsCb cb : mAlbumsCbs) cb.onAlbumsModified();
}
}
@SuppressWarnings("unused")
public void onAlbumsDeleted() {
synchronized (mAlbumsCbs) {
for (AlbumsCb cb : mAlbumsCbs) cb.onAlbumsDeleted();
}
}
@SuppressWarnings("unused")
public void onGenresAdded() {
synchronized (mGenreCbs) {
for (GenresCb cb : mGenreCbs) cb.onGenresAdded();
}
}
@SuppressWarnings("unused")
public void onGenresModified() {
synchronized (mGenreCbs) {
for (GenresCb cb : mGenreCbs) cb.onGenresModified();
}
}
@SuppressWarnings("unused")
public void onGenresDeleted() {
synchronized (mGenreCbs) {
for (GenresCb cb : mGenreCbs) cb.onGenresDeleted();
}
}
@SuppressWarnings("unused")
public void onPlaylistsAdded() {
synchronized (mPlaylistCbs) {
for (PlaylistsCb cb : mPlaylistCbs) cb.onPlaylistsAdded();
}
}
@SuppressWarnings("unused")
public void onPlaylistsModified() {
synchronized (mPlaylistCbs) {
for (PlaylistsCb cb : mPlaylistCbs) cb.onPlaylistsModified();
}
}
@SuppressWarnings("unused")
public void onPlaylistsDeleted() {
synchronized (mPlaylistCbs) {
for (PlaylistsCb cb : mPlaylistCbs) cb.onPlaylistsDeleted();
}
}
public void onDiscoveryStarted(String entryPoint) {
synchronized (devicesDiscoveryCbList) {
if (!devicesDiscoveryCbList.isEmpty())
for (DevicesDiscoveryCb cb : devicesDiscoveryCbList)
cb.onDiscoveryStarted(entryPoint);
}
synchronized (entryPointsEventsCbList) {
if (!entryPointsEventsCbList.isEmpty())
for (EntryPointsEventsCb cb : entryPointsEventsCbList)
cb.onDiscoveryStarted(entryPoint);
}
}
public void onDiscoveryProgress(String entryPoint) {
synchronized (devicesDiscoveryCbList) {
if (!devicesDiscoveryCbList.isEmpty())
for (DevicesDiscoveryCb cb : devicesDiscoveryCbList)
cb.onDiscoveryProgress(entryPoint);
}
synchronized (entryPointsEventsCbList) {
if (!entryPointsEventsCbList.isEmpty())
for (EntryPointsEventsCb cb : entryPointsEventsCbList)
cb.onDiscoveryProgress(entryPoint);
}
}
public void onDiscoveryCompleted(String entryPoint) {
synchronized (devicesDiscoveryCbList) {
if (!devicesDiscoveryCbList.isEmpty())
for (DevicesDiscoveryCb cb : devicesDiscoveryCbList)
cb.onDiscoveryCompleted(entryPoint);
}
synchronized (entryPointsEventsCbList) {
if (!entryPointsEventsCbList.isEmpty())
for (EntryPointsEventsCb cb : entryPointsEventsCbList)
cb.onDiscoveryCompleted(entryPoint);
}
}
public void onParsingStatsUpdated(int percent) {
synchronized (devicesDiscoveryCbList) {
if (!devicesDiscoveryCbList.isEmpty())
for (DevicesDiscoveryCb cb : devicesDiscoveryCbList)
cb.onParsingStatsUpdated(percent);
}
}
@SuppressWarnings("unused")
public void onBackgroundTasksIdleChanged(boolean isIdle) {
mIsWorking = !isIdle;
sRunning.postValue(mIsWorking);
LocalBroadcastManager.getInstance(sContext).sendBroadcast(new Intent(ACTION_IDLE).putExtra(STATE_IDLE, isIdle));
if (isIdle) {
synchronized (onMedialibraryReadyListeners) {
for (OnMedialibraryReadyListener listener : onMedialibraryReadyListeners) listener.onMedialibraryIdle();
}
}
}
@SuppressWarnings("unused")
public void onReloadStarted(String entryPoint) {
synchronized (devicesDiscoveryCbList) {
if (!devicesDiscoveryCbList.isEmpty())
for (DevicesDiscoveryCb cb : devicesDiscoveryCbList)
cb.onReloadStarted(entryPoint);
}
}
@SuppressWarnings("unused")
public void onReloadCompleted(String entryPoint) {
synchronized (devicesDiscoveryCbList) {
if (!devicesDiscoveryCbList.isEmpty())
for (DevicesDiscoveryCb cb : devicesDiscoveryCbList)
cb.onReloadCompleted(entryPoint);
}
}
@SuppressWarnings("unused")
public void onEntryPointBanned(String entryPoint, boolean success) {
synchronized (entryPointsEventsCbList) {
if (!entryPointsEventsCbList.isEmpty())
for (EntryPointsEventsCb cb : entryPointsEventsCbList)
cb.onEntryPointBanned(entryPoint, success);
}
}
@SuppressWarnings("unused")
public void onEntryPointUnbanned(String entryPoint, boolean success) {
synchronized (entryPointsEventsCbList) {
if (!entryPointsEventsCbList.isEmpty())
for (EntryPointsEventsCb cb : entryPointsEventsCbList)
cb.onEntryPointUnbanned(entryPoint, success);
}
}
@SuppressWarnings("unused")
void onEntryPointAdded(String entryPoint, boolean success) {
synchronized (entryPointsEventsCbList) {
if (!entryPointsEventsCbList.isEmpty())
for (EntryPointsEventsCb cb : entryPointsEventsCbList)
cb.onEntryPointAdded(entryPoint, success);
}
}
@SuppressWarnings("unused")
public void onEntryPointRemoved(String entryPoint, boolean success) {
synchronized (entryPointsEventsCbList) {
if (!entryPointsEventsCbList.isEmpty())
for (EntryPointsEventsCb cb : entryPointsEventsCbList)
cb.onEntryPointRemoved(entryPoint, success);
}
}
// public static LiveData<AMediaWrapper> lastThumb = new SingleEvent<>();
@SuppressWarnings({"unused", "unchecked"})
public void onMediaThumbnailReady(AMediaWrapper media, boolean success) {
if (success) ((MutableLiveData)lastThumb).postValue(media);
}
public void addMediaCb(MediaCb mediaUpdatedCb) {
if (!mIsInitiated) return;
synchronized (mMediaCbs) {
// if (mMediaCbs.isEmpty()) {
// nativeSetMediaAddedCbFlag(FLAG_MEDIA_ADDED_AUDIO|FLAG_MEDIA_ADDED_VIDEO);
// nativeSetMediaUpdatedCbFlag(FLAG_MEDIA_UPDATED_AUDIO|FLAG_MEDIA_UPDATED_VIDEO);
// }
mMediaCbs.add(mediaUpdatedCb);
}
}
public void removeMediaCb(MediaCb mediaUpdatedCb) {
if (!mIsInitiated) return;
synchronized (mMediaCbs) {
mMediaCbs.remove(mediaUpdatedCb);
// if (mMediaCbs.isEmpty()) {
// nativeSetMediaAddedCbFlag(0);
// nativeSetMediaUpdatedCbFlag(0);
// }
}
}
public void addArtistsCb(ArtistsCb artistsAddedCb) {
if (!mIsInitiated) return;
synchronized (mArtistsCbs) {
mArtistsCbs.add(artistsAddedCb);
}
}
public void removeArtistsCb(ArtistsCb artistsAddedCb) {
if (!mIsInitiated) return;
synchronized (mArtistsCbs) {
mArtistsCbs.remove(artistsAddedCb);
}
}
public void addAlbumsCb(AlbumsCb AlbumsAddedCb) {
if (!mIsInitiated) return;
synchronized (mAlbumsCbs) {
mAlbumsCbs.add(AlbumsAddedCb);
}
}
public void removeAlbumsCb(AlbumsCb AlbumsAddedCb) {
if (!mIsInitiated) return;
synchronized (mAlbumsCbs) {
mAlbumsCbs.remove(AlbumsAddedCb);
}
}
public void addGenreCb(GenresCb GenreCb) {
if (!mIsInitiated) return;
synchronized (mGenreCbs) {
this.mGenreCbs.add(GenreCb);
}
}
public void removeGenreCb(GenresCb GenreCb) {
if (!mIsInitiated) return;
synchronized (mGenreCbs) {
this.mGenreCbs.remove(GenreCb);
}
}
public void addPlaylistCb(PlaylistsCb playlistCb) {
if (!mIsInitiated) return;
synchronized (mPlaylistCbs) {
this.mPlaylistCbs.add(playlistCb);
}
}
public void removePlaylistCb(PlaylistsCb playlistCb) {
if (!mIsInitiated) return;
synchronized (mPlaylistCbs) {
this.mPlaylistCbs.remove(playlistCb);
}
}
public SearchAggregate search(String query) {
return mIsInitiated && !TextUtils.isEmpty(query) ? nativeSearch(query) : null;
}
......@@ -789,58 +488,6 @@ public class Medialibrary extends AMedialibrary {
return mIsInitiated && !TextUtils.isEmpty(query) ? nativeSearchPagedPlaylist(query, sort, desc, nbItems, offset) : null;
}
public void addDeviceDiscoveryCb(DevicesDiscoveryCb cb) {
synchronized (devicesDiscoveryCbList) {
if (!devicesDiscoveryCbList.contains(cb))
devicesDiscoveryCbList.add(cb);
}
}
public void removeDeviceDiscoveryCb(DevicesDiscoveryCb cb) {
synchronized (devicesDiscoveryCbList) {
devicesDiscoveryCbList.remove(cb);
}
}
public void addOnMedialibraryReadyListener(OnMedialibraryReadyListener cb) {
synchronized (onMedialibraryReadyListeners) {
if (!onMedialibraryReadyListeners.contains(cb))
onMedialibraryReadyListeners.add(cb);
}
}
public void removeOnMedialibraryReadyListener(OnMedialibraryReadyListener cb) {
synchronized (onMedialibraryReadyListeners) {
onMedialibraryReadyListeners.remove(cb);
}
}
public void addEntryPointsEventsCb(EntryPointsEventsCb cb) {
synchronized (entryPointsEventsCbList) {
if (!entryPointsEventsCbList.contains(cb))
entryPointsEventsCbList.add(cb);
}
}
public void removeEntryPointsEventsCb(EntryPointsEventsCb cb) {
synchronized (entryPointsEventsCbList) {
entryPointsEventsCbList.remove(cb);
}
}
public void addOnDeviceChangeListener(OnDeviceChangeListener listener) {
synchronized (onDeviceChangeListeners) {
if (!onDeviceChangeListeners.contains(listener))
onDeviceChangeListeners.add(listener);
}
}
public void removeOnDeviceChangeListener(OnDeviceChangeListener listener) {
synchronized (onDeviceChangeListeners) {
onDeviceChangeListeners.remove(listener);
}
}
// Native methods
private native int nativeInit(String dbPath, String thumbsPath);
private native void nativeStart();
......
......@@ -28,22 +28,18 @@ import org.videolan.medialibrary.stubs.StubPlaylist;
public class ServiceLocator {
private static ServiceLocator mServiceLocator;
private static LocatorMode mMode = LocatorMode.VLC_ANDROID;
public static void setLocatorMode(LocatorMode mode) {
ServiceLocator.mMode = mode;
}
enum LocatorMode {
public static String EXTRA_TEST_STUBS = "extra_test_stubs";
public enum LocatorMode {
VLC_ANDROID,
TESTS,
}
public static ServiceLocator getInstance() {
return mServiceLocator;
}
public static AMedialibrary getAMedialibrary() {
if (mMode == LocatorMode.VLC_ANDROID) {
return new Medialibrary();
......
......@@ -2,18 +2,22 @@ package org.videolan.medialibrary.interfaces;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import org.videolan.medialibrary.ServiceLocator;
import org.videolan.medialibrary.SingleEvent;
import org.videolan.medialibrary.Tools;
import org.videolan.medialibrary.interfaces.media.AAlbum;
import org.videolan.medialibrary.interfaces.media.AArtist;
import org.videolan.medialibrary.interfaces.media.AFolder;
......@@ -101,7 +105,6 @@ abstract public class AMedialibrary {
@NonNull
public static AMedialibrary getInstance() {
System.out.println("This is the real medialibrary");
return instance;
}
......@@ -197,6 +200,382 @@ abstract public class AMedialibrary {
void onDeviceChange();
}
// If media is not in ML, find it with its path
public AMediaWrapper findMedia(AMediaWrapper mw) {
if (mIsInitiated && mw != null && mw.getId() == 0L) {
final Uri uri = mw.getUri();
final AMediaWrapper libraryMedia = getMedia(uri);
if (libraryMedia != null) {
libraryMedia.addFlags(mw.getFlags());
return libraryMedia;
}
if (TextUtils.equals("file", uri.getScheme()) &&
uri.getPath() != null && uri.getPath().startsWith("/sdcard")) {
final AMediaWrapper alternateMedia = getMedia(Tools.convertLocalUri(uri));
if (alternateMedia != null) {
alternateMedia.addFlags(mw.getFlags());
return alternateMedia;
}
}
}
return mw;
}
@SuppressWarnings("unused")
public void onMediaAdded(AMediaWrapper[] mediaList) {
synchronized (mMediaCbs) {
for (MediaCb cb : mMediaCbs) cb.onMediaAdded();
}
}
@SuppressWarnings("unused")
public void onMediaUpdated(AMediaWrapper[] mediaList) {
synchronized (mMediaCbs) {
for (MediaCb cb : mMediaCbs) cb.onMediaModified();
}
}
@SuppressWarnings("unused")
public void onMediaDeleted() {
synchronized (mMediaCbs) {
for (MediaCb cb : mMediaCbs) cb.onMediaDeleted();
}
}
@SuppressWarnings("unused")
public void onArtistsAdded() {
synchronized (mArtistsCbs) {
for (ArtistsCb cb : mArtistsCbs) cb.onArtistsAdded();
}
}
@SuppressWarnings("unused")
public void onArtistsModified() {
synchronized (mArtistsCbs) {
for (ArtistsCb cb : mArtistsCbs) cb.onArtistsModified();
}
}
@SuppressWarnings("unused")
public void onArtistsDeleted() {
synchronized (mArtistsCbs) {
for (ArtistsCb cb : mArtistsCbs) cb.onArtistsDeleted();
}
}
@SuppressWarnings("unused")
public void onAlbumsAdded() {
synchronized (mAlbumsCbs) {
for (AlbumsCb cb : mAlbumsCbs) cb.onAlbumsAdded();
}
}
@SuppressWarnings("unused")
public void onAlbumsModified() {
synchronized (mAlbumsCbs) {
for (AlbumsCb cb : mAlbumsCbs) cb.onAlbumsModified();
}
}
@SuppressWarnings("unused")
public void onAlbumsDeleted() {
synchronized (mAlbumsCbs) {
for (AlbumsCb cb : mAlbumsCbs) cb.onAlbumsDeleted();
}
}
@SuppressWarnings("unused")
public void onGenresAdded() {
synchronized (mGenreCbs) {
for (GenresCb cb : mGenreCbs) cb.onGenresAdded();
}
}
@SuppressWarnings("unused")
public void onGenresModified() {
synchronized (mGenreCbs) {
for (GenresCb cb : mGenreCbs) cb.onGenresModified();
}
}
@SuppressWarnings("unused")
public void onGenresDeleted() {
synchronized (mGenreCbs) {
for (GenresCb cb : mGenreCbs) cb.onGenresDeleted();
}
}
@SuppressWarnings("unused")
public void onPlaylistsAdded() {
synchronized (mPlaylistCbs) {
for (PlaylistsCb cb : mPlaylistCbs) cb.onPlaylistsAdded();
}
}
@SuppressWarnings("unused")
public void onPlaylistsModified() {
synchronized (mPlaylistCbs) {
for (PlaylistsCb cb : mPlaylistCbs) cb.onPlaylistsModified();
}
}
@SuppressWarnings("unused")
public void onPlaylistsDeleted() {
synchronized (mPlaylistCbs) {
for (PlaylistsCb cb : mPlaylistCbs) cb.onPlaylistsDeleted();
}
}