From 68da2e022ddd51d069abbf7612b88f6a23d5f034 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Wed, 23 Oct 2019 22:41:20 +0200 Subject: Migrated download log events to EventBus --- .../fragment/CompletedDownloadsFragment.java | 19 +++++++++++++--- .../antennapod/fragment/DownloadLogFragment.java | 25 ++++++++++++---------- 2 files changed, 30 insertions(+), 14 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java index 1917e4c75..b85578060 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java @@ -16,6 +16,7 @@ import java.util.List; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.adapter.DownloadedEpisodesListAdapter; +import de.danoeh.antennapod.core.event.DownloadLogEvent; import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.storage.DBReader; @@ -27,6 +28,8 @@ 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 static de.danoeh.antennapod.dialog.EpisodesApplyActionFragment.ACTION_ADD_TO_QUEUE; import static de.danoeh.antennapod.dialog.EpisodesApplyActionFragment.ACTION_DELETE; @@ -38,9 +41,7 @@ public class CompletedDownloadsFragment extends ListFragment { private static final String TAG = CompletedDownloadsFragment.class.getSimpleName(); - private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED | - EventDistributor.DOWNLOADLOG_UPDATE | - EventDistributor.UNREAD_ITEMS_UPDATE; + private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED | EventDistributor.UNREAD_ITEMS_UPDATE; private List items = new ArrayList<>(); private DownloadedEpisodesListAdapter listAdapter; @@ -56,6 +57,13 @@ public class CompletedDownloadsFragment extends ListFragment { listAdapter = new DownloadedEpisodesListAdapter(getActivity(), itemAccess); setListAdapter(listAdapter); setListShown(false); + EventBus.getDefault().register(this); + } + + @Override + public void onDestroyView() { + EventBus.getDefault().unregister(this); + super.onDestroyView(); } @Override @@ -144,6 +152,11 @@ public class CompletedDownloadsFragment extends ListFragment { } }; + @Subscribe + public void onDownloadLogChanged(DownloadLogEvent event) { + loadItems(); + } + private void loadItems() { if (disposable != null) { disposable.dispose(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java index 528c50747..2c5417b85 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java @@ -19,6 +19,7 @@ import java.util.List; import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.DownloadLogAdapter; +import de.danoeh.antennapod.core.event.DownloadLogEvent; import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedMedia; @@ -30,6 +31,8 @@ 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; /** * Shows the download log @@ -45,14 +48,12 @@ public class DownloadLogFragment extends ListFragment { @Override public void onStart() { super.onStart(); - EventDistributor.getInstance().register(contentUpdate); loadItems(); } @Override public void onStop() { super.onStop(); - EventDistributor.getInstance().unregister(contentUpdate); if (disposable != null) { disposable.dispose(); } @@ -77,6 +78,13 @@ public class DownloadLogFragment extends ListFragment { adapter = new DownloadLogAdapter(getActivity(), itemAccess); setListAdapter(adapter); + EventBus.getDefault().register(this); + } + + @Override + public void onDestroyView() { + EventBus.getDefault().unregister(this); + super.onDestroyView(); } private void onFragmentLoaded() { @@ -133,15 +141,10 @@ public class DownloadLogFragment extends ListFragment { } }; - private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { - - @Override - public void update(EventDistributor eventDistributor, Integer arg) { - if ((arg & EventDistributor.DOWNLOADLOG_UPDATE) != 0) { - loadItems(); - } - } - }; + @Subscribe + public void onDownloadLogChanged(DownloadLogEvent event) { + loadItems(); + } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { -- cgit v1.2.3 From d8ffa6c4591102c96adf1096b211caf0db7aa168 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Wed, 23 Oct 2019 22:44:44 +0200 Subject: Migrated playback history events to EventBus --- .../de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'app/src/main') 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 f9fca87fc..ab15c3602 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java @@ -12,6 +12,7 @@ import android.view.MenuItem; import android.view.View; import android.widget.ListView; +import de.danoeh.antennapod.core.event.PlaybackHistoryEvent; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; @@ -42,8 +43,7 @@ public class PlaybackHistoryFragment extends ListFragment { public static final String TAG = "PlaybackHistoryFragment"; - private static final int EVENTS = EventDistributor.PLAYBACK_HISTORY_UPDATE | - EventDistributor.PLAYER_STATUS_UPDATE; + private static final int EVENTS = EventDistributor.PLAYER_STATUS_UPDATE; private List playbackHistory; private FeedItemlistAdapter adapter; @@ -166,6 +166,12 @@ public class PlaybackHistoryFragment extends ListFragment { } } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onHistoryUpdated(PlaybackHistoryEvent event) { + loadItems(); + getActivity().supportInvalidateOptionsMenu(); + } + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override -- cgit v1.2.3 From 7d3b78091fcead9a4a89861f39d42df601e080a4 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Wed, 23 Oct 2019 22:49:04 +0200 Subject: Removed event that is never sent --- .../de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java | 4 +--- app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java | 5 ++--- app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java | 3 +-- 3 files changed, 4 insertions(+), 8 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java index b85578060..7196198cc 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java @@ -41,8 +41,6 @@ public class CompletedDownloadsFragment extends ListFragment { private static final String TAG = CompletedDownloadsFragment.class.getSimpleName(); - private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED | EventDistributor.UNREAD_ITEMS_UPDATE; - private List items = new ArrayList<>(); private DownloadedEpisodesListAdapter listAdapter; private Disposable disposable; @@ -146,7 +144,7 @@ public class CompletedDownloadsFragment extends ListFragment { private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { - if ((arg & EVENTS) != 0) { + if ((arg & EventDistributor.UNREAD_ITEMS_UPDATE) != 0) { loadItems(); } } 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 b8ae7bb5b..37277a7c4 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -76,9 +76,8 @@ public class QueueFragment extends Fragment { public static final String TAG = "QueueFragment"; - private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED | - EventDistributor.UNREAD_ITEMS_UPDATE | // sent when playback position is reset - EventDistributor.PLAYER_STATUS_UPDATE; + private static final int EVENTS = EventDistributor.UNREAD_ITEMS_UPDATE // sent when playback position is reset + | EventDistributor.PLAYER_STATUS_UPDATE; private TextView infoBar; private RecyclerView recyclerView; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java index 7f3c60e5d..b05b7025c 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java @@ -148,8 +148,7 @@ public class SearchFragment extends ListFragment { private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { - if ((arg & (EventDistributor.UNREAD_ITEMS_UPDATE - | EventDistributor.DOWNLOAD_HANDLED)) != 0) { + if ((arg & EventDistributor.UNREAD_ITEMS_UPDATE) != 0) { search(); } } -- cgit v1.2.3