Fix auto cache cleanup

This commit is contained in:
tom5079
2020-10-03 10:03:57 +09:00
parent 54a5cd21ea
commit ade2864351
3 changed files with 3 additions and 11 deletions

View File

@@ -37,19 +37,11 @@ fun cleanCache(context: Context) = CoroutineScope(Dispatchers.IO).launch {
val cacheFolder = File(context.cacheDir, "imageCache")
val downloadManager = DownloadManager.getInstance(context)
cacheFolder.listFiles { file ->
val galleryID = file.name.toIntOrNull() ?: return@listFiles true
!(downloadManager.downloadFolderMap.containsKey(galleryID) || histories.contains(galleryID))
}?.forEach {
it.deleteRecursively()
}
DownloadManager.getInstance(context).downloadFolderMap.keys.forEach {
val folder = File(cacheFolder, it.toString())
if (!downloadManager.isDownloading(it) && folder.exists()) {
folder.deleteRecursively()
Cache.delete(it)
}
}