Do not refresh feeds more often than necessary

This commit is contained in:
ByteHamster 2019-10-30 19:27:38 +01:00
parent 6825cca32a
commit 69f3a1210f
6 changed files with 36 additions and 11 deletions

View File

@ -201,7 +201,7 @@ public class UITestUtils {
adapter.setCompleteFeed(hostedFeeds.toArray(new Feed[hostedFeeds.size()])); adapter.setCompleteFeed(hostedFeeds.toArray(new Feed[hostedFeeds.size()]));
adapter.setQueue(queue); adapter.setQueue(queue);
adapter.close(); adapter.close();
EventBus.getDefault().post(new FeedListUpdateEvent()); EventBus.getDefault().post(new FeedListUpdateEvent(hostedFeeds));
EventBus.getDefault().post(QueueEvent.setQueue(queue)); EventBus.getDefault().post(QueueEvent.setQueue(queue));
} }

View File

@ -409,8 +409,10 @@ public class FeedItemlistFragment extends ListFragment {
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onFeedListChanged(FeedListUpdateEvent event) { public void onFeedListChanged(FeedListUpdateEvent event) {
if (event.contains(feed)) {
updateUi(); updateUi();
} }
}
private void updateProgressBarVisibility() { private void updateProgressBarVisibility() {
if (isUpdatingFeed != updateRefreshMenuItemChecker.isRefreshing()) { if (isUpdatingFeed != updateRefreshMenuItemChecker.isRefreshing()) {

View File

@ -25,6 +25,7 @@ import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.view.EmptyViewHandler; import de.danoeh.antennapod.view.EmptyViewHandler;
import org.greenrobot.eventbus.ThreadMode;
/** /**
* Displays all running downloads and provides actions to cancel them * Displays all running downloads and provides actions to cancel them
@ -75,7 +76,7 @@ public class RunningDownloadsFragment extends ListFragment {
setListAdapter(null); setListAdapter(null);
} }
@Subscribe(sticky = true) @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEvent(DownloadEvent event) { public void onEvent(DownloadEvent event) {
Log.d(TAG, "onEvent() called with: " + "event = [" + event + "]"); Log.d(TAG, "onEvent() called with: " + "event = [" + event + "]");
DownloaderUpdate update = event.update; DownloaderUpdate update = event.update;

View File

@ -1,6 +1,28 @@
package de.danoeh.antennapod.core.event; 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 class FeedListUpdateEvent {
public FeedListUpdateEvent() { private final List<Long> feeds = new ArrayList<>();
public FeedListUpdateEvent(List<Feed> 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());
} }
} }

View File

@ -299,7 +299,7 @@ public final class DBTasks {
media.setDownloaded(false); media.setDownloaded(false);
media.setFile_url(null); media.setFile_url(null);
DBWriter.setFeedMedia(media); 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(); adapter.close();
try { try {
DBWriter.addNewFeed(context, newFeedsList.toArray(new Feed[newFeedsList.size()])).get(); DBWriter.addNewFeed(context, newFeedsList.toArray(new Feed[0])).get();
DBWriter.setCompleteFeed(updatedFeedsList.toArray(new Feed[updatedFeedsList.size()])).get(); DBWriter.setCompleteFeed(updatedFeedsList.toArray(new Feed[0])).get();
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException e) {
e.printStackTrace(); e.printStackTrace();
} }
EventBus.getDefault().post(new FeedListUpdateEvent()); EventBus.getDefault().post(new FeedListUpdateEvent(updatedFeedsList));
return resultFeeds; return resultFeeds;
} }

View File

@ -173,7 +173,7 @@ public class DBWriter {
if (ClientConfig.gpodnetCallbacks.gpodnetEnabled()) { if (ClientConfig.gpodnetCallbacks.gpodnetEnabled()) {
GpodnetPreferences.addRemovedFeed(feed.getDownload_url()); 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. // 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 // especially important if download or refresh failed, as the user should not be able
@ -803,7 +803,7 @@ public class DBWriter {
adapter.open(); adapter.open();
adapter.setFeedPreferences(preferences); adapter.setFeedPreferences(preferences);
adapter.close(); adapter.close();
EventBus.getDefault().post(new FeedListUpdateEvent()); EventBus.getDefault().post(new FeedListUpdateEvent(preferences.getFeedID()));
}); });
} }
@ -842,7 +842,7 @@ public class DBWriter {
adapter.open(); adapter.open();
adapter.setFeedCustomTitle(feed.getId(), feed.getCustomTitle()); adapter.setFeedCustomTitle(feed.getId(), feed.getCustomTitle());
adapter.close(); adapter.close();
EventBus.getDefault().post(new FeedListUpdateEvent()); EventBus.getDefault().post(new FeedListUpdateEvent(feed));
}); });
} }