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 35a4014ba..f25159046 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java @@ -201,7 +201,7 @@ public class UITestUtils { adapter.setCompleteFeed(hostedFeeds.toArray(new Feed[hostedFeeds.size()])); adapter.setQueue(queue); adapter.close(); - EventBus.getDefault().post(new FeedListUpdateEvent()); + EventBus.getDefault().post(new FeedListUpdateEvent(hostedFeeds)); EventBus.getDefault().post(QueueEvent.setQueue(queue)); } 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 48c84344c..63851acd4 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java @@ -409,7 +409,9 @@ public class FeedItemlistFragment extends ListFragment { @Subscribe(threadMode = ThreadMode.MAIN) public void onFeedListChanged(FeedListUpdateEvent event) { - updateUi(); + if (event.contains(feed)) { + updateUi(); + } } private void updateProgressBarVisibility() { 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 528fa7c32..7e8823c27 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java @@ -25,6 +25,7 @@ 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 org.greenrobot.eventbus.ThreadMode; /** * Displays all running downloads and provides actions to cancel them @@ -75,7 +76,7 @@ public class RunningDownloadsFragment extends ListFragment { setListAdapter(null); } - @Subscribe(sticky = true) + @Subscribe(sticky = true, threadMode = ThreadMode.MAIN) public void onEvent(DownloadEvent event) { Log.d(TAG, "onEvent() called with: " + "event = [" + event + "]"); DownloaderUpdate update = event.update; diff --git a/core/src/main/java/de/danoeh/antennapod/core/event/FeedListUpdateEvent.java b/core/src/main/java/de/danoeh/antennapod/core/event/FeedListUpdateEvent.java index 6073eb3bc..ca8db3cc9 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/event/FeedListUpdateEvent.java +++ b/core/src/main/java/de/danoeh/antennapod/core/event/FeedListUpdateEvent.java @@ -1,6 +1,28 @@ package de.danoeh.antennapod.core.event; +import de.danoeh.antennapod.core.feed.Feed; + +import java.util.ArrayList; +import java.util.List; + public class FeedListUpdateEvent { - public FeedListUpdateEvent() { + private final List feeds = new ArrayList<>(); + + public FeedListUpdateEvent(List feeds) { + for (Feed feed : feeds) { + this.feeds.add(feed.getId()); + } + } + + public FeedListUpdateEvent(Feed feed) { + feeds.add(feed.getId()); + } + + public FeedListUpdateEvent(long feedId) { + feeds.add(feedId); + } + + public boolean contains(Feed feed) { + return feeds.contains(feed.getId()); } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java index 84f57e87a..9d37a5f2a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java @@ -299,7 +299,7 @@ public final class DBTasks { media.setDownloaded(false); media.setFile_url(null); DBWriter.setFeedMedia(media); - EventBus.getDefault().post(new FeedListUpdateEvent()); + EventBus.getDefault().post(new FeedListUpdateEvent(media.getItem().getFeed())); } /** @@ -558,13 +558,13 @@ public final class DBTasks { adapter.close(); try { - DBWriter.addNewFeed(context, newFeedsList.toArray(new Feed[newFeedsList.size()])).get(); - DBWriter.setCompleteFeed(updatedFeedsList.toArray(new Feed[updatedFeedsList.size()])).get(); + DBWriter.addNewFeed(context, newFeedsList.toArray(new Feed[0])).get(); + DBWriter.setCompleteFeed(updatedFeedsList.toArray(new Feed[0])).get(); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } - EventBus.getDefault().post(new FeedListUpdateEvent()); + EventBus.getDefault().post(new FeedListUpdateEvent(updatedFeedsList)); return resultFeeds; } 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 919123950..8f0626c5c 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 @@ -173,7 +173,7 @@ public class DBWriter { if (ClientConfig.gpodnetCallbacks.gpodnetEnabled()) { GpodnetPreferences.addRemovedFeed(feed.getDownload_url()); } - EventBus.getDefault().post(new FeedListUpdateEvent()); + EventBus.getDefault().post(new FeedListUpdateEvent(feed)); // we assume we also removed download log entries for the feed or its media files. // especially important if download or refresh failed, as the user should not be able @@ -803,7 +803,7 @@ public class DBWriter { adapter.open(); adapter.setFeedPreferences(preferences); adapter.close(); - EventBus.getDefault().post(new FeedListUpdateEvent()); + EventBus.getDefault().post(new FeedListUpdateEvent(preferences.getFeedID())); }); } @@ -842,7 +842,7 @@ public class DBWriter { adapter.open(); adapter.setFeedCustomTitle(feed.getId(), feed.getCustomTitle()); adapter.close(); - EventBus.getDefault().post(new FeedListUpdateEvent()); + EventBus.getDefault().post(new FeedListUpdateEvent(feed)); }); }