don't query DB from the UI thread\!

This commit is contained in:
Tom Hennen 2016-01-31 19:25:26 -05:00
parent 79b5328ecf
commit 000633f60c
8 changed files with 25 additions and 10 deletions

View File

@ -517,6 +517,11 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe
return (navDrawerData != null) ? navDrawerData.numDownloadedItems : 0;
}
@Override
public int getReclaimableItems() {
return (navDrawerData != null) ? navDrawerData.reclaimableSpace : 0;
}
@Override
public int getFeedCounter(long feedId) {
return navDrawerData != null ? navDrawerData.feedCounters.get(feedId) : 0;

View File

@ -643,11 +643,15 @@ public class MainActivity extends AppCompatActivity implements NavDrawerActivity
return (navDrawerData != null) ? navDrawerData.numDownloadedItems : 0;
}
@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() {

View File

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

View File

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

View File

@ -23,7 +23,7 @@ public class APNullCleanupAlgorithm extends EpisodeCleanupAlgorithm {
}
@Override
public int getAvailableSpace() {
public int getReclaimableItems() {
return 0;
}
}

View File

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

View File

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

View File

@ -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