Cancel ChapterLoader correctly
This commit is contained in:
parent
7513c6e1ad
commit
74d18b747a
@ -8,6 +8,7 @@ import androidx.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import de.danoeh.antennapod.core.preferences.SleepTimerPreferences;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
@ -57,7 +58,7 @@ public class PlaybackServiceTaskManager {
|
||||
private ScheduledFuture<?> widgetUpdaterFuture;
|
||||
private ScheduledFuture<?> sleepTimerFuture;
|
||||
private volatile Future<List<FeedItem>> queueFuture;
|
||||
private volatile Future<?> chapterLoaderFuture;
|
||||
private volatile Disposable chapterLoaderFuture;
|
||||
|
||||
private SleepTimer sleepTimer;
|
||||
|
||||
@ -289,28 +290,19 @@ public class PlaybackServiceTaskManager {
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void cancelChapterLoader() {
|
||||
if (isChapterLoaderActive()) {
|
||||
chapterLoaderFuture.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized boolean isChapterLoaderActive() {
|
||||
return chapterLoaderFuture != null && !chapterLoaderFuture.isDone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new thread that loads the chapter marks from a playable object. If another chapter loader is already active,
|
||||
* it will be cancelled first.
|
||||
* On completion, the callback's onChapterLoaded method will be called.
|
||||
*/
|
||||
public synchronized void startChapterLoader(@NonNull final Playable media) {
|
||||
if (isChapterLoaderActive()) {
|
||||
cancelChapterLoader();
|
||||
if (chapterLoaderFuture != null) {
|
||||
chapterLoaderFuture.dispose();
|
||||
chapterLoaderFuture = null;
|
||||
}
|
||||
|
||||
if (media.getChapters() == null) {
|
||||
Completable.create(emitter -> {
|
||||
chapterLoaderFuture = Completable.create(emitter -> {
|
||||
media.loadChapterMarks();
|
||||
emitter.onComplete();
|
||||
})
|
||||
@ -330,7 +322,11 @@ public class PlaybackServiceTaskManager {
|
||||
cancelWidgetUpdater();
|
||||
disableSleepTimer();
|
||||
cancelQueueLoader();
|
||||
cancelChapterLoader();
|
||||
|
||||
if (chapterLoaderFuture != null) {
|
||||
chapterLoaderFuture.dispose();
|
||||
chapterLoaderFuture = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user