diff options
Diffstat (limited to 'core')
7 files changed, 29 insertions, 7 deletions
diff --git a/core/build.gradle b/core/build.gradle index 01efdaa0b..af6bb1203 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -58,7 +58,7 @@ dependencies { implementation "com.squareup.okhttp3:okhttp:$okhttpVersion" implementation "com.squareup.okhttp3:okhttp-urlconnection:$okhttpVersion" implementation "com.squareup.okio:okio:$okioVersion" - implementation "de.greenrobot:eventbus:$eventbusVersion" + implementation "org.greenrobot:eventbus:$eventbusVersion" implementation "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion" implementation "io.reactivex.rxjava2:rxjava:$rxJavaVersion" implementation "org.awaitility:awaitility:$awaitilityVersion" diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java index 96c413b41..787d465d8 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java @@ -20,6 +20,7 @@ import android.util.Pair; import android.webkit.URLUtil; import org.apache.commons.io.FileUtils; +import org.greenrobot.eventbus.EventBus; import org.xml.sax.SAXException; import java.io.File; @@ -71,7 +72,6 @@ import de.danoeh.antennapod.core.util.ChapterUtils; import de.danoeh.antennapod.core.util.DownloadError; import de.danoeh.antennapod.core.util.InvalidFeedException; import de.danoeh.antennapod.core.util.gui.NotificationUtils; -import de.greenrobot.event.EventBus; /** * Manages the download of feedfiles in the app. Downloads can be enqueued via the startService intent. diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 8395c227c..d4be0013f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -71,7 +71,7 @@ import de.danoeh.antennapod.core.util.QueueAccess; import de.danoeh.antennapod.core.util.gui.NotificationUtils; import de.danoeh.antennapod.core.util.playback.ExternalMedia; import de.danoeh.antennapod.core.util.playback.Playable; -import de.greenrobot.event.EventBus; +import org.greenrobot.eventbus.EventBus; /** * Controls the MediaPlayer that plays a FeedMedia-file diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java index 624ecdf90..a464d74f1 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java @@ -19,7 +19,8 @@ import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.util.playback.Playable; -import de.greenrobot.event.EventBus; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; import io.reactivex.Completable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; @@ -78,6 +79,7 @@ public class PlaybackServiceTaskManager { EventBus.getDefault().register(this); } + @Subscribe public void onEvent(QueueEvent event) { Log.d(TAG, "onEvent(QueueEvent " + event +")"); cancelQueueLoader(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java index f7226729a..c55acb6ef 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java @@ -8,6 +8,7 @@ import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.util.Log; +import org.greenrobot.eventbus.EventBus; import org.shredzone.flattr4j.model.Flattr; import java.io.File; @@ -48,7 +49,6 @@ import de.danoeh.antennapod.core.util.Permutor; import de.danoeh.antennapod.core.util.flattr.FlattrStatus; import de.danoeh.antennapod.core.util.flattr.FlattrThing; import de.danoeh.antennapod.core.util.flattr.SimpleFlattrThing; -import de.greenrobot.event.EventBus; /** * Provides methods for writing data to AntennaPod's database. diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java index 1daa43025..405c246c9 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java @@ -39,7 +39,7 @@ import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.download.DownloadStatus; import de.danoeh.antennapod.core.util.LongIntMap; import de.danoeh.antennapod.core.util.flattr.FlattrStatus; -import de.greenrobot.event.EventBus; +import org.greenrobot.eventbus.EventBus; // TODO Remove media column from feeditem table diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java index a77086f2a..2c70e9435 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java @@ -26,6 +26,7 @@ import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import de.danoeh.antennapod.core.R; +import de.danoeh.antennapod.core.event.ServiceEvent; import de.danoeh.antennapod.core.feed.Chapter; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.MediaType; @@ -44,6 +45,9 @@ import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; /** * Communicates with the playback service. GUI classes should use this class to @@ -70,6 +74,7 @@ public abstract class PlaybackController { private boolean mediaInfoLoaded = false; private boolean released = false; private boolean initialized = false; + private boolean eventsRegistered = false; private Disposable serviceBinder; private Disposable mediaLoader; @@ -96,7 +101,11 @@ public abstract class PlaybackController { /** * Creates a new connection to the playbackService. */ - public void init() { + public synchronized void init() { + if (!eventsRegistered) { + EventBus.getDefault().register(this); + eventsRegistered = true; + } if (PlaybackService.isRunning) { initServiceRunning(); } else { @@ -104,6 +113,13 @@ public abstract class PlaybackController { } } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onEventMainThread(ServiceEvent event) { + if (event.action == ServiceEvent.Action.SERVICE_STARTED) { + init(); + } + } + private synchronized void initServiceRunning() { if (initialized) { return; @@ -165,6 +181,10 @@ public abstract class PlaybackController { media = null; released = true; + if (eventsRegistered) { + EventBus.getDefault().unregister(this); + eventsRegistered = false; + } } /** |