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.setQueue(queue);
adapter.close();
EventBus.getDefault().post(new FeedListUpdateEvent());
EventBus.getDefault().post(new FeedListUpdateEvent(hostedFeeds));
EventBus.getDefault().post(QueueEvent.setQueue(queue));
}

View File

@ -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() {

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.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;

View File

@ -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<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.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;
}

View File

@ -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));
});
}