diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2019-05-19 19:19:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-19 19:19:52 +0200 |
commit | 0b6930517aad20af509fa66ef58c115b98c71738 (patch) | |
tree | 634660a2113883228e237e467413371c9bfb8f25 | |
parent | 5ea87f70f75ea37cde810c5c69356169e3c51da0 (diff) | |
parent | 55874607dff955ca68e7e1a6c271049c72c1677b (diff) | |
download | AntennaPod-0b6930517aad20af509fa66ef58c115b98c71738.zip |
Merge pull request #3109 from ByteHamster/eventbus-v3
Eventbus v3
27 files changed, 116 insertions, 122 deletions
diff --git a/app/build.gradle b/app/build.gradle index 711048239..97b9596b9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -144,7 +144,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" diff --git a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java index 08e7f6fc5..c9f0527e1 100644 --- a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java +++ b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java @@ -19,7 +19,7 @@ import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager; import de.danoeh.antennapod.core.storage.PodDBAdapter; import de.danoeh.antennapod.core.util.playback.Playable; -import de.greenrobot.event.EventBus; +import org.greenrobot.eventbus.EventBus; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java b/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java index ff5374268..263790c2f 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java @@ -27,9 +27,9 @@ import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.storage.PodDBAdapter; import de.danoeh.antennapod.core.util.playback.PlaybackController; import de.danoeh.antennapod.fragment.ExternalPlayerFragment; -import de.greenrobot.event.EventBus; import de.test.antennapod.util.service.download.HTTPBin; import de.test.antennapod.util.syndication.feedgenerator.RSS2Generator; +import org.greenrobot.eventbus.EventBus; /** * Utility methods for UI tests. diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index 3bbe206f8..0b9735f59 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -43,7 +43,6 @@ import de.danoeh.antennapod.core.dialog.ConfirmationDialog; import de.danoeh.antennapod.core.event.MessageEvent; import de.danoeh.antennapod.core.event.ProgressEvent; import de.danoeh.antennapod.core.event.QueueEvent; -import de.danoeh.antennapod.core.event.ServiceEvent; import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; @@ -68,11 +67,13 @@ import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; import de.danoeh.antennapod.fragment.QueueFragment; import de.danoeh.antennapod.fragment.SubscriptionFragment; import de.danoeh.antennapod.menuhandler.NavDrawerActivity; -import de.greenrobot.event.EventBus; 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; /** * The activity that is shown when the user launches the app. @@ -765,6 +766,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi }, error -> Log.e(TAG, Log.getStackTraceString(error))); } + @Subscribe public void onEvent(QueueEvent event) { Log.d(TAG, "onEvent(" + event + ")"); // we are only interested in the number of queue items, not download status or position @@ -776,6 +778,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi loadData(); } + @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(ProgressEvent event) { Log.d(TAG, "onEvent(" + event + ")"); switch(event.action) { @@ -794,6 +797,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi } } + @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(MessageEvent event) { Log.d(TAG, "onEvent(" + event + ")"); View parentLayout = findViewById(R.id.drawer_layout); diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index 86d4ec642..154c7c148 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -38,7 +38,6 @@ import com.joanzapata.iconify.fonts.FontAwesomeIcons; import java.util.Locale; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.event.ServiceEvent; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.MediaType; @@ -661,15 +660,6 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements StorageUtils.checkStorageAvailability(this); } - public void onEventMainThread(ServiceEvent event) { - Log.d(TAG, "onEvent(" + event + ")"); - if (event.action == ServiceEvent.Action.SERVICE_STARTED) { - if (controller != null) { - controller.init(); - } - } - } - /** * Called by 'handleStatus()' when the PlaybackService is waiting for * a video surface. diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java index 4a1dae3e9..7b2ab3249 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java @@ -7,7 +7,6 @@ import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; -import android.support.annotation.Nullable; import android.support.design.widget.AppBarLayout; import android.support.design.widget.Snackbar; import android.support.v4.app.Fragment; @@ -34,7 +33,6 @@ import com.viewpagerindicator.CirclePageIndicator; import java.util.List; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.adapter.ChaptersListAdapter; import de.danoeh.antennapod.adapter.NavListAdapter; import de.danoeh.antennapod.core.asynctask.FeedRemover; import de.danoeh.antennapod.core.dialog.ConfirmationDialog; @@ -62,11 +60,13 @@ import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; import de.danoeh.antennapod.fragment.QueueFragment; import de.danoeh.antennapod.fragment.SubscriptionFragment; import de.danoeh.antennapod.menuhandler.NavDrawerActivity; -import de.greenrobot.event.EventBus; 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; /** * Activity for playing files that do not require a video surface. @@ -108,12 +108,6 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem private Disposable disposable; @Override - protected void onPause() { - super.onPause(); - EventBus.getDefault().unregister(this); - } - - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); supportPostponeEnterTransition(); @@ -127,6 +121,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem disposable.dispose(); } EventDistributor.getInstance().unregister(contentUpdate); + EventBus.getDefault().unregister(this); saveCurrentFragment(); } @@ -176,10 +171,9 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem } @Override - protected void onResume() { - super.onResume(); + protected void onStart() { + super.onStart(); AutoUpdateManager.checkShouldRefreshFeeds(getApplicationContext()); - EventDistributor.getInstance().register(contentUpdate); EventBus.getDefault().register(this); loadData(); @@ -443,6 +437,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem }, error -> Log.e(TAG, Log.getStackTraceString(error))); } + @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(MessageEvent event) { Log.d(TAG, "onEvent(" + event + ")"); View parentLayout = findViewById(R.id.drawer_layout); diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java index 145908e97..35c423a47 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -31,6 +31,9 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; import org.apache.commons.lang3.StringUtils; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; @@ -68,7 +71,6 @@ import de.danoeh.antennapod.core.util.URLChecker; import de.danoeh.antennapod.core.util.syndication.FeedDiscoverer; import de.danoeh.antennapod.core.util.syndication.HtmlToPlainText; import de.danoeh.antennapod.dialog.AuthenticationDialog; -import de.greenrobot.event.EventBus; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -123,6 +125,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { } }; + @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(DownloadEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); setSubscribeButtonState(feed); @@ -193,24 +196,19 @@ public class OnlineFeedViewActivity extends AppCompatActivity { } @Override - protected void onResume() { - super.onResume(); + protected void onStart() { + super.onStart(); isPaused = false; EventDistributor.getInstance().register(listener); EventBus.getDefault().register(this); } @Override - protected void onPause() { - super.onPause(); + protected void onStop() { + super.onStop(); isPaused = true; EventDistributor.getInstance().unregister(listener); EventBus.getDefault().unregister(this); - } - - @Override - protected void onStop() { - super.onStop(); if (downloader != null && !downloader.isFinished()) { downloader.cancel(); } diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java index 4b8601ec6..dc056a3f9 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java @@ -18,7 +18,7 @@ import com.afollestad.materialdialogs.MaterialDialog; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.event.MessageEvent; import de.danoeh.antennapod.core.preferences.SleepTimerPreferences; -import de.greenrobot.event.EventBus; +import org.greenrobot.eventbus.EventBus; public abstract class SleepTimerDialog { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java index f2ae47ac4..48b891631 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java @@ -51,12 +51,15 @@ import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; import de.danoeh.antennapod.menuhandler.MenuItemUtils; + import de.danoeh.antennapod.view.EmptyViewHandler; -import de.greenrobot.event.EventBus; 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; /** * Shows unread or recently published episodes @@ -107,12 +110,12 @@ public class AllEpisodesFragment extends Fragment { if (viewsCreated && itemsLoaded) { onFragmentLoaded(); } + EventBus.getDefault().register(this); } @Override public void onResume() { super.onResume(); - EventBus.getDefault().registerSticky(this); loadItems(); registerForContextMenu(recyclerView); } @@ -120,7 +123,6 @@ public class AllEpisodesFragment extends Fragment { @Override public void onPause() { super.onPause(); - EventBus.getDefault().unregister(this); saveScrollPosition(); unregisterForContextMenu(recyclerView); } @@ -128,6 +130,7 @@ public class AllEpisodesFragment extends Fragment { @Override public void onStop() { super.onStop(); + EventBus.getDefault().unregister(this); EventDistributor.getInstance().unregister(contentUpdate); if (disposable != null) { disposable.dispose(); @@ -430,6 +433,7 @@ public class AllEpisodesFragment extends Fragment { }; + @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(FeedItemEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); if (episodes == null) { @@ -456,6 +460,7 @@ public class AllEpisodesFragment extends Fragment { return true; } + @Subscribe(sticky = true, threadMode = ThreadMode.MAIN) public void onEventMainThread(DownloadEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); DownloaderUpdate update = event.update; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java index ffec47dba..0ffd1a8da 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java @@ -11,11 +11,10 @@ import java.util.ListIterator; import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.ChaptersListAdapter; -import de.danoeh.antennapod.core.event.ServiceEvent; import de.danoeh.antennapod.core.feed.Chapter; import de.danoeh.antennapod.core.util.playback.Playable; import de.danoeh.antennapod.core.util.playback.PlaybackController; -import de.greenrobot.event.EventBus; + import io.reactivex.Maybe; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -60,8 +59,8 @@ public class ChaptersFragment extends ListFragment { } }; controller.init(); + loadMediaInfo(); - EventBus.getDefault().register(this); } @Override @@ -76,7 +75,6 @@ public class ChaptersFragment extends ListFragment { @Override public void onStop() { super.onStop(); - EventBus.getDefault().unregister(this); controller.release(); controller = null; } @@ -98,12 +96,6 @@ public class ChaptersFragment extends ListFragment { return chapters.size() - 1; } - public void onEventMainThread(ServiceEvent event) { - if (event.action == ServiceEvent.Action.SERVICE_STARTED && controller != null) { - controller.init(); - } - } - private void loadMediaInfo() { if (disposable != null) { disposable.dispose(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java index 7bb9c60e4..7fd61d3ad 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java @@ -14,11 +14,9 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.event.ServiceEvent; import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.util.playback.Playable; import de.danoeh.antennapod.core.util.playback.PlaybackController; -import de.greenrobot.event.EventBus; import io.reactivex.Maybe; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -99,19 +97,11 @@ public class CoverFragment extends Fragment { }; controller.init(); loadMediaInfo(); - EventBus.getDefault().register(this); - } - - public void onEventMainThread(ServiceEvent event) { - if (event.action == ServiceEvent.Action.SERVICE_STARTED && controller != null) { - controller.init(); - } } @Override public void onStop() { super.onStop(); - EventBus.getDefault().unregister(this); controller.release(); controller = null; } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java index dca574984..348c73b92 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java @@ -24,7 +24,6 @@ import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.util.playback.Playable; import de.danoeh.antennapod.core.util.playback.PlaybackController; -import de.greenrobot.event.EventBus; import io.reactivex.Maybe; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -92,13 +91,6 @@ public class ExternalPlayerFragment extends Fragment { loadMediaInfo(); } - public void onEventMainThread(ServiceEvent event) { - Log.d(TAG, "onEvent(" + event + ")"); - if (event.action == ServiceEvent.Action.SERVICE_STARTED) { - controller.init(); - } - } - private PlaybackController setupPlaybackController() { return new PlaybackController(getActivity(), true) { @@ -146,7 +138,6 @@ public class ExternalPlayerFragment extends Fragment { controller = setupPlaybackController(); controller.init(); loadMediaInfo(); - EventBus.getDefault().register(this); } @Override @@ -156,7 +147,6 @@ public class ExternalPlayerFragment extends Fragment { controller.release(); controller = null; } - EventBus.getDefault().unregister(this); } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java index d4a662d43..d362d5c0b 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java @@ -18,6 +18,8 @@ import de.danoeh.antennapod.core.event.FavoritesEvent; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; /** @@ -37,6 +39,7 @@ public class FavoriteEpisodesFragment extends AllEpisodesFragment { @Override protected String getPrefName() { return PREF_NAME; } + @Subscribe public void onEvent(FavoritesEvent event) { Log.d(TAG, "onEvent() called with: " + "event = [" + event + "]"); loadItems(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java index 9cee59531..ed591d21c 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java @@ -28,7 +28,6 @@ import android.widget.Toast; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MediaplayerInfoActivity; -import de.danoeh.antennapod.core.event.ServiceEvent; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.IntentUtils; @@ -36,7 +35,6 @@ import de.danoeh.antennapod.core.util.NetworkUtils; import de.danoeh.antennapod.core.util.ShareUtils; import de.danoeh.antennapod.core.util.playback.PlaybackController; import de.danoeh.antennapod.core.util.playback.Timeline; -import de.greenrobot.event.EventBus; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -310,19 +308,11 @@ public class ItemDescriptionFragment extends Fragment { }; controller.init(); load(); - EventBus.getDefault().register(this); - } - - public void onEventMainThread(ServiceEvent event) { - if (event.action == ServiceEvent.Action.SERVICE_STARTED && controller != null) { - controller.init(); - } } @Override public void onStop() { super.onStop(); - EventBus.getDefault().unregister(this); controller.release(); controller = null; } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java index 4b8f6a16a..2b8b2aa33 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java @@ -68,11 +68,13 @@ import de.danoeh.antennapod.core.util.playback.Timeline; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; import de.danoeh.antennapod.view.OnSwipeGesture; import de.danoeh.antennapod.view.SwipeGestureDetector; -import de.greenrobot.event.EventBus; 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; /** * Displays information about a FeedItem and actions. @@ -266,10 +268,15 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { } @Override + public void onStart() { + super.onStart(); + EventDistributor.getInstance().register(contentUpdate); + EventBus.getDefault().register(this); + } + + @Override public void onResume() { super.onResume(); - EventDistributor.getInstance().register(contentUpdate); - EventBus.getDefault().registerSticky(this); if(itemsLoaded) { progbarLoading.setVisibility(View.GONE); updateAppearance(); @@ -277,8 +284,8 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { } @Override - public void onPause() { - super.onPause(); + public void onStop() { + super.onStop(); EventDistributor.getInstance().unregister(contentUpdate); EventBus.getDefault().unregister(this); } @@ -537,6 +544,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { ((MainActivity)getActivity()).loadChildFragment(fragment); } + @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(FeedItemEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); for(FeedItem item : event.items) { @@ -547,6 +555,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { } } + @Subscribe(sticky = true, threadMode = ThreadMode.MAIN) public void onEventMainThread(DownloadEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); DownloaderUpdate update = event.update; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java index 726de8369..3d6e0a458 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java @@ -68,11 +68,13 @@ import de.danoeh.antennapod.dialog.RenameFeedDialog; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; import de.danoeh.antennapod.menuhandler.FeedMenuHandler; import de.danoeh.antennapod.menuhandler.MenuItemUtils; -import de.greenrobot.event.EventBus; 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; /** * Displays a list of FeedItems. @@ -143,6 +145,8 @@ public class ItemlistFragment extends ListFragment { @Override public void onStart() { super.onStart(); + EventDistributor.getInstance().register(contentUpdate); + EventBus.getDefault().register(this); if (viewsCreated && itemsLoaded) { onFragmentLoaded(); } @@ -151,16 +155,14 @@ public class ItemlistFragment extends ListFragment { @Override public void onResume() { super.onResume(); - EventDistributor.getInstance().register(contentUpdate); - EventBus.getDefault().registerSticky(this); ((MainActivity)getActivity()).getSupportActionBar().setTitle(""); updateProgressBarVisibility(); loadItems(); } @Override - public void onPause() { - super.onPause(); + public void onStop() { + super.onStop(); EventDistributor.getInstance().unregister(contentUpdate); EventBus.getDefault().unregister(this); if(disposable != null) { @@ -359,6 +361,7 @@ public class ItemlistFragment extends ListFragment { activity.getSupportActionBar().setTitle(feed.getTitle()); } + @Subscribe public void onEvent(FeedEvent event) { Log.d(TAG, "onEvent() called with: " + "event = [" + event + "]"); if(event.feedId == feedID) { @@ -366,6 +369,7 @@ public class ItemlistFragment extends ListFragment { } } + @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(FeedItemEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); if(feed == null || feed.getItems() == null || adapter == null) { @@ -380,6 +384,7 @@ public class ItemlistFragment extends ListFragment { } } + @Subscribe(sticky = true, threadMode = ThreadMode.MAIN) public void onEventMainThread(DownloadEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); DownloaderUpdate update = event.update; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java index e8f35b180..efa727ca0 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java @@ -31,11 +31,13 @@ import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.view.EmptyViewHandler; -import de.greenrobot.event.EventBus; 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; public class PlaybackHistoryFragment extends ListFragment { @@ -91,29 +93,18 @@ public class PlaybackHistoryFragment extends ListFragment { } - - @Override - public void onResume() { - super.onResume(); - EventBus.getDefault().registerSticky(this); - loadItems(); - } - @Override public void onStart() { super.onStart(); EventDistributor.getInstance().register(contentUpdate); - } - - @Override - public void onPause() { - super.onPause(); - EventBus.getDefault().unregister(this); + EventBus.getDefault().register(this); + loadItems(); } @Override public void onStop() { super.onStop(); + EventBus.getDefault().unregister(this); EventDistributor.getInstance().unregister(contentUpdate); if(disposable != null) { disposable.dispose(); @@ -135,6 +126,7 @@ public class PlaybackHistoryFragment extends ListFragment { viewsCreated = false; } + @Subscribe(sticky = true) public void onEvent(DownloadEvent event) { Log.d(TAG, "onEvent() called with: " + "event = [" + event + "]"); DownloaderUpdate update = event.update; @@ -193,6 +185,7 @@ public class PlaybackHistoryFragment extends ListFragment { } } + @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(FeedItemEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); if(playbackHistory == null) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index 13580be4f..36d0811b3 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -52,12 +52,15 @@ import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.QueueSorter; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; import de.danoeh.antennapod.menuhandler.MenuItemUtils; + import de.danoeh.antennapod.view.EmptyViewHandler; -import de.greenrobot.event.EventBus; 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; /** * Shows all items in the queue @@ -105,7 +108,7 @@ public class QueueFragment extends Fragment { } loadItems(true); EventDistributor.getInstance().register(contentUpdate); - EventBus.getDefault().registerSticky(this); + EventBus.getDefault().register(this); } @Override @@ -124,6 +127,7 @@ public class QueueFragment extends Fragment { } } + @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(QueueEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); if (queue == null) { @@ -162,6 +166,7 @@ public class QueueFragment extends Fragment { onFragmentLoaded(false); } + @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(FeedItemEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); if (queue == null) { @@ -182,6 +187,7 @@ public class QueueFragment extends Fragment { } } + @Subscribe(sticky = true, threadMode = ThreadMode.MAIN) public void onEventMainThread(DownloadEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); DownloaderUpdate update = event.update; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java index 3c40b542c..718502ea2 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java @@ -21,7 +21,8 @@ import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.view.EmptyViewHandler; -import de.greenrobot.event.EventBus; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; /** * Displays all running downloads and provides actions to cancel them @@ -54,14 +55,14 @@ public class RunningDownloadsFragment extends ListFragment { } @Override - public void onResume() { - super.onResume(); - EventBus.getDefault().registerSticky(this); + public void onStart() { + super.onStart(); + EventBus.getDefault().register(this); } @Override - public void onPause() { - super.onPause(); + public void onStop() { + super.onStop(); EventBus.getDefault().unregister(this); } @@ -72,6 +73,7 @@ public class RunningDownloadsFragment extends ListFragment { adapter = null; } + @Subscribe(sticky = true) public void onEvent(DownloadEvent event) { Log.d(TAG, "onEvent() called with: " + "event = [" + event + "]"); DownloaderUpdate update = event.update; diff --git a/build.gradle b/build.gradle index 664cecbd9..86c2ced41 100644 --- a/build.gradle +++ b/build.gradle @@ -49,7 +49,7 @@ project.ext { commonsioVersion = "2.5" commonslangVersion = "3.6" commonstextVersion = "1.3" - eventbusVersion = "2.4.0" + eventbusVersion = "3.1.1" flattr4jVersion = "2.14" glideVersion = "4.8.0" glideOkhttpIntegrationVersion = "4.8.0" 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; + } } /** |