diff options
author | ByteHamster <info@bytehamster.com> | 2019-10-25 11:19:52 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2019-10-25 11:19:52 +0200 |
commit | 728ed23077ceb19d927eb563c504f6b11010dc7f (patch) | |
tree | 9a4a45f77ab923fe032f180496a23c6832119a7f /app | |
parent | d4b9d0fd59996c97ad108755117d797091cecba4 (diff) | |
download | AntennaPod-728ed23077ceb19d927eb563c504f6b11010dc7f.zip |
Migrated feed list update event to EventBus
Diffstat (limited to 'app')
7 files changed, 48 insertions, 101 deletions
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 82dc63d68..85e67c8ba 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java @@ -4,6 +4,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.util.Log; +import de.danoeh.antennapod.core.event.FeedListUpdateEvent; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -201,7 +202,7 @@ public class UITestUtils { adapter.setCompleteFeed(hostedFeeds.toArray(new Feed[hostedFeeds.size()])); adapter.setQueue(queue); adapter.close(); - EventDistributor.getInstance().sendFeedUpdateBroadcast(); + EventBus.getDefault().post(new FeedListUpdateEvent()); EventBus.getDefault().post(QueueEvent.setQueue(queue)); } 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 4cddb4ead..10138e3db 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -34,6 +34,7 @@ import android.widget.Toast; import com.bumptech.glide.Glide; +import de.danoeh.antennapod.core.event.FeedListUpdateEvent; import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.Validate; @@ -85,8 +86,6 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi private static final String TAG = "MainActivity"; - private static final int EVENTS = EventDistributor.FEED_LIST_UPDATE; - public static final String PREF_NAME = "MainActivityPrefs"; public static final String PREF_IS_FIRST_LAUNCH = "prefMainActivityIsFirstLaunch"; public static final String PREF_LAST_FRAGMENT_TAG = "prefMainActivityLastFragmentTag"; @@ -490,7 +489,6 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi @Override public void onStart() { super.onStart(); - EventDistributor.getInstance().register(contentUpdate); EventBus.getDefault().register(this); RatingDialog.init(this); } @@ -518,7 +516,6 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi @Override protected void onStop() { super.onStop(); - EventDistributor.getInstance().unregister(contentUpdate); EventBus.getDefault().unregister(this); if (disposable != null) { disposable.dispose(); @@ -822,16 +819,11 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi loadData(); } - private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { - @Override - public void update(EventDistributor eventDistributor, Integer arg) { - if ((EVENTS & arg) != 0) { - Log.d(TAG, "Received contentUpdate Intent."); - loadData(); - } - } - }; + @Subscribe + public void onFeedListChanged(FeedListUpdateEvent event) { + loadData(); + } private void handleNavIntent() { Log.d(TAG, "handleNavIntent()"); 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 016168b45..6fd05049d 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java @@ -36,6 +36,7 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.NavListAdapter; import de.danoeh.antennapod.core.asynctask.FeedRemover; import de.danoeh.antennapod.core.dialog.ConfirmationDialog; +import de.danoeh.antennapod.core.event.FeedListUpdateEvent; import de.danoeh.antennapod.core.event.MessageEvent; import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.Feed; @@ -119,7 +120,6 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem if (disposable != null) { disposable.dispose(); } - EventDistributor.getInstance().unregister(contentUpdate); saveCurrentFragment(); } @@ -171,7 +171,6 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem @Override protected void onStart() { super.onStart(); - EventDistributor.getInstance().register(contentUpdate); loadData(); } @@ -445,16 +444,10 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem snackbar.show(); } - private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { - - @Override - public void update(EventDistributor eventDistributor, Integer arg) { - if ((EventDistributor.FEED_LIST_UPDATE & arg) != 0) { - Log.d(TAG, "Received contentUpdate Intent."); - loadData(); - } - } - }; + @Subscribe + public void onFeedListChanged(FeedListUpdateEvent event) { + loadData(); + } private final NavListAdapter.ItemAccess itemAccess = new NavListAdapter.ItemAccess() { @Override 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 9486c810f..542b33e4b 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -32,6 +32,7 @@ import android.widget.TextView; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; +import de.danoeh.antennapod.core.event.FeedListUpdateEvent; import org.apache.commons.lang3.StringUtils; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -94,7 +95,6 @@ public class OnlineFeedViewActivity extends AppCompatActivity { public static final String ARG_TITLE = "title"; private static final int RESULT_ERROR = 2; private static final String TAG = "OnlineFeedViewActivity"; - private static final int EVENTS = EventDistributor.FEED_LIST_UPDATE; private volatile List<Feed> feeds; private Feed feed; private String selectedDownloadUrl; @@ -109,30 +109,6 @@ public class OnlineFeedViewActivity extends AppCompatActivity { private Disposable download; private Disposable parser; private Disposable updater; - private final EventDistributor.EventListener listener = new EventDistributor.EventListener() { - @Override - public void update(EventDistributor eventDistributor, Integer arg) { - if ((arg & EventDistributor.FEED_LIST_UPDATE) != 0) { - updater = Observable.fromCallable(DBReader::getFeedList) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe( - feeds -> { - OnlineFeedViewActivity.this.feeds = feeds; - setSubscribeButtonState(feed); - }, error -> Log.e(TAG, Log.getStackTraceString(error)) - ); - } else if ((arg & EVENTS) != 0) { - setSubscribeButtonState(feed); - } - } - }; - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onEventMainThread(DownloadEvent event) { - Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); - setSubscribeButtonState(feed); - } @Override protected void onCreate(Bundle savedInstanceState) { @@ -202,7 +178,6 @@ public class OnlineFeedViewActivity extends AppCompatActivity { protected void onStart() { super.onStart(); isPaused = false; - EventDistributor.getInstance().register(listener); EventBus.getDefault().register(this); } @@ -210,7 +185,6 @@ public class OnlineFeedViewActivity extends AppCompatActivity { protected void onStop() { super.onStop(); isPaused = true; - EventDistributor.getInstance().unregister(listener); EventBus.getDefault().unregister(this); if (downloader != null && !downloader.isFinished()) { downloader.cancel(); @@ -312,6 +286,25 @@ public class OnlineFeedViewActivity extends AppCompatActivity { } } + @Subscribe + public void onFeedListChanged(FeedListUpdateEvent event) { + updater = Observable.fromCallable(DBReader::getFeedList) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe( + feeds -> { + OnlineFeedViewActivity.this.feeds = feeds; + setSubscribeButtonState(feed); + }, error -> Log.e(TAG, Log.getStackTraceString(error)) + ); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onEventMainThread(DownloadEvent event) { + Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); + setSubscribeButtonState(feed); + } + private void parseFeed() { if (feed == null || (feed.getFile_url() == null && feed.isDownloaded())) { throw new IllegalStateException("feed must be non-null and downloaded when parseFeed is called"); @@ -388,7 +381,6 @@ public class OnlineFeedViewActivity extends AppCompatActivity { this.feed = feed; this.selectedDownloadUrl = feed.getDownload_url(); - EventDistributor.getInstance().register(listener); ListView listView = findViewById(R.id.listview); listView.setSelector(android.R.color.transparent); LayoutInflater inflater = LayoutInflater.from(this); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java index 74f652b11..b12660193 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java @@ -25,6 +25,7 @@ import android.widget.Toast; import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration; import de.danoeh.antennapod.core.event.DownloadLogEvent; +import de.danoeh.antennapod.core.event.FeedListUpdateEvent; import de.danoeh.antennapod.core.event.PlaybackPositionEvent; import de.danoeh.antennapod.core.event.PlayerStatusEvent; import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent; @@ -67,9 +68,6 @@ import io.reactivex.schedulers.Schedulers; public abstract class EpisodesListFragment extends Fragment { public static final String TAG = "EpisodesListFragment"; - - private static final int EVENTS = EventDistributor.FEED_LIST_UPDATE; - private static final String DEFAULT_PREF_NAME = "PrefAllEpisodesFragment"; private static final String PREF_SCROLL_POSITION = "scroll_position"; private static final String PREF_SCROLL_OFFSET = "scroll_offset"; @@ -103,7 +101,6 @@ public abstract class EpisodesListFragment extends Fragment { public void onStart() { super.onStart(); setHasOptionsMenu(true); - EventDistributor.getInstance().register(contentUpdate); EventBus.getDefault().register(this); loadItems(); } @@ -125,7 +122,6 @@ public abstract class EpisodesListFragment extends Fragment { public void onStop() { super.onStop(); EventBus.getDefault().unregister(this); - EventDistributor.getInstance().unregister(contentUpdate); if (disposable != null) { disposable.dispose(); } @@ -427,22 +423,15 @@ public abstract class EpisodesListFragment extends Fragment { updateUi(); } - @Subscribe + @Subscribe(threadMode = ThreadMode.MAIN) public void onUnreadItemsChanged(UnreadItemsUpdateEvent event) { updateUi(); } - private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { - @Override - public void update(EventDistributor eventDistributor, Integer arg) { - if ((arg & EVENTS) != 0) { - loadItems(); - if (isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing()) { - requireActivity().invalidateOptionsMenu(); - } - } - } - }; + @Subscribe(threadMode = ThreadMode.MAIN) + public void onFeedListChanged(FeedListUpdateEvent event) { + updateUi(); + } void loadItems() { if (disposable != null) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java index 2061c0591..8ab82a861 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java @@ -28,6 +28,7 @@ import com.bumptech.glide.request.RequestOptions; import com.joanzapata.iconify.Iconify; import com.joanzapata.iconify.widget.IconTextView; +import de.danoeh.antennapod.core.event.FeedListUpdateEvent; import de.danoeh.antennapod.core.event.PlaybackPositionEvent; import de.danoeh.antennapod.core.event.PlayerStatusEvent; import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent; @@ -81,9 +82,6 @@ import io.reactivex.schedulers.Schedulers; @SuppressLint("ValidFragment") public class FeedItemlistFragment extends ListFragment { private static final String TAG = "ItemlistFragment"; - - private static final int EVENTS = EventDistributor.FEED_LIST_UPDATE; - private static final String ARGUMENT_FEED_ID = "argument.de.danoeh.antennapod.feed_id"; private FeedItemlistAdapter adapter; @@ -150,7 +148,6 @@ public class FeedItemlistFragment extends ListFragment { registerForContextMenu(getListView()); - EventDistributor.getInstance().register(contentUpdate); EventBus.getDefault().register(this); loadItems(); } @@ -159,7 +156,6 @@ public class FeedItemlistFragment extends ListFragment { public void onDestroyView() { super.onDestroyView(); - EventDistributor.getInstance().unregister(contentUpdate); EventBus.getDefault().unregister(this); if (disposable != null) { disposable.dispose(); @@ -407,18 +403,10 @@ public class FeedItemlistFragment extends ListFragment { updateUi(); } - private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { - - @Override - public void update(EventDistributor eventDistributor, Integer arg) { - if ((EVENTS & arg) != 0) { - Log.d(TAG, "Received contentUpdate Intent. arg " + arg); - refreshHeaderView(); - loadItems(); - updateProgressBarVisibility(); - } - } - }; + @Subscribe(threadMode = ThreadMode.MAIN) + public void onFeedListChanged(FeedListUpdateEvent event) { + updateUi(); + } private void updateProgressBarVisibility() { if (isUpdatingFeed != updateRefreshMenuItemChecker.isRefreshing()) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java index 38d1598ce..57d5bcd39 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -28,6 +28,7 @@ import de.danoeh.antennapod.adapter.SubscriptionsAdapter; import de.danoeh.antennapod.core.asynctask.FeedRemover; import de.danoeh.antennapod.core.dialog.ConfirmationDialog; import de.danoeh.antennapod.core.event.DownloadEvent; +import de.danoeh.antennapod.core.event.FeedListUpdateEvent; import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent; import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.Feed; @@ -56,8 +57,6 @@ import org.greenrobot.eventbus.ThreadMode; public class SubscriptionFragment extends Fragment { public static final String TAG = "SubscriptionFragment"; - - private static final int EVENTS = EventDistributor.FEED_LIST_UPDATE; private static final String PREFS = "SubscriptionFragment"; private static final String PREF_NUM_COLUMNS = "columns"; @@ -159,7 +158,6 @@ public class SubscriptionFragment extends Fragment { @Override public void onStart() { super.onStart(); - EventDistributor.getInstance().register(contentUpdate); EventBus.getDefault().register(this); loadSubscriptions(); } @@ -167,7 +165,6 @@ public class SubscriptionFragment extends Fragment { @Override public void onStop() { super.onStop(); - EventDistributor.getInstance().unregister(contentUpdate); EventBus.getDefault().unregister(this); if(disposable != null) { disposable.dispose(); @@ -294,15 +291,10 @@ public class SubscriptionFragment extends Fragment { dialog.createNewDialog().show(); } - private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { - @Override - public void update(EventDistributor eventDistributor, Integer arg) { - if ((EVENTS & arg) != 0) { - Log.d(TAG, "Received contentUpdate Intent."); - loadSubscriptions(); - } - } - }; + @Subscribe + public void onFeedListChanged(FeedListUpdateEvent event) { + loadSubscriptions(); + } @Subscribe public void onUnreadItemsChanged(UnreadItemsUpdateEvent event) { |