From 8ae4446fc1679486ecf80110984a69a416e1fdcf Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 10 Jan 2018 17:31:34 -0800 Subject: Fixes #814: Limit undeletable files to ones we are playing soon or just played --- .../java/github/daneren2005/dsub/service/DownloadService.java | 8 ++++++++ app/src/main/java/github/daneren2005/dsub/util/CacheCleaner.java | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/github') diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java index 4b8d9db3..e1b3d0ae 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -1036,6 +1036,14 @@ public class DownloadService extends Service { return temp; } + public synchronized List getRecentDownloads() { + int from = Math.max(currentPlayingIndex - 10, 0); + int to = Math.min(currentPlayingIndex + 20, downloadList.size() - 1); + List temp = downloadList.subList(from, to); + temp.addAll(backgroundDownloadList); + return temp; + } + public List getBackgroundDownloads() { return backgroundDownloadList; } diff --git a/app/src/main/java/github/daneren2005/dsub/util/CacheCleaner.java b/app/src/main/java/github/daneren2005/dsub/util/CacheCleaner.java index ac8fa72a..f160e176 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/CacheCleaner.java +++ b/app/src/main/java/github/daneren2005/dsub/util/CacheCleaner.java @@ -151,7 +151,7 @@ public class CacheCleaner { private Set findUndeletableFiles() { Set undeletable = new HashSet(5); - for (DownloadFile downloadFile : downloadService.getDownloads()) { + for (DownloadFile downloadFile : downloadService.getRecentDownloads()) { undeletable.add(downloadFile.getPartialFile()); undeletable.add(downloadFile.getCompleteFile()); } -- cgit v1.2.3