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

Medialibrary: Remove dependency to 'Tools' module

parent f58b1d1b
......@@ -99,7 +99,6 @@ dependencies {
api "androidx.core:core:$rootProject.ext.androidxVersion"
api "androidx.fragment:fragment:$rootProject.ext.androidxVersion"
testImplementation "junit:junit:$rootProject.ext.junitVersion"
implementation project(':tools')
}
apply from: '../publish.gradle'
/*****************************************************************************
* Medialibrary.java
*****************************************************************************
* Copyright © 2017-2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
package org.videolan.medialibrary;
import android.Manifest;
......@@ -33,7 +53,6 @@ import androidx.core.content.ContextCompat;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import videolan.org.commontools.LiveEvent;
@SuppressWarnings("JniMissingFunction")
public class Medialibrary {
......@@ -686,7 +705,7 @@ public class Medialibrary {
}
}
public static LiveData<MediaWrapper> lastThumb = new LiveEvent<>();
public static LiveData<MediaWrapper> lastThumb = new SingleEvent<>();
@SuppressWarnings({"unused", "unchecked"})
void onMediaThumbnailReady(MediaWrapper media, boolean success) {
if (success) ((MutableLiveData)lastThumb).postValue(media);
......
/*****************************************************************************
* SingleEvent.java
*****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
package org.videolan.medialibrary;
import android.util.Log;
import java.util.concurrent.atomic.AtomicBoolean;
import androidx.annotation.NonNull;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
public class SingleEvent<T> extends MutableLiveData<T> {
private static final String TAG = "SingleEvent";
private final AtomicBoolean mPending = new AtomicBoolean(false);
@Override
public void observe(@NonNull LifecycleOwner owner, @NonNull final Observer observer) {
if (hasActiveObservers()) Log.w(TAG, "Multiple observers registered but only one will be notified of changes.");
// Observe the internal MutableLiveData
super.observe(owner, new Observer<T>() {
@Override
public void onChanged(T t) {
if (mPending.compareAndSet(true, false)) observer.onChanged(t);
}
});
}
@Override
public void observeForever(@NonNull final Observer<? super T> observer) {
super.observeForever(new Observer<T>() {
@Override
public void onChanged(T t) {
if (mPending.compareAndSet(true, false)) observer.onChanged(t);
}
});
}
@Override
public void setValue(T value) {
mPending.set(true);
super.setValue(value);
}
public void clear() {
super.setValue(null);
}
}
/*****************************************************************************
* LiveEvent.kt
*****************************************************************************
* Copyright © 2017-2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
package videolan.org.commontools
import android.util.Log
......
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