Merge pull request #3121 from ByteHamster/network-main-thread

Fixed NetworkOnMainThreadException
This commit is contained in:
H. Lehmann 2019-04-16 23:03:56 +02:00 committed by GitHub
commit 09e7f60db8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 12 deletions

View File

@ -19,6 +19,9 @@ import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.util.playback.Playable;
import de.greenrobot.event.EventBus;
import io.reactivex.Completable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
/**
@ -262,19 +265,16 @@ public class PlaybackServiceTaskManager {
cancelChapterLoader();
}
Runnable chapterLoader = () -> {
Log.d(TAG, "Chapter loader started");
if (media.getChapters() == null) {
Completable.create(emitter -> {
media.loadChapterMarks();
if (!Thread.currentThread().isInterrupted() && media.getChapters() != null) {
callback.onChapterLoaded(media);
emitter.onComplete();
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(() -> callback.onChapterLoaded(media));
}
}
Log.d(TAG, "Chapter loader stopped");
};
chapterLoader = useMainThreadIfNecessary(chapterLoader);
chapterLoaderFuture = schedExecutor.submit(chapterLoader);
}
/**