Do not start download service if there is nothing to download
This commit is contained in:
parent
66c91f9962
commit
bbb7cfe7ed
|
@ -74,13 +74,12 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm {
|
||||||
int downloadedEpisodes = DBReader.getNumberOfDownloadedEpisodes();
|
int downloadedEpisodes = DBReader.getNumberOfDownloadedEpisodes();
|
||||||
int deletedEpisodes = UserPreferences.getEpisodeCleanupAlgorithm()
|
int deletedEpisodes = UserPreferences.getEpisodeCleanupAlgorithm()
|
||||||
.makeRoomForEpisodes(context, autoDownloadableEpisodes);
|
.makeRoomForEpisodes(context, autoDownloadableEpisodes);
|
||||||
boolean cacheIsUnlimited = UserPreferences.getEpisodeCacheSize() == UserPreferences
|
boolean cacheIsUnlimited =
|
||||||
.getEpisodeCacheSizeUnlimited();
|
UserPreferences.getEpisodeCacheSize() == UserPreferences.getEpisodeCacheSizeUnlimited();
|
||||||
int episodeCacheSize = UserPreferences.getEpisodeCacheSize();
|
int episodeCacheSize = UserPreferences.getEpisodeCacheSize();
|
||||||
|
|
||||||
int episodeSpaceLeft;
|
int episodeSpaceLeft;
|
||||||
if (cacheIsUnlimited ||
|
if (cacheIsUnlimited || episodeCacheSize >= downloadedEpisodes + autoDownloadableEpisodes) {
|
||||||
episodeCacheSize >= downloadedEpisodes + autoDownloadableEpisodes) {
|
|
||||||
episodeSpaceLeft = autoDownloadableEpisodes;
|
episodeSpaceLeft = autoDownloadableEpisodes;
|
||||||
} else {
|
} else {
|
||||||
episodeSpaceLeft = episodeCacheSize - (downloadedEpisodes - deletedEpisodes);
|
episodeSpaceLeft = episodeCacheSize - (downloadedEpisodes - deletedEpisodes);
|
||||||
|
@ -89,6 +88,7 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm {
|
||||||
FeedItem[] itemsToDownload = candidates.subList(0, episodeSpaceLeft)
|
FeedItem[] itemsToDownload = candidates.subList(0, episodeSpaceLeft)
|
||||||
.toArray(new FeedItem[episodeSpaceLeft]);
|
.toArray(new FeedItem[episodeSpaceLeft]);
|
||||||
|
|
||||||
|
if (itemsToDownload.length > 0) {
|
||||||
Log.d(TAG, "Enqueueing " + itemsToDownload.length + " items for download");
|
Log.d(TAG, "Enqueueing " + itemsToDownload.length + " items for download");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -96,7 +96,7 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm {
|
||||||
} catch (DownloadRequestException e) {
|
} catch (DownloadRequestException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,13 +80,14 @@ public class DownloadRequester implements DownloadStateProvider {
|
||||||
* with the same source URL is already stored, this one will be skipped.
|
* with the same source URL is already stored, this one will be skipped.
|
||||||
* @return True if any of the download request was accepted, false otherwise.
|
* @return True if any of the download request was accepted, false otherwise.
|
||||||
*/
|
*/
|
||||||
public synchronized boolean download(@NonNull Context context,
|
public synchronized boolean download(@NonNull Context context, DownloadRequest... requests) {
|
||||||
DownloadRequest... requests) {
|
|
||||||
return download(context, false, requests);
|
return download(context, false, requests);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean download(@NonNull Context context, boolean cleanupMedia,
|
private boolean download(@NonNull Context context, boolean cleanupMedia, DownloadRequest... requests) {
|
||||||
DownloadRequest... requests) {
|
if (requests.length <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
|
|
||||||
ArrayList<DownloadRequest> requestsToSend = new ArrayList<>(requests.length);
|
ArrayList<DownloadRequest> requestsToSend = new ArrayList<>(requests.length);
|
||||||
|
|
Loading…
Reference in New Issue