diff options
author | Tom Hennen <tom.hennen@gmail.com> | 2016-01-31 19:25:26 -0500 |
---|---|---|
committer | Tom Hennen <tom.hennen@gmail.com> | 2016-01-31 19:25:26 -0500 |
commit | 000633f60c4977e7e5a94675034669124ab69e2b (patch) | |
tree | be904257fc6c9ca78cefffdd84635d47fb9bd86a | |
parent | 79b5328ecf26df8f59816b717f5a6fcf92694d91 (diff) | |
download | AntennaPod-000633f60c4977e7e5a94675034669124ab69e2b.zip |
don't query DB from the UI thread\!
8 files changed, 25 insertions, 10 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java index 12bae2f51..8af6f3552 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -518,6 +518,11 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe } @Override + public int getReclaimableItems() { + return (navDrawerData != null) ? navDrawerData.reclaimableSpace : 0; + } + + @Override public int getFeedCounter(long feedId) { return navDrawerData != null ? navDrawerData.feedCounters.get(feedId) : 0; } 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 f96764b42..bd7da7c03 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -644,10 +644,14 @@ public class MainActivity extends AppCompatActivity implements NavDrawerActivity } @Override + public int getReclaimableItems() { + return (navDrawerData != null) ? navDrawerData.reclaimableSpace : 0; + } + + @Override public int getFeedCounter(long feedId) { return navDrawerData != null ? navDrawerData.feedCounters.get(feedId) : 0; } - }; private void loadData() { diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java index 6a99e7ebc..269614d35 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java @@ -228,9 +228,10 @@ public class NavListAdapter extends BaseAdapter } } else if(tag.equals(DownloadsFragment.TAG) && UserPreferences.isEnableAutodownload()) { int epCacheSize = UserPreferences.getEpisodeCacheSize(); - // don't count episodes that we could delete when autodownloading + // don't count episodes that can be reclaimed int spaceUsed = itemAccess.getNumberOfDownloadedItems() - - UserPreferences.getEpisodeCleanupAlgorithm().getAvailableSpace(); + itemAccess.getReclaimableItems(); + if (spaceUsed >= epCacheSize) { holder.count.setText("{md-disc-full 150%}"); Iconify.addIcons(holder.count); @@ -338,6 +339,7 @@ public class NavListAdapter extends BaseAdapter int getQueueSize(); int getNumberOfNewItems(); int getNumberOfDownloadedItems(); + int getReclaimableItems(); int getFeedCounter(long feedId); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java b/core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java index afb7c2f9d..80703e22d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java @@ -32,7 +32,7 @@ public class APCleanupAlgorithm extends EpisodeCleanupAlgorithm { /** * @return the number of episodes that *could* be cleaned up, if needed */ - public int getAvailableSpace() + public int getReclaimableItems() { return getCandidates().size(); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/APNullCleanupAlgorithm.java b/core/src/main/java/de/danoeh/antennapod/core/storage/APNullCleanupAlgorithm.java index cd99c5a11..9cec62d83 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/APNullCleanupAlgorithm.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/APNullCleanupAlgorithm.java @@ -23,7 +23,7 @@ public class APNullCleanupAlgorithm extends EpisodeCleanupAlgorithm { } @Override - public int getAvailableSpace() { + public int getReclaimableItems() { return 0; } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/APQueueCleanupAlgorithm.java b/core/src/main/java/de/danoeh/antennapod/core/storage/APQueueCleanupAlgorithm.java index 9444278b7..baa9a986e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/APQueueCleanupAlgorithm.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/APQueueCleanupAlgorithm.java @@ -26,7 +26,7 @@ public class APQueueCleanupAlgorithm extends EpisodeCleanupAlgorithm { /** * @return the number of episodes that *could* be cleaned up, if needed */ - public int getAvailableSpace() + public int getReclaimableItems() { return getCandidates().size(); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java index 0563f878f..68187306d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java @@ -1017,7 +1017,8 @@ public final class DBReader { int numNewItems = adapter.getNumberOfNewItems(); int numDownloadedItems = adapter.getNumberOfDownloadedEpisodes(); - NavDrawerData result = new NavDrawerData(feeds, queueSize, numNewItems, numDownloadedItems, feedCounters); + NavDrawerData result = new NavDrawerData(feeds, queueSize, numNewItems, numDownloadedItems, + feedCounters, UserPreferences.getEpisodeCleanupAlgorithm().getReclaimableItems()); adapter.close(); return result; } @@ -1028,17 +1029,20 @@ public final class DBReader { public int numNewItems; public int numDownloadedItems; public LongIntMap feedCounters; + public int reclaimableSpace; public NavDrawerData(List<Feed> feeds, int queueSize, int numNewItems, int numDownloadedItems, - LongIntMap feedIndicatorValues) { + LongIntMap feedIndicatorValues, + int reclaimableSpace) { this.feeds = feeds; this.queueSize = queueSize; this.numNewItems = numNewItems; this.numDownloadedItems = numDownloadedItems; this.feedCounters = feedIndicatorValues; + this.reclaimableSpace = reclaimableSpace; } } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/EpisodeCleanupAlgorithm.java b/core/src/main/java/de/danoeh/antennapod/core/storage/EpisodeCleanupAlgorithm.java index 065374381..97cbdca33 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/EpisodeCleanupAlgorithm.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/EpisodeCleanupAlgorithm.java @@ -40,9 +40,9 @@ public abstract class EpisodeCleanupAlgorithm { } /** - * @return the number of episodes that *could* be cleaned up, if needed + * @return the number of episodes/items that *could* be cleaned up, if needed */ - public abstract int getAvailableSpace(); + public abstract int getReclaimableItems(); /** * @param amountOfRoomNeeded the number of episodes we want to download |