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

@@ -38,7 +38,7 @@ android {
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 30 targetSdkVersion 30
versionCode 61 versionCode 61
versionName "5.1.2" versionName "5.1.2-hotfix2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
} }

View File

@@ -12,7 +12,7 @@
"filters": [], "filters": [],
"properties": [], "properties": [],
"versionCode": 61, "versionCode": 61,
"versionName": "5.1.2", "versionName": "5.1.2-hotfix2",
"enabled": true, "enabled": true,
"outputFile": "app-release.apk" "outputFile": "app-release.apk"
} }

View File

@@ -37,19 +37,11 @@ fun cleanCache(context: Context) = CoroutineScope(Dispatchers.IO).launch {
val cacheFolder = File(context.cacheDir, "imageCache") val cacheFolder = File(context.cacheDir, "imageCache")
val downloadManager = DownloadManager.getInstance(context) 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 { DownloadManager.getInstance(context).downloadFolderMap.keys.forEach {
val folder = File(cacheFolder, it.toString()) val folder = File(cacheFolder, it.toString())
if (!downloadManager.isDownloading(it) && folder.exists()) { if (!downloadManager.isDownloading(it) && folder.exists()) {
folder.deleteRecursively() Cache.delete(it)
} }
} }